Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify your lab from week 5 (discounts multi-way with formatted output) so that the user may repeat this as many times as they wish using

Modify your lab from week 5 (discounts multi-way with formatted output) so that the user may repeat this as many times as they wish using a sentinel value loop. Use a sentinel value loop (page 166). Use a sales amount of 0 as the sentinel value. Count the transactions, and total the amount due.

I started this but I can't figure out how to correctly use the "while"

import java.util.Scanner; public class assignment5 { public static void main(String [] args) { // Create a Scanner object Scanner input = new Scanner (System.in);

///Prompt user to enter employees name, hours worked, and hourly pay System.out.print("Enter employee's first and last name: " ); String firstName = input.next(); String lastName = input.next(); System.out.print("Enter number of hours worked: " ); double hoursWorked = input.nextDouble(); System.out.print("Enter hourly pay rate: " ); double payRate = input.nextDouble();

// Declare variables double regularPay; double overtimePay; double grossPay; double deductions; double netPay; final double federalTax = (.2); double tax;

//Determine the pay based on hours worked if (hoursWorked <= 40) { overtimePay = 0; regularPay = hoursWorked * payRate; } else { overtimePay = (hoursWorked - 40) * payRate * 1.5; regularPay = 40 * payRate; }

//Calculations of gross pay, deductions, and final amount grossPay = (regularPay + overtimePay); tax = federalTax * grossPay; deductions = tax; netPay = (grossPay - deductions);

//Outputs System.out.println("Employees name: " + lastName + ", " + firstName ); System.out.printf("Hours worked: %2.2f " , hoursWorked ); System.out.printf("Hourly Rate: %2.2f " , payRate ); System.out.printf("Gross Pay: %2.2f " , grossPay ); System.out.printf("Regular pay: %2.2f/n " , regularPay); System.out.printf("OvertimePay: %2.2f/n " , overtimePay); System.out.printf("Deductions: %2.2f " ); System.out.printf("Federal Tax: %2.2f/n " , tax); System.out.printf("TotalDeductions: %2.2f/n " , tax); System.out.printf("Net Pay: %2.2f " , netPay );

input.close(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions