//======= Problem 3 Arrays of Employee Objects ============ //a) Make an array o
ID: 3832486 • Letter: #
Question
//======= Problem 3 Arrays of Employee Objects ============
//a) Make an array of 6 Employee objects called startup
// and make all its elements refer to default Employee objects
// (use a for loop and assign each cell a new Employee())
Employee [] startup = new Employee[6];
for(int e = 0; e < startup.length; e++){
startup[e] = new Employee();
}
//b) Define the method printAllEmployees where indicated below main
// then activate the following 2 statements:
System.out.println("Here are the employees at our new startup:");
printAllEmplyees();
//c) Set the first three elements to new Employees with fictitious
// names, IDs and salarys (like John Pilsner, 1111,35000 ... etc)
// and print all the employees again
Employee E1 = new Employee("John Pilsner", 28531,35000);
Employee E2 = new Employee("Parker Jones", 39261,42000);
Employee E3 = new Employee("Jane Smith", 74120 , 57620);
//d) If a 5% raise can be given by setting an employees salary *= 1.05,
// define the method giveRaiseToAll where indicated below main,
// then activate the following statements:
System.out.println("After giving a 5% raise to all workers:");
giveRaiseToAll(startup,5);
printAllEmployees(startup);
//------- End Problem 3 ------------------------------------*/
}
// 3b) Define the static void method printAllEmployees here
// in this method, use a for loop to .print() all the items in array
public static void printAllEmplyees(){
for( int i = 0; i < startup.length; i++){
startup[i].print();
}
}
// 3c) Define the static void method giveRaiseToAll here
// it receives as parameters an array of Employees and a double rate
// in this method, define a double scale variable
// and set scale equal to 1 + rate/100
// then use a for loop to access each employee
// and use the getSalary and setSalary methods to
// change the salary to a new salary that is scale * old salary
// you can do this in one line using "composition"
// or in several lines using local variables to store
// intermediate values
public static void giveRaiseToAll( Array [] employess, double rate){
double scale = 1 + rate/100;
for (
}
Explanation / Answer
//======= Problem 3 Arrays of Employee Objects ============
//a) Make an array of 6 Employee objects called startup
// and make all its elements refer to default Employee objects
// (use a for loop and assign each cell a new Employee())
Employee [] startup = new Employee[6];
for(int e = 0; e < startup.length; e++){
startup[e] = new Employee();
}
//b) Define the method printAllEmployees where indicated below main
// then activate the following 2 statements:
System.out.println("Here are the employees at our new startup:");
printAllEmplyees();
//c) Set the first three elements to new Employees with fictitious
// names, IDs and salarys (like John Pilsner, 1111,35000 ... etc)
// and print all the employees again
Employee E1 = new Employee("John Pilsner", 28531,35000);
Employee E2 = new Employee("Parker Jones", 39261,42000);
Employee E3 = new Employee("Jane Smith", 74120 , 57620);
//d) If a 5% raise can be given by setting an employees salary *= 1.05,
// define the method giveRaiseToAll where indicated below main,
// then activate the following statements:
System.out.println("After giving a 5% raise to all workers:");
giveRaiseToAll(startup,5);
printAllEmployees(startup);
//------- End Problem 3 ------------------------------------*/
}
// 3b) Define the static void method printAllEmployees here
// in this method, use a for loop to .print() all the items in array
public static void printAllEmplyees(){
for( int i = 0; i < startup.length; i++){
startup[i].print();
}
}
// 3c) Define the static void method giveRaiseToAll here
// it receives as parameters an array of Employees and a double rate
// in this method, define a double scale variable
// and set scale equal to 1 + rate/100
// then use a for loop to access each employee
// and use the getSalary and setSalary methods to
// change the salary to a new salary that is scale * old salary
// you can do this in one line using "composition"
// or in several lines using local variables to store
// intermediate values
public static void giveRaiseToAll( Employee [] employess, double rate){
double scale = 1 + rate/100;
for ( int i=0; i<employess.length; i++){
employess[i].salary = scale*employess[i].salary;
}
Please let me know in case of any issue
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.