2. The following program has compilation and logic errors. It also has unconvent
ID: 3888037 • Letter: 2
Question
2. The following program has compilation and logic errors. It also has unconventional names. Fix it!
public class netIncome {
/**
* Class exercise to compute net income
* gross income = hrs worked x rate per hr
* net income = gross income - (gross income * tax rate)
*
* Ouput MUST display gross and net incomes.
*/
public static void main(String[] args) {
int hoursworked;
double ratePerHour;
double taxRate = .10;
double grossIncome;
double netIncome;
Scanner scan = new Scanner(System.in);
System.out.print("Please enter the number of hours worked: ");
hoursWorked = scan.nextInt();
System.out.println("Please enter the rate per hour: ");
ratePerHour = input.nextDouble();
gross = hoursWorked * ratePerHr;
netIncome = (grossIncome - grossIncome )* taxRate;
System.out.printf("Gross income: %s Net Income: %s ", grossIncome, taxRate);
}
}
2) Find the gross and net income.
Input: # of hours worked (hours)
Rate per hour (rate)
Tax: %10 of gross income
Output: gross
net
Explanation / Answer
Hi
I have fixed the issues and highlighted the code changes below.
netIncome.java
import java.util.Scanner;
public class netIncome {
/**
* Class exercise to compute net income
* gross income = hrs worked x rate per hr
* net income = gross income - (gross income * tax rate)
*
* Ouput MUST display gross and net incomes.
*/
public static void main(String[] args) {
int hoursWorked;
double ratePerHour;
double taxRate = .10;
double grossIncome;
double netIncome;
Scanner scan = new Scanner(System.in);
System.out.print("Please enter the number of hours worked: ");
hoursWorked = scan.nextInt();
System.out.println("Please enter the rate per hour: ");
ratePerHour = scan.nextDouble();
grossIncome = hoursWorked * ratePerHour;
netIncome = grossIncome - (grossIncome * taxRate);
System.out.printf("Gross income: %s Net Income: %s ", grossIncome, netIncome);
}
}
Output:
Please enter the number of hours worked: 1500
Please enter the rate per hour:
5
Gross income: 7500.0
Net Income: 6750.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.