Program functionality. The program asks a user for their hourly wage and the num
ID: 3749680 • Letter: P
Question
Program functionality. The program asks a user for their hourly wage and the number of hours they work per week. It then uses the SalaryCalculator object to do the monthly and yearly (annual) salary calculations and prints these results to the console. What you need to do: There are three places in the salaryCalculator class that you need to add code. They are marked by TODO in the comments (see figure 5). 1. 2. 3. Implement the constructor by initializing the two member variables. Implement the calculateAnnualSalary method. Implement the calculateMonthlysalary method. Figure 5 public SalaryCalculator ) ITODO: initialize workingWeeksPerYear to 50, monthsPe *TODO: Implement this method * This method calculates and returns the annual (yearly) * and the hours worked per week. public double calculateAnnualsalary (double hourlywage, dou return 0.0; *TODO: Implement this method * This method calculates and returns the monthly salaryb * and the hours worked per week public double calculateMonthlySalary (double hourlywage, do return 0.0;Explanation / Answer
import java.util.*;
class SalaryCalculator
{
private int workingWeeksPerYear,workingWeeksPerMonth;
public SalaryCalculator()//default constructor
{
workingWeeksPerYear = 50;
workingWeeksPerMonth = 4;
}
public double calculateAnnualSalary(double hourlyWage,double hoursWeek )
{
return workingWeeksPerYear * hourlyWage*hoursWeek;
}
public double calculateMonthlySalary(double hourlyWage,double hoursWeek )
{
return workingWeeksPerMonth * hourlyWage*hoursWeek;
}
}
class Test
{
public static void main (String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter the hourly wage : ");
double hourlyWage = input.nextDouble();
System.out.println("Enter the number of working hours per week : ");
double hoursWeek = input.nextDouble();
SalaryCalculator sc = new SalaryCalculator();
System.out.printf("Annual Salary : $%.2f",sc.calculateAnnualSalary(hourlyWage,hoursWeek));
System.out.printf(" Monthly Salary : $%.2f",sc.calculateMonthlySalary(hourlyWage,hoursWeek));
}
}
Output:
Enter the hourly wage :12.3
Enter the number of working hours per week :38.5
Annual Salary : $23677.50
Monthly Salary : $1894.20
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.