Programming and Logic I Budget Assignment Create a program called Budget.java. My program would be ConwayBudget.java and my class name would be ConwayBudget. All the input from the user should be from...

1 answer below »
Programming and Logic I

Budget Assignment



Create a program called Budget.java. My program would be

ConwayBudget.java and my class name would be ConwayBudget.



All the input from the user should be from the command line (use the Scanner

object). You only need to create one Scanner object to handle all the input.

Do not use JOptionPane.



This program will simulate entering values for a monthly budget. It will total the

user’s expenses for the month and then indicate whether the user went over budget.

The program will not know how many values the user will enter. The user will

enter the sentinel value of -1 when the user has completed entering expenses.



The program will utilize a while loop to keep a running total of expenses. (Use a

while loop; do not use a do-while loop.) Before the loop begins, prompt the user

for the first expense (this is called a priming read). Within the loop, add the

expense to the running total. Then prompt the user for the next expense. The

program will also need to keep track of the number of expenses the user enters.

This can be accomplished by using a variable that is incremented by 1 within the

loop. The user will enter the value -1 when there are no more expenses to enter.

This sentinel value of -1 will terminate the loop.



The loop condition must be constructed to check for the sentinel value.



When the loop has completed, the program will print to the screen the total

budgeted for the month, the number of expenses, and expense total, and whether

the user was under, at or over budget.



Notes:

• Use a “priming read” before the loop begins. See code on page 220 for an

example.

• Several int variables (for expense total, expense count) will be needed for

the program to run properly. Initialize these variables to appropriate

values before the loop begins.

• The user can enter -1 as the first value if there are no expenses to enter.

The loop should not be entered in this case. Make sure to test for this.

• Test the program! Use the values shown in the sample output and make

sure the same results are printed.
Answered 9 days AfterOct 08, 2021

Answer To: Programming and Logic I Budget Assignment Create a program called Budget.java. My program would be...

Naval answered on Oct 18 2021
137 Votes
Assignment/Assignment Java.pdf
Budget Assignment
Create a program called Budget.java. My program would be
ConwayBudget.java and my class name would be ConwayBudget.
All the input from the user should be from the command line (use the Scanner
object). You only need to create one S
canner object to handle all the input.
Do not use JOptionPane.
This program will simulate entering values for a monthly budget. It will total the
user’s expenses for the month and then indicate whether the user went over budget.
The program will not know how many values the user will enter. The user will
enter the sentinel value of -1 when the user has completed entering expenses.
The program will utilize a while loop to keep a running total of expenses. (Use a
while loop; do not use a do-while loop.) Before the loop begins, prompt the user
for the first expense (this is called a priming read). Within the loop, add the
expense to the running total. Then prompt the user for the next expense. The
program will also need to keep track of the number of expenses the user enters.
This can be accomplished by using a variable that is incremented by 1 within the
loop. The user will enter the value -1 when there are no more expenses to enter.
This sentinel value of -1 will terminate the loop.
The loop condition must be constructed to check for the sentinel value.
When the loop has completed, the program will print to the screen the total
budgeted for the month, the number of expenses, and expense total, and whether
the user was under, at or over budget.
Notes:
• Use a “priming read” before the loop begins. See code on page 220 for an
example.
• Several int variables (for expense total, expense count) will be needed for
the program to run properly. Initialize these variables to appropriate
values before the loop begins.
• The user can enter -1 as the first value if there are no expenses to enter.
The loop should not be entered in this case. Make sure to test for this.
• Test the program! Use the values shown in the sample output and make
sure the same results are printed.
import java.util.Scanner;
public class ConwayBudget {
public static void main(String[] args) {
//for storing total budget of Month
float totalBudget = 0;
//for storing Number of Expenses
int numberOfExpenses = 0;
//for total Expenses of Month
float totalExpenses = 0;
//Scanner object initilization for taking system input through Keyboard
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the Value of monthly Budget :- ");
//taking total budget as input
totalBudget = scanner.nextFloat();
System.out.print("Enter " + (numberOfExpenses+1) + " expense or (-1) to end :-
" );
float expense = scanner.nextFloat();
//This loop will terminate when expense input will be -1
while(expense != -1){
//Adding expense to...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here