I have created a method in java in my menu list and I have to put...

50.1K

Verified Solution

Question

Programming

I have created a method in java in my menu list and I have toput all the work into the method but I cannot get it to print andam not sure where I am going wrong. this is my code:

public staticvoid main(String[] args) {

// TODO Auto-generated method stub

Scanner in = newScanner(System.in);

String fName = \"\";

String lName = \"\";

double hoursWorked;

double hourlyRate;

int optionOne = 1;

int optionTwo = 2;

int optionThree = 3;

int optionFour = 4;

int choice;

System.out.println(\"CalculatorMenu\");

System.out.println(\"1) WageCalculator\");

System.out.println(\"2) CouponCalculator\");

System.out.println(\"3) Roman NumberConverter\");

System.out.println(\"4) Exit\");

System.out.println(\"\");

System.out.println(\"Enter choice:\");

choice = in.nextInt();

switch(choice) {

case 1:

System.out.println(\"Enter first name:\");

fName = in.next();

System.out.println(\"Enter last name:\");

lName = in.next();

System.out.println(\"Enter hourly rate:\");

hourlyRate = in.nextDouble();

System.out.println(\"Enter hoursworked: \");

hoursWorked = in.nextDouble();

System.out.printf(\"Name: \" + fName +\",\" + lName);

System.out.println(\"\");

wageCalculator();

break;

case 2:

double purchaseAmount;

int purchaseType;

final double autoP = 1;

final double frag = 2;

final double acc = 3;

System.out.println(\"Enter purchaseamount: \");

purchaseAmount = in.nextDouble(); {

System.out.println(\"Choose purchasetype: \");

System.out.println(\"1) AutoParts\");

System.out.println(\"2)Fragrances\");

System.out.println(\"3)Accessories\");

purchaseType = in.nextInt();

} if (purchaseType == autoP) {

System.out.println(\"Your coupon is: $\"+ purchaseAmount*.10 + \"(Auto Parts)\");

} if (purchaseType == frag) {

System.out.println(\"Your coupon is: $\"+ purchaseAmount*.15 + \"(Fragrances)\");

} if (purchaseType == acc) {

System.out.println(\"Your coupon is: $\"+ purchaseAmount*.20 + \"(Accessories)\");

}

break;

case 3:

double calc_wages;

System.out.println(\"No option rightnow\");

break;

case 4:

System.out.println(\"Thank you forusing our program. Have a great day!\");

}

// public static int convertRomanNumber(String str). {

// }

}

private staticvoid wageCalculator() {

// TODO Auto-generated method stub

double hoursWorked = 0;

double hourlyRate = 0;

double overtimeHours;

double overtimePay = 0;

double regularPay = 0;

if (hoursWorked > 40) {

overtimeHours = hoursWorked - 40;

System.out.println(\"Overtime hours: \"+ overtimeHours);

overtimePay = overtimeHours*(1.5*hourlyRate);

System.out.println(\"Overtime Pay: \" +overtimePay);

hoursWorked = 40;

}

regularPay = hourlyRate*hoursWorked;

System.out.println(\"Regular hoursworked: \" + hoursWorked);

System.out.println(\"Regular Pay: $\" +regularPay);

System.out.printf(\"Total Pay $%.2f\",regularPay + overtimePay);

}

}

Answer & Explanation Solved by verified expert
3.5 Ratings (558 Votes)
SolutionYou were getting wrong output because you didnt passhourlyRatehoursWorked value to wageCalculator method You haveto passed these values explicitly as these values are used indiiferent function main and wageCalculator To get ProperOutput use wageCalculatorhourlyRatehoursWorked inside case1And Declare method asprivate static void wageCalculatordouble hourlyRatedoublehoursWorked TODO Autogenerated methodstub double overtimeHours double overtimePay 0 double regularPay 0 if hoursWorked 40 overtimeHours hoursWorked 40 SystemoutprintlnOvertime hours overtimeHours overtimePay    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students