I\'m in java one and I need help with this code. please follow the directions. I
ID: 3677913 • Letter: I
Question
I'm in java one and I need help with this code. please follow the directions. 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.
2 ID 12345 98765 13579Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package practice;
import java.util.Scanner;
/**
*
* @author Shivakumar
*/
public class PayrollManager {
static int[] ID=new int[3];
static double[] paychecks= new double[3]; //Declaring values
static double wage;
static int hours;
public void wages(int hours,double hwage,int index) // method to calculate wages
{
switch(index)
{
case 0: paychecks[0]=hours*hwage; // using switch
case 1: paychecks[1]=hours*hwage;
case 2: paychecks[2]=hours*hwage;
}
}
public void input() // method to store Employee ids
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter three employee IDs, separated by spaces:");
String[] temp=sc.nextLine().split("\s+");
ID[0]=Integer.parseInt(temp[0]);
ID[1]=Integer.parseInt(temp[1]);
ID[2]=Integer.parseInt(temp[2]);
}
public static void main(String args[])
{
PayrollManager obj=new PayrollManager(); // creating object
obj.input();
Scanner sc1=new Scanner(System.in); // scanner for console input
for(int i=0;i<3;i++) // Loop to enter values
{
System.out.println("What is employee "+ID[i]+"'s hourly wage?$");
wage=sc1.nextDouble();
System.out.println("How many hours did employee "+ID[i]+" work this week?");
hours=sc1.nextInt();
obj.wages(hours, wage, i);
}
for(int i=0;i<3;i++) // Loop to display wages
System.out.print("Employee "+ID[i]+" will be paid $"+paychecks[i]+" this week. ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.