Write a program that asks the user to enter the amount of the users paycheck for
ID: 3646176 • Letter: W
Question
Write a program that asks the user to enter the amount of the users paycheck for the month. A loop should then prompt the user to enter each of his or her expenses for the month, and keep a running total. Expenses should include housing, utilities, insurance cost, food, and other. When the loop finishes, the program should display the amount of disposable income that is available. Disposable income is the amount of the paycheck - all monthly expenses. If there is no disposable income at the end of the month then display the following message "You are over budget for this month."Explanation / Answer
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
double paycheck;
Scanner in = new Scanner(System.in);
System.out.println(" enter paycheck for this month");
paycheck = in.nextDouble();
double sum = 0;
double expense = 0;
while(expense != -1)
{
sum = sum + expense;
System.out.println(" enter expense for this month" );
expense = in.nextDouble();
}
if(sum > paycheck)
{
System.out.println("You are over budget for this month." );
}
else
System.out.println("Disposable income is " + (paycheck - sum) );
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.