Question

In: Computer Science

For this week's assignment analyze a family's spending habits by creating a program that performs arithmetic...

For this week's assignment analyze a family's spending habits by creating a program that performs arithmetic calculations. The program should ask the user to enter information for the following questions. How much does the family spend on groceries per month? How much does the family spend on dining out per month? How much does the family spend on entertainment per month? How much does the family spend on rent/mortgage per month? How much does the family spend on utilities per month? How many family members are there? What is the family income per year? Questions 1–5 and 7 should accept decimal values from the user. Question 6 should accept an integer from the user. The program should output the total amount that the family spent on food per month. This includes groceries and dining out. The program also needs to output the total amount spent on living expenses each month. This is the sum of rent/mortgage and utilities. The program should also display the entertainment expenses per person per month. Finally, the program needs to show the family surplus (deficit if the number is negative). This is the income minus all expenses. But remember that the expenses are input as monthly numbers and the income is yearly, so you will need to convert the monthly expenses to yearly numbers to calculate the surplus.

Please use Java &

On top: import java.util.Scanner;

import java.text.DecimalFormat;

Then in the body of (your code), create a new format just like you created a scanner.

Like this: DecimalFormat df = new DecimalFormat(".0

Solutions

Expert Solution

import java.util.Scanner;

public class FamilySpending {

public static void main(String[] args) {

Scanner input=new Scanner(System.in);

System.out.print("How much does the family spend on groceries per month?");
double grocery_month=input.nextDouble();
System.out.println("How much does the family spend on dining out per month?");
double dining_month=input.nextDouble();
System.out.println("How much does the family spend on entertainment per month?");
double entertainment_month=input.nextDouble();
System.out.println("How much does the family spend on rent/mortgage per month?");
double rent_month=input.nextDouble();
System.out.println("How much does the family spend on utilities per month?");
double utilities_month=input.nextDouble();
System.out.println("How many family members are there?");
int number_family=input.nextInt();
System.out.println("What is the family income per year?");
double family_income=input.nextDouble();
System.out.println("Total food expenses each month = "+(grocery_month+dining_month));
System.out.println("Total amount spent on living expenses each month = "+(rent_month+utilities_month));
System.out.println("Entertainment expenses per person per month = "+(entertainment_month/number_family));
double total_expense=grocery_month+dining_month+entertainment_month+rent_month+utilities_month;
double income_month= (family_income/12.0);
double defict=income_month-total_expense;
System.out.println("Surplus/Deficit is: "+ defict);


}

}


Related Solutions

Write a program that performs the following two tasks in java Reads an arithmetic expression in...
Write a program that performs the following two tasks in java Reads an arithmetic expression in an infix form, stores it in a queue (infix queue) and converts it to a postfix form (saved in a postfix queue). Evaluates the postfix expression. Use linked lists to implement the Queue and Stack ADTs. DO NOT USE BUILT IN JAVA CLASSES
Write a program that performs the following two tasks: Reads an arithmetic expression in an infix...
Write a program that performs the following two tasks: Reads an arithmetic expression in an infix form, stores it in a queue (infix queue) and converts it to a postfix form (saved in a postfix queue). Evaluates the postfix expression. Use the algorithms described in class/ lecture notes. Use linked lists to implement the Queue and Stack ADTs. Using Java built-in classes will result in 0 points. You must use your own Stack and Queue classes (my code is a...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
/* CIS 251 In Class Assignment    This program performs various operations on a ten element...
/* CIS 251 In Class Assignment    This program performs various operations on a ten element int array. */ #include <iostream> using namespace std; void start (int boxes [10]); void move (int squares [10], int x, int y, int z); void add (int arr [10], int first, int last); void print (int arr [10]); int main () { int my_arr [10];    cout << "The original array is:\n"; print (my_arr);    start (my_arr); cout << "\n\nThe array after start is:\n";...
Write a C++ program that start the assignment by creating a file named pointerTasks.cpp with an...
Write a C++ program that start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one. For each step, include a comment in your program indicating which step you are completing in the following statement(s). The easiest way to do this is copy and paste the below...
Write a C++ program that start the assignment by creating a file named pointerTasks.cpp with an...
Write a C++ program that start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main() to accomplish each of the tasks listed below. Some of the tasks will only require a single C++ statement, others will require more than one. For each step, include a comment in your program indicating which step you are completing in the following statement(s). The easiest way to do this is copy and paste the below...
For this assignment you will be creating a basic Hotel Reservation System. The program must meet...
For this assignment you will be creating a basic Hotel Reservation System. The program must meet the following guidelines: User can reserve up to 3 rooms at a time Your program will need to loop through to continue to ask needed questions to determine cost. Room rates (room variants): Suite $250 2 Queens $150 1 King $175 Ocean view add $50 Fridge for Room $25 Pets additional $50 Sales tax rate will be 5.5% Your program will show out the...
Program Slicing Assignment 1- Choose a program you’d like to analyze. Explain what the program’s purpose...
Program Slicing Assignment 1- Choose a program you’d like to analyze. Explain what the program’s purpose is and how many lines of code it has. 2- Browse the tools necessary for slicing and install if you haven’t already done so. If there is a problem with the tool, and you would not like to use it, explain: What the tool is used for, and why wouldn’t use it. 3- demonstrate static, dynamic, forward, and backward slicing using a slicing criterion....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT