Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with a java code. Write a program that asks the user to enter the amou

ID: 3646385 • Letter: N

Question

Need help with a java code. 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) );
}
}