1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
alukav5142 [94]
3 years ago
11

Write a program that asks the user to enter the amount s/he has budgeted for a month. The amount should be between 1000 and 2000

(do an input validation). A loop should then prompt the user to enter each of the expenses (show at least 3 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 or exactly on budget. # Hints # Declare variables to store the budget amount, amount spent, difference, and total. # Initialize for while loop # Get the budgeted amount from the user and do input validation # Get the total amount spent from the user (while statement starts, make sure to enter exit criteria) # Determine whether the user is over or under budget, and display the result (if elif else) # print what was the budgeted amount # print what was the amount spent
Computers and Technology
1 answer:
Elena-2011 [213]3 years ago
5 0

Answer:

The program to this question can be given as:

Program:

  //import package for user input.

import java.util.*;      

//define class

public class Budget                      

{

public static void main(String [] a)            //define main method.

{

//creating Scanner class object.

Scanner ob =new Scanner(System.in);    

//define variable.      

double budgetamount=0, amountspent=0 ,difference=0,total=0,num=0 ;        

int count = 0;                            

System.out.println("How much have you budgeted for the month? :");        //print message.

budgetamount=ob.nextDouble();                             //taking input

       while(budgetamount != 0)           //checkig number greater then 4 digite.

       {

           budgetamount= budgetamount/10;        

           ++count;

       }

       if(count>4)                 //condition

       {

       System.out.println("enter each expense, then type -999 to quit: ");

       while(num!=-999)               //taking expense  

       {

       total=total+num;                 //totaling expense

       num=scan.nextDouble();                  

       }

       if(total<=budgetamount)           //condtion for over budget.

       {

       System.out.print("under budget:");         //print message

       System.out.print(budgetamount-total);

       }

       else

       {

       System.out.print("over budget:");              //for under budget

       System.out.print(total-budgetamount);

       }

       }

       else

       {

       System.out.println("not valid");        //message for number lessthen 4 digit.    

       }                                      

}

}

output:

How much have you budgeted for the month? : 1200.55.

enter each expense, then type -999 to quit: 365.89

556.90

339.98

-999

over budget:1262.77

Explanation:

The explanation of this program can be given as:

In the above program we import the package in that is used for scanner class. This class is used for the input from the user after input we use the while loop and if-else statement. The while loop is the entry control loop It is used for input validation and if-else is used for the checking condition. Then we insert expense that is inserted by the user. Then we calculate under-budgeted and over-budgeted by conditional statement that is if-else. and at the last we print it.

You might be interested in
True or False: You cannot change the default margin size for Word documents.  
Veronika [31]
The answer is false because you can change the margin size on words documents.
8 0
3 years ago
Differentiate Between register and Memory location (
trasher [3.6K]

Answer:

Register-it contains all the instructions that are present in the processor.

Memory location- it is the particular memory address where the data is stored.

Explanation: Difference between register and memory location are as follows :-

  • Register are the found in the CPU internal storage and memory location is present on the RAM.
  • Registers are faster in movement as compared to the memory location.
  • Register has the capacity of holding of less data as compared to the memory location which can store data in large amount .

7 0
3 years ago
This is your data.
Dmitriy789 [7]
The answer is B Hope this helps
7 0
3 years ago
Read 2 more answers
Jacob is a website designer. Whenever his company takes on a new project, Jacob takes the initiative and comes up with ideas and
Troyanec [42]
Eating a potato is what hes using
3 0
2 years ago
¿Por qué es importante usar adecuadamente el celular?
posledela

Answer:

to stop it from breaking

Explanation:

5 0
2 years ago
Other questions:
  • What would be the desired output of a home security system?
    6·1 answer
  • Tommy has hired a marketing company to create a billboard advertisement
    11·2 answers
  • The Microsoft-NanoServer-Guest-Package installs the drivers necessary for installing Nano Server as a host OS on a physical mach
    15·1 answer
  • Help PLEASE (in attachment)
    8·1 answer
  • Why are answers not appearing? I've seen many complain about this recently.
    8·1 answer
  • Pls help
    15·2 answers
  • How do you change the order of the slides in your presentation in the slide pane 
    15·2 answers
  • Explain the term creating in word processing​
    12·1 answer
  • 15. Virus cannot infect files that are saved in i. USB ii. CD-ROMs iii. Memory card iv. All of them​
    14·2 answers
  • After a Hacker has selects her target, performed reconnaissance on the potential target's network, and probed active Internet Ad
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!