Question

In: Computer Science

How to create a program Budget Enter the amount budgeted for the month: 400 Enter the...

How to create a program Budget

Enter the amount budgeted for the month: 400

Enter the expense (-1 to quite):100

Enter the expense (-1 to quite):-1

$400 budgeted.

1 expenses totaling $100.

$300 under budget.

Need to use sentinel value of -1, while loop

Solutions

Expert Solution

Program in java:

//importing class for user input
import java.util.Scanner;
//class declaration
public class Budget
{
   //main method
   public static void main(String args[])
   {
       //variables
       int budget,amt,totamt=0,count=0;
       //creating object for taking user input
       Scanner inp=new Scanner(System.in);
       //asking for user input
       System.out.print("Enter the amount budgeted for the month: ");
       //storing the value provided by user
       budget=inp.nextInt();
       //using do while loop to write the logic
       do
       {
           //asking for the expenses from user
           System.out.print("Enter the expense (-1 to quite): ");
           //storing user input
           amt=inp.nextInt();
           //if the passed value is not sentinel
           if(amt!=-1)
           {
               //increment the count
               count++;
               //reassign the total
               totamt=totamt+amt;
           }
       //checking for sentinel case to exit the loop
       }while(amt!=-1);
       //printing the results
       System.out.println("$"+budget+" budgeted.");
       System.out.println(count+" expenses totaling $"+totamt);
       System.out.println("$"+(budget-totamt)+" under budget.");
   }
}

Output:


Related Solutions

Write a program that will ask the user to enter the amount of a purchase. The...
Write a program that will ask the user to enter the amount of a purchase. The program should then compute the state and county sales tax. Assume the state sales tax is 5 percent and the county sales tax is 2.5 percent. The program should display the amount of the purchase, the state sales tax, the county sales tax, the total sales tax, and the total of the sale (which is the sum of the amount of purchase plus the...
Budget Problem Part A The ABC company manufactures bookcases that sell for $400. Budgeted sales for...
Budget Problem Part A The ABC company manufactures bookcases that sell for $400. Budgeted sales for first months are as follows: Month Budgeted Sales (units) January 1000 February 1500 March 2500 April 2000 Required Calculate sales budget in $ for each monthand total the first quarter Part B Each bookcase requires 30 square feetof oak at a cost of $10 per sq foot.. the company wants to maintain an inventory of bookcases equal to 10% of the following month,s sales....
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Create a program that will loop and prompt to enter the highlighted data items in the...
Create a program that will loop and prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine; const int NAME_SIZE = 20; const int STREET_SIZE = 30; const int CITY_SIZE = 20; const int STATE_CODE_SIZE = 3; struct Customers { long customerNumber; char name[NAME_SIZE]; char streetAddress_1[STREET_SIZE]; char streetAddress_2[STREET_SIZE]; char city[CITY_SIZE]; char state[STATE_CODE_SIZE]; int zipCode;     char isDeleted;     char newLine; }; Always set the item isDeleted to 'N' and...
Create a program that will loop and prompt to enter the highlighted data items in the...
Create a program that will loop and prompt to enter the highlighted data items in the structure below. This is every item except customerNumber , isDeleted and newLine; const int NAME_SIZE = 20; const int STREET_SIZE = 30; const int CITY_SIZE = 20; const int STATE_CODE_SIZE = 3; struct Customers { long customerNumber; char name[NAME_SIZE]; char streetAddress_1[STREET_SIZE]; char streetAddress_2[STREET_SIZE]; char city[CITY_SIZE]; char state[STATE_CODE_SIZE]; int zipCode;     char isDeleted;     char newLine; }; Always set the item isDeleted to 'N' and...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter payroll information Employee name and create variable for scanner Hours worked Hourly pay rate Federal tax rate State tax rate Declare variable doubles for gross pay, federal, state and total deduction Display payroll statement example: Name of employee Hours worked Hourly pay rate Gross pay which is equal hours worked multiply hourly pay rate Federal withholding which is equal of gross pay multiply federal...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT