I\'m in java one and I need help with this code. please follow the directions (
ID: 3678237 • Letter: I
Question
I'm in java one and I need help with this code. please follow the directions (use arrays and for loops). make sure that the output matches the given outpu. I will apreciate you help. thank you.
Programming Concepts
1. Arrays
2. forLoops
Assignment Description
You will be simulating a payroll manager, where you must calculate paychecks for three people.
You must accomplish this assignment using two arrays: one array to hold the employee IDs, and another to hold the paycheck amounts.
For example:
The two arrays will be parallel arrays, so employee 12345's paycheck will be $250.46, employee 98765's paycheck will be $512.65, and employee 13579's paycheck will be $888.46.
Assignment Requirements
You must use an array to hold the ID numbers, and another one to hold the paycheck amounts
You must print out the dollar amount with commas, if necessary. To do that, use the format specifier %,.2f
Assignment Suggestions
1. Declare these variables:
a. int[] ID: An array to hold the employee ID numbers (size 3)
b. double[] paychecks: An array to hold the paycheck amounts (size 3)
c. double wage: To store the employee's wage
d. int hours: To store the employee's hours worked
2.Prompt the user to enter in the employee IDs, separated by spaces.
3.Store each ID number entered into the array of IDs.
4.Using a loop...
a. Ask the user to enter in the employee's wage
i. Store the wage
b. Ask the user to enter in the employee's hours
i. Store the hours
c. Calculate their paycheck, and store the result into the paycheck array for the employee. 5. Using a loop...
5. using a loop
a. Print out each employee's name and their wage, like in the sample output.
output example
user@loki:~$ java PayrollManager
Please enter three employee IDs, separated by spaces: 24680 56789 44444
What is employee 24680's hourly wage? $2.34
How many hours did employee 24680 work this week? 25
What is employee 56789's hourly wage? $0.01
How many hours did employee 56789 work this week? 168
What is employee 44444's hourly wage? $593.32
How many hours did employee 44444 work this week? 832
Employee 24680 will be paid $58.50 this week. Employee 56789 will be paid $1.68 this week. Employee 44444 will be paid $493,642.24 this week.
Run 2
user@loki:~$ java PayrollManager
Please enter three employee IDs, separated by spaces: 31415 11235 27182
What is employee 31415's hourly wage? $0.93
How many hours did employee 31415 work this week? 50000
What is employee 11235's hourly wage? $54321 How many hours did employee 11235 work this week? 2
What is employee 27182's hourly wage? $3.65 How many hours did employee 27182 work this week? 25
Employee 31415 will be paid $46,500.00 this week.
Employee 11235 will be paid $108,642.00 this week.
Employee 27182 will be paid $91.25 this week.
Explanation / Answer
import java.util.Scanner;
public class EmployeeWageCalculator {
public static void main(String[] args) {
// variable declaration
int[] ID = new int[3];
double[] paychecks = new double[3];
double wage;
int hours;
// to read user input
Scanner sc = new Scanner(System.in);
System.out.print("Please enter three employee IDs, separated by spaces: ");
String ids = sc.nextLine();
int i=0;
for(String id: ids.split("\s+")){ // splitting by space
ID[i] = Integer.parseInt(id);
i++;
}
String wageString = "";
for(i=0; i<3; i++){
// reading hourly wage as string with dollar sign
System.out.print("What is employee "+ID[i]+"'s hourly wage? ");
wageString = sc.next();
// ignoring $ sign
wageString = wageString.substring(1);
// converting string to double
wage = Double.parseDouble(wageString);
// reading number of hours for this week
System.out.print("How many hours did employee "+ID[i]+" work this week? ");
hours = sc.nextInt();
// calculating and storing wage
paychecks[i] = wage*hours;
}
// closing scanner
sc.close();
// printing employee paychecks
for(i=0; i<3;i++){
System.out.println("Employee "+ID[i]+" will be paid $"+String.format("%.2f", paychecks[i])+" this week");
}
}
}
/*
Output:
Please enter three employee IDs, separated by spaces: 24680 56789 4444
What is employee 24680's hourly wage? $2.34
How many hours did employee 24680 work this week? 25
What is employee 56789's hourly wage? $0.01
How many hours did employee 56789 work this week? 168
What is employee 4444's hourly wage? $593.32
How many hours did employee 4444 work this week? 832
Employee 24680 will be paid $58.50 this week
Employee 56789 will be paid $1.68 this week
Employee 4444 will be paid $493642.24 this week
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.