import java.util.Scanner;
public class ThreeFiveRevised
{
public static final double OVERTIME_PAY_RATE = 1.5;
public static final double REGULAR_PAY_RATE = 1.0;
public static void main(String[] args)
{
grabHourlyWages();
calculateMondayPay();
calculateTuesdayPay();
calculateWedneimport java.util.Scanner;
public class ThreeFiveRevised
{
public static final double OVERTIME_PAY_RATE = 1.5;
public static final double REGULAR_PAY_RATE = 1.0;
public static void main(String[] args)
{
grabHourlyWages();
calculateMondayPay();
calculateTuesdayPay();
calculateWednesdayPay();
calculateThursdayPay();
calculateFridayPay();
calculateTotalPay();
}
public static double grabHourlyWages()
{
Scanner reader = new Scanner(System.in);
System.out.println("Hourly wage");
double hourlyWage = reader.nextDouble();
double overtimeWage = hourlyWage * 1.5;
calculateMondayPay();
calculateTuesdayPay();
calculateWednesdayPay();
calculateThursdayPay();
calculateFridayPay();
return hourlyWage;
}
public static double calculateMondayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Monday");
double regularMonHours = reader.nextDouble();
System.out.println("Overtime hours on Monday");
double overtimeMonHours = reader.nextDouble();
double mondayPay =
(hourlyWage * regularMonHours) + (overtimeWage * overtimeMonHours);
return mondayPay;
}
public static double calculateTuesdayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Tuesday");
double regularTuesHours = reader.nextDouble();
System.out.println("Overtime hours on Tuesday");
double overtimeTuesHours = reader.nextDouble();
double tuesdayPay =
(hourlyWage * regularTuesHours) + (overtimeWage * overtimeTuesHours);
return tuesdayPay;
}
public static double calculateWednesdayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Wednesday");
double regularWedHours = reader.nextDouble();
System.out.println("Overtime hours on Wednesday");
double overtimeWedHours = reader.nextDouble();
double wednesdayPay =
(hourlyWage * regularWedHours) + (overtimeWage * overtimeWedHours);
return wednesdayPay;
}
public static double calculateThursdayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Thursday");
double regularThursHours = reader.nextDouble();
System.out.println("Overtime hours on Thursday");
double overtimeThursHours = reader.nextDouble();
double thursdayPay =
(hourlyWage * regularThursHours) + (overtimeWage * overtimeThursHours);
return thursdayPay;
}
public static double calculateFridayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Friday");
double regularFriHours = reader.nextDouble();
System.out.println("Overtime hours on Friday");
double overtimeFriHours = reader.nextDouble();
double fridayPay =
(hourlyWage * regularFriHours) + (overtimeWage * overtimeFriHours);
return fridayPay;
}
public static double calculateTotalPay()
{
double mondayPay = calculateMondayPay();
double tuesdayPay = calculateTuesdayPay();
double wednesdayPay = calculateWednesdayPay();
double thursdayPay = calculateThursdayPay();
double fridayPay = calculateFridayPay();
double TotalPay =
mondayPay + tuesdayPay + wednesdayPay + thursdayPay + fridayPay;
return TotalPay;
}
}
sdayPay();
calculateThursdayPay();
calculateFridayPay();
calculateTotalPay();
}
public static double grabHourlyWages()
{
Scanner reader = new Scanner(System.in);
System.out.println("Hourly wage");
double hourlyWage = reader.nextDouble();
double overtimeWage = hourlyWage * 1.5;
calculateMondayPay();
calculateTuesdayPay();
calculateWednesdayPay();
calculateThursdayPay();
calculateFridayPay();
return hourlyWage;
}
public static double calculateMondayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Monday");
double regularMonHours = reader.nextDouble();
System.out.println("Overtime hours on Monday");
double overtimeMonHours = reader.nextDouble();
double mondayPay =
(hourlyWage * regularMonHours) + (overtimeWage * overtimeMonHours);
return mondayPay;
}
public static double calculateTuesdayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Tuesday");
double regularTuesHours = reader.nextDouble();
System.out.println("Overtime hours on Tuesday");
double overtimeTuesHours = reader.nextDouble();
double tuesdayPay =
(hourlyWage * regularTuesHours) + (overtimeWage * overtimeTuesHours);
return tuesdayPay;
}
public static double calculateWednesdayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Wednesday");
double regularWedHours = reader.nextDouble();
System.out.println("Overtime hours on Wednesday");
double overtimeWedHours = reader.nextDouble();
double wednesdayPay =
(hourlyWage * regularWedHours) + (overtimeWage * overtimeWedHours);
return wednesdayPay;
}
public static double calculateThursdayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Thursday");
double regularThursHours = reader.nextDouble();
System.out.println("Overtime hours on Thursday");
double overtimeThursHours = reader.nextDouble();
double thursdayPay =
(hourlyWage * regularThursHours) + (overtimeWage * overtimeThursHours);
return thursdayPay;
}
public static double calculateFridayPay()
{
double hourlyWage = grabHourlyWages();
double overtimeWage = grabHourlyWages();
Scanner reader = new Scanner(System.in);
System.out.println("Regular hours on Friday");
double regularFriHours = reader.nextDouble();
System.out.println("Overtime hours on Friday");
double overtimeFriHours = reader.nextDouble();
double fridayPay =
(hourlyWage * regularFriHours) + (overtimeWage * overtimeFriHours);
return fridayPay;
}
public static double calculateTotalPay()
{
double mondayPay = calculateMondayPay();
double tuesdayPay = calculateTuesdayPay();
double wednesdayPay = calculateWednesdayPay();
double thursdayPay = calculateThursdayPay();
double fridayPay = calculateFridayPay();
double TotalPay =
mondayPay + tuesdayPay + wednesdayPay + thursdayPay + fridayPay;
return TotalPay;
}
}
我上课的任务是获取用户的小时工资,周一至周五每一天的正常工作时间和加班小时数。然后计算总工资。他们只是介绍了方法,所以虽然您可以在main方法中做到这一点,但我的老师特别告诉我们,我们需要每天在各自的方法中进行计算,并且仅将main方法用作调用其他方法的地方,而不用它实际进行任何计算。
我已经停下来了,因为我不确定从现在开始该怎么做。我为工作日的每一天创建了五种方法,并且为计算创建了方法。问题是,如何设置方法?我做了
calculateTotalPay(星期一付款,星期二付款,星期三付款,星期四付款,星期五付款)
但是我无法从这五个方法中的每一个发送信息,因为当我说mondayPay方法时,我不能仅发送一个参数,因为calculateTOtalPay方法需要5个参数,而且我也无法发送参数分别因为我不知道如何。帮助..?
java的新手,很抱歉,如果我的问题很愚蠢,唯一没有提出建议答案的原因可能是因为我不知道该问题的措辞。
答案 0 :(得分:1)
简单:您的所有方法都是无效的。
将其更改为返回计算结果!然后,调用这些方法的方法将具有一种很好的方法来获取返回的结果。
因此:将返回类型更改为适当的类型(可能是双精度类型),然后向每个方法添加一个return语句。
double someResult = callMyMethod();
是下一步。