Hi,
I'm having issues with driver class is giving me issues. The code needs 2 for loops requirement.
The driver class will create an array of 3 CircusClown objects.
Use a loop to get user input for your 3 objects.
Use a loop to print the toString() method of your 3 objects.
Determine and print the name of the clown that earned the most bonus pay for the week.
The code must work with ANY sized array. I said to make an array of size 3, but if you
were to change it to size 100, you should not have to alter ANY of your code.
Here is my work any help please.
// Class Clown
public class Clown {
private String name;
private double salary;
private double hours;
private double years;
public Clown( String n, double s, double h, double y ) {
name = n;
salary = s;
hours = h;
years = y;
}
//getter methods
public String getName() {
return name;
}
public double getSalary() {
return salary;
}
public double getHoursWorked() {
return hours;
}
public double getYearsWorked() {
return years;
}
public double calcBaseWeekPay() {
return (hours * salary);
}
public double calcBonusAmount() {
double rate = .05;
if (years >= 30) {
rate = .3;
}
else if (years >= 15 && years < 30) {
rate = .15;
}
else {
rate = .05;
}
return calcBaseWeekPay() * rate;
}
public double calcTotalPay() {
return calcBaseWeekPay() + calcBonusAmount();
}
public String toString() {
return "Clowns Name is" + name +
"Bonus Amount is" + calcBonusAmount() +
"Total Weekly Pay is" + calcBaseWeekPay();
}
}
Here is my diver tester.
import java.util.*;
public class ClownTester {
public static void main(String[] args) {
Scanner play = new Scanner(System.in);
String name;
double salary;
int hours;
int years;
for (int i = 0; i < circusClowns.length(); i++) {
System.out.print("Enter the name of the clown: ");
name = play.nextLine();
System.out.print("Enter salary for " + name + ": ");
salary = play.nextDouble();
System.out.print("Enter the number of hours: ");
hours = play.nextInt();
System.out.print("Enter the number of years: ");
years = play.nextInt();
circusClowns[i] = new Clown(name, salary, hours, years);
}
// Now, for the second for loop to print, just use the one you already have:
for (Clown cc : circusClown) {
System.out.println(cc.toString());
}
double mostBonusPay = circusClown[0].calcBonusAmount() //assume the biggest is the first one
int index = 0; //assume the biggest is the first one
for (int i = 1; i < circusClown.length(); i++) {
if (circusClown[i].calcBonusAmount() > mostBonusPay) {
mostBonusPay = circusClown[i].calcBonusAmount();
index = i;
}
}
}
}