PLEASE USE JUST BASIC COMPILER ONLY : Using the Do...loop until, Write a program
ID: 3757644 • Letter: P
Question
PLEASE USE JUST BASIC COMPILER ONLY :
Using the Do...loop until, Write a program to input the salary. If the salary is over 100,000 then calculate the federal tax at 20% otherwise calculate the federal tax 15%. Display the federal tax.
Calculate the statetax at the rate of 5%
Also, Count the number of people who earned salaries in the following ranges.
1) More than 100000
2) More 50000 and less than 100000
3) More than 25000 and less than 50000
4) Below 25000
Ask the user if he/she wants to continue. If the user says “yes”, repeat the whole thing to fetch the salary of the next employee, calculate and display the federal tax, etc.
The program should also calculate the total federal tax and total state tax with held from all the employees. You can do this using accumulation concept.
Hint: Each time the computer calculates the federal tax for one employee, keep accumulating it.
Explanation / Answer
import java.util.Scanner;
public class Payroll
{
public static void main (String []args)
{
String name;
int hours;
double rate;
double fedTax;
double stateTax;
Scanner input = new Scanner(System.in);
System.out.print("Enter employee name: ");
name = input.next();
System.out.print("Enter number of hours worked in a week: ");
hours=input.nextInt();
System.out.print("Enter hourly pay rate: ");
rate=input.nextDouble();
System.out.print("Enter federal tax withholding rate: ");
fedTax=input.nextDouble();
System.out.print("Enter state tax withholding rate: ");
stateTax=input.nextDouble();
If(grossPay <= 10,0000)
{
counter++;
}
else if (grossPay <= 50,000 && grossPay > 10,0000)
{
counter++;
}
else if (grossPay <= 25,000 && grossPay > 50,000)
{
counter++;
}
else if grossPay > 10,0000)
{
counter++;
}
double grossPay;
grossPay = rate * hours;
double fedwithHolding;
if (grossPay < 10,0000)
{
fedwithHolding = (20/100) * grossPay;
}
else
{
fedwithHolding = (15/100) * grossPay;
}
double statewithHolding;
statewithHolding = (5/100) * grossPay;
double deduction;
deduction = fedwithHolding + statewithHolding;
double netPay;
netPay = (grossPay) - deduction;
System.out.println("The grosspay is $" +grossPay);
System.out.println("The netpay is $" +netPay);
System.out.println("Employee's name: " +name);
System.out.println("Number of hours worked in a week: "+hours);
System.out.println("Hourly pay rate: $"+rate);
System.out.println("Federal tax withholding rate: "+fedTax+"%");
System.out.println("State tax withholding rate: "+stateTax+"%");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.