Ask Question
9 March, 20:39

16. Budget Analysis Write a program that asks the user to enter the amount that he or she has budgeted for a month. A loop should then prompt the user to enter each of his or her expenses for the month, and keep a running total. When the loop finishes, the program should display the amount that the user is over or under budget.

+2
Answers (1)
  1. 10 March, 00:28
    0
    import java. util. Scanner;

    public class num8 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter month's budget");

    double monthBudget = in. nextDouble ();

    double totalExpenses = 0.0;

    double n;

    do{

    System. out. println ("Enter expenses Enter zero to stop");

    n = in. nextDouble ();

    totalExpenses + = n;

    }while (n>0);

    System. out. println ("Total expenses is "+totalExpenses);

    System. out. println ("The amount over your budget is " + Math. abs (monthBudget-totalExpenses));

    }

    }

    Explanation:

    Using Java programming language Prompt user for month's budget Use Scanner class to receive and store the amount entered in a variable Use a do while loop to continuously request user to enter amount of expenses Use a variable totalExpenses to add up all the expenses inside the do while loop Terminate the loop when user enters 0 as amount. Subtract totalExpenses from monthBudget and display the difference as the amount over the budget
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “16. Budget Analysis Write a program that asks the user to enter the amount that he or she has budgeted for a month. A loop should then ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers