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;
}
}
My assignment for a class is to take the hourly wage of the user, the number of regular hours and overtime hours worked for each individual day of Mon-Fri. Then calculate the total pay. They just introduced methods, so while you could just do this in the main method, my teacher specifically told us that we needed to do calculations for each day in a respective method, and only use the main method as the place to call the other methods, and not use it to actually do any calculations.
I have come to a stop, because I'm not sure what to do from this point on. I have created my five methods for each day of the work week, and I created my method for the calculations. The thing is, how do I set up the method? I did
calculateTotalPay(mondayPay, tuesdayPay, wednesdayPay, thursdayPay, fridayPay)
However I can't send the information from each of the five methods because when I go into say the mondayPay method I can't send just one argument since the calculateTOtalPay method takes 5 arguments, and I can't send the arguments separately because I don't know how. Help..?
very new to java so sorry if my question is stupid, only reason it didn't come up as a suggested answer is probably because I didn't know how to word the question.
Simple: all your methods are void.
Change them to return the result of their computation! Then the method invoking these methods has a nice and clean way to acquire said returned result.
So: change the return type to the appropriate type (probably double) and add a return statement to each method.
double someResult = callMyMethod();
Is the next step then.