Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java HomeWork 10

eltom117
eltom117 


Attached is the questions, but you have to use the same TextBook I sent you before, also use the textIO that I sent out previously. Thank you. Attachments Tags Clarifications

Answers

Java Homework 10 - Solution

dickersonka
dickersonka 



Attached is the solution to the java homework 10. For reference 10.8 has a suffix of 2 and 10.12 has a suffix of 3 since they deal with the same classes. Attachments
Assignment10.zip (21 K) Download
Preview
// non-negative } // end method setBaseSalary // return base salary public double getBaseSalary() { return baseSalary; } // end method getBaseSalary // calculate earnings; override method earnings in CommissionEmployee @Override public double earnings() { return getBaseSalary()

Preview
public final void setBaseSalary( double salary ) { baseSalary = ( salary < 0.0 ) ? 0.0 : salary; // non-negative } // end method setBaseSalary // return base salary public double getBaseSalary() { return baseSalary; } // end method

Preview
) { super( x, y, radius, radius ); } // overridden methods public String getName() { return "Circle"; } public void print() { System.out.println( "(" + super.getX() + ",

Preview
double grossSales; // gross weekly sales private double commissionRate; // commission percentage // five-argument constructor public CommissionEmployee2( String first, String last, String ssn, Date2 birthDate, double sales, double rate ) { super( first, last, ssn, birthDate); setGrossSales( sales ); setCommissionRate( rate );

Preview
first, last, ssn, birthDate); setGrossSales( sales ); setCommissionRate( rate ); } // end five-argument CommissionEmployee constructor // set commission rate public final void setCommissionRate( double rate ) { commissionRate = ( rate > 0.0 && rate < 1.0 ) ? rate :

Preview
} public int volume() { return ( int ) ( super.getDimension1() * super.getDimension1() * super.getDimension1() ); } public void print() { System.out.println( "(" + super.getX() + ", " + super.getY() + ") " + "side: "

Preview
<= daysPerMonth[ month ] ) return testDay; // check for leap year if ( month == 2 && testDay == 29 && ( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0 ) ) )

Preview
Date2 birthDate) { this.firstName = firstName; this.lastName = lastName; this.socialSecurityNumber = socialSecurityNumber; this.setBirthDate(birthDate); } // end three-argument Employee constructor // set first name public void setFirstName( String first ) { firstName = first; } // end method setFirstName

Preview
return firstName; } // end method getFirstName // set last name public void setLastName( String last ) { lastName = last; } // end method setLastName // return last name public String getLastName() { return lastName;

Preview
<= 168.0 ) ) ? hoursWorked : 0.0; } // end method setHours // return hours worked public double getHours() { return hours; } // end method getHours // calculate earnings; override abstract method earnings in Employee public double

Preview
// return String representation of HourlyEmployee object @Override public String toString() { return String.format( "hourly employee: %s\n%s: $%,.2f; %s: %,.2f", super.toString(), "hourly wage", getWage(), "hours worked", getHours() ); } // end method toString @Override public double getPaymentAmount() {

Preview
{

Preview
commissionEmployee.earnings() )); TextIO.putln(String.format( "%s\n%s: $%,.2f\n\n", basePlusCommissionEmployee, "earned", basePlusCommissionEmployee.earnings() )); // create four-element Employee array Employee2 employees[] = new Employee2[ 4 ]; // initialize array with Employees employees[ 0 ] = salariedEmployee; employees[ 1 ] = hourlyEmployee; employees[ 2 ] = commissionEmployee;

Preview
TextIO.putln("###################################"); SalariedEmployee3 salariedEmployee = new SalariedEmployee3( "John", "Smith", "111-11-1111", new Date2(5,11,1984),800.00 ); HourlyEmployee3 hourlyEmployee = new HourlyEmployee3( "Karen", "Price", "222-22-2222", new Date2(6,15,1988),16.75, 40 ); CommissionEmployee3 commissionEmployee = new CommissionEmployee3( "Sue", "Jones", "333-33-3333", new Date2(8,25,1974),10000, .06 ); BasePlusCommissionEmployee3 basePlusCommissionEmploye

Preview
Employee public double earnings() { return getWeeklySalary(); } // end method earnings // return String representation of SalariedEmployee object @Override public String toString() { return String.format( "salaried employee: %s\n%s: $%,.2f", super.toString(), "weekly salary", getWeeklySalary() ); } // end

Preview
constructor // set salary public final void setWeeklySalary( double salary ) { weeklySalary = salary < 0.0 ? 0.0 : salary; } // end method setWeeklySalary // return salary public double getWeeklySalary() { return weeklySalary; } //

Preview
public void setY( int y ) { this.y = y; } // get x coordinate public int getX() { return x; } // get y coordinate public int

Preview
] = sphere; Cube cube = new Cube( 79, 61, 73 ); shapeArray[ 3 ] = cube; threeDArray[ 1 ] = cube; } // display shape info public void displayShapeInfo() { TextIO.writeStandardOutput(); // call method print on all

Preview
public int volume() { return ( int ) ( 4 / 3 * Math.PI * super.getDimension1() * super.getDimension1() * super.getDimension1() ); } public void print() { System.out.println( "(" + super.getX() + ", " + super.getY() + ") " + "radius: "

Preview
} public int area() { return super.getDimension1() * super.getDimension1(); } // set method public void setSide( int side ) { super.setDimension1( side ); } // get

Preview
* TextIO provides a set of static methods for reading and writing text. By * default, it reads from standard input and writes to standard output, but it * is possible to redirect the input and output to files or to other input and * output

Preview
) { dimension1 = d; } public void setDimension2( int d ) { dimension2 = d; } public void setDimension3( int d ) { dimension3 = d; } // get methods public int

Preview
public void setDimension2( int d ) { dimension2 = d; } // get methods public int getDimension1() { return dimension1; } public int getDimension2()

Screenshots
Purchase Answer