1. Use an object of type String to add a person\'s name to the data assigned wit
ID: 3653407 • Letter: 1
Question
1. Use an object of type String to add a person's name to the data assigned within your program.
2. Use methods to carry out the work of your program. The main block of code should only consist of method calls to carry out the tasks. Remember that method names begin with a verb, reflecting the action being carried out by that block of code. Also keep in mind that methods are narrow in focus, completing only one basic function. Most of the methods in this project will be relatively short; however, be aware of the fact that having only one method in this revision will not constitute successful completion of this project.
Explanation / Answer
please rate - thanks
// Money
import java.util.Scanner;
public class Money
{ public static void main(String[] args)
{ int employeeNumber; double hourlyWage, hoursWorked, hoursWorkedOvertime, totalPay;
String name;
Scanner keyboard = new Scanner(System.in);
name=getName(keyboard);
employeeNumber = getNumber(keyboard);
hourlyWage=getHourly(keyboard);
hoursWorked =getRegHours(keyboard);
hoursWorkedOvertime = getOverHours(keyboard);
totalPay=getTotal(hoursWorked,hourlyWage,hoursWorkedOvertime);
printit(totalPay,name,employeeNumber);
}
public static String getName(Scanner keyboard)
{System.out.println("What is the employee name?");
return keyboard.nextLine();
}
public static int getNumber(Scanner keyboard)
{System.out.println("What is the employee number?");
return Integer.parseInt(keyboard.nextLine());
}
public static double getHourly(Scanner keyboard)
{ System.out.println("What is the hourly wage amount?");
return Double.parseDouble(keyboard.nextLine());
}
public static double getRegHours(Scanner keyboard)
{ System.out.println("What is the number of regular hours worked?");
return Double.parseDouble(keyboard.nextLine());
}
public static double getOverHours(Scanner keyboard)
{ System.out.println("What is the number of overtime hours worked?");
return Double.parseDouble(keyboard.nextLine());
}
public static double getTotal(double hoursWorked,double hourlyWage,double hoursWorkedOvertime)
{return (hoursWorked*hourlyWage+hoursWorkedOvertime*hourlyWage*1.5);
}
public static void printit(double totalPay, String name,int number)
{System.out.println("Enployee name: "+name);
System.out.println("Employee number: "+number);
System.out.printf("Total Pay : $%.2f", totalPay);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.