Question

This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate it from the program’s output). Your output should match our examples exactly when given the same input. (Be mindful of spacing, such as after input prompts and between output sections.) Look at the other example logs on the course web site to get more examples of the program's behavior. The program begins with an introductory message that briefly explains the program. The program then prompts the user for the number of income categories, then reads in that many income amounts. Next, the program asks whether the user would like to enter monthly or daily expenses. (The user enters 1 for monthly and 2 for daily.) The program will then read in a number of expense categories and an amount for each category, similar to how income was read. The program should then print out the total amount of income and expenses for the month, as well as the average amount of each per day. You may assume a month has exactly 31 days, though your program should be able to be easily modified to change this assumption (see below). After printing the total income and expenses, the program should print out whether the user spent or earned more money for the given month and by how much. If income and expenses were exactly equal, the user is considered to have spent $0 more than they earned (as opposed to earning $0 more than they spent). Finally, the program should print out which category the user falls into based on their net income for the month. The user’s net income is the result of subtracting their expenses from their income. The four categories are defined as follows: More than +$250: "big saver" More than -$250 but not more than $0: "spender" More than $0 but not more than +$250: "saver" -$250 or less: "big spender" After printing the user’s category, print a custom message of your choice about their spending habits. This message should be different for each range shown above and should be at least 1 line of any non-offensive text you like. This program processes user input using a Scanner. All monetary inputs will be real numbers; all other input will be integers. You may assume the user always enters valid input. When prompted for a value, the user will enter a value of the correct type. The user will enter a number of income and expense categories ≥ 1, and will only ever enter 1 or 2 when asked how to enter expenses. The monetary amount for each category of income and expense will be a non-negative real number (including real numbers such as 3.14 or 89.705).

This program asks for your monthly income and expenses, then tells you your net monthly income.

How many categories of income? 3

Next income amount? $1000

Next income amount? $250.25

Next income amount? $175.50

Enter 1) monthly or 2) daily expenses? 1

How many categories of expense? 4

Next expense amount? $850

Next expense amount? $49.95

Next expense amount? $75

Next expense amount? $120.67

Total income = $1425.75 ($45.99/day)

Total expenses = $1095.62 ($35.34/day)

You earned $330.13 more than you spent this month.

You're a big saver.

You should define a class constant for the number of days in a month. You should refer to this constant throughout your program appropriately so that the value can be changed and your program will continue to function correctly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Budgeter.java

import java.util.Scanner;

public class Budgeter {

   /*
   * Creating an Scanner class object which is used to get the inputs entered
   * by the user
   */
   static Scanner sc = new Scanner(System.in);
   static final int MONTHDAYS = 31;

   public static void main(String[] args) {
       //calling the methods.
       aboutProgram();
       performCalculations();

   }

   /*
   * This method will get the inputs entered by the user
   * and perform the calculations
   */
   private static void performCalculations() {
       int icnt = 0;
       double totIncome = 0, income = 0, totMonthly = 0.0, totDaily = 0.0;
       int monthlyOrDaily;
       System.out.print("How many categories of income? ");
       icnt = sc.nextInt();
       for (int i = 0; i < icnt; i++) {
           System.out.print("Next income amount? $");
           income = sc.nextDouble();
           totIncome += income;
       }
       System.out.print("Enter 1) monthly or 2) daily expenses?");
       monthlyOrDaily = sc.nextInt();
       if (monthlyOrDaily == 1) {
           System.out.print("How many monthly categories of expense? ");
           int cntMonthly = sc.nextInt();
           totMonthly = getTotMonthlyExpences(cntMonthly);
           System.out.printf("Total income = $%.2f($%.2f/day)\n", totIncome,totIncome / MONTHDAYS);
           double monAvg = totMonthly / MONTHDAYS;
           System.out.printf("Total expenses = $%.2f($%.2f/day)\n",totMonthly, monAvg);

           calculateDiff(totIncome, totMonthly);
       } else {
           System.out.print("How many daily categories of expense? ");
           int cntDaily = sc.nextInt();
           totDaily = getDailyExpense(cntDaily);
           System.out.printf("Total income = $%.2f($%.2f/day)\n", totIncome,totIncome / MONTHDAYS);
           System.out.printf("Total expenses = $%.2f($%.2f/day)\n", totDaily*MONTHDAYS,totDaily);
           calculateDiff(totIncome, totDaily*MONTHDAYS);
       }

   }

   private static void calculateDiff(double totIncome, double totMonthly) {
       double amt = 0.0;
       if (totIncome >= totMonthly) {
           amt = totIncome - totMonthly;
           System.out.printf(
                   "You earned $%.2f more than you spent this month.\n", amt);
       } else {
           amt = totIncome - totMonthly;
           System.out.printf("You spent $%.2f more than they earned.\n", -amt);

       }

       displayCategory(amt);
   }

   /*
   * Ths method will display the category type based on the amount.
   */
   private static void displayCategory(double amt) {
       if (amt > 250) {
           System.out.println("You're a big saver.");
       } else if (amt > 0 && amt <= 250) {
           System.out.println("You're a saver.");
       } else if (amt > -250 && amt <= 0) {
           System.out.println("You're a spender.");
       } else if (amt <= -250) {
           System.out.println("You're a big spender.");
       }

   }

   private static double getDailyExpense(int cntDaily) {
       double amt = 0.0, totAmt = 0.0;
       for (int i = 1; i <= cntDaily; i++) {
           System.out.print("Next expense amount? ");
           amt = sc.nextDouble();
           totAmt += amt;
       }
       return totAmt;
   }

   private static double getTotMonthlyExpences(int cntMonthly) {
       double totMonthly = 0, expense = 0.0;

       for (int i = 1; i <= cntMonthly; i++) {
           System.out.print("Next expense amount? $");
           totMonthly += sc.nextDouble();
       }

       return totMonthly;
   }

   private static void aboutProgram() {
       System.out.println("This program asks for your monthly income and");
       System.out.println("expenses, then tells you your net monthly income.");

   }

}
__________________________

Output:

This program asks for your monthly income and
expenses, then tells you your net monthly income.
How many categories of income? 3
Next income amount? $1000
Next income amount? $250.25
Next income amount? $175.50
Enter 1) monthly or 2) daily expenses?1
How many monthly categories of expense? 4
Next expense amount? $850
Next expense amount? $49.95
Next expense amount? $75
Next expense amount? $120.67
Total income = $1425.75($45.99/day)
Total expenses = $1095.62($35.34/day)
You earned $330.13 more than you spent this month.
You're a big saver.


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • Analyze a family's spending habits by creating a program that performs arithmetic calculations. The program should...

    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...

  • In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a...

    In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a user for the number of interior and exterior murals scheduled to be painted during a month and computes the expected revenue for each type of mural. The program also prompts the user for the month number and modifies the pricing based on requirements listed in Chapter 4. Now, modify the program so that the user must enter a month value from 1 through 12....

  • Use python and use if, elif and else statements. Thank you! The program should first ask...

    Use python and use if, elif and else statements. Thank you! The program should first ask the user if they are a hero or a villain. If they enter “villain”, the program should ask them their name; if they enter “hero”, it should ask how many people they have saved, and respond to that information. Using decision structures, have your program execute certain print statements following these rules: If they enter that they are a villain Ask for their name...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Program In Assembly For this part, your MAL program must be in a file named p5b.mal....

    Program In Assembly For this part, your MAL program must be in a file named p5b.mal. It must have at least one function in addition to the main program. For the purposes of Part (b), you may assume the following 1. Any line of text typed by a user has at most 80 characters including the newline character. 2. A whitespace character refers to a space, a tab or the new line character. 3. A word is any sequence of...

  • In python coding please add functions/methods at least 3 of them. Please just adjust code I...

    In python coding please add functions/methods at least 3 of them. Please just adjust code I have provided and update it to include functions/methods. You can rearrange the code, edit or delete parts to add functions/methods. PLEASE DO NOT make a Whole New code. Please use what I have provided. I do not need a whole different code, just edits on what I have provided. THIS is the original question:Design a modular program that asks the user to enter the...

  • In this lab, you will write a C program to encrypt a file. The program prompts...

    In this lab, you will write a C program to encrypt a file. The program prompts the user to enter a key (maximum of 5 bytes), then the program uses the key to encrypt the file. Note that the user might enter more than 5 characters, but only the first 5 are used. If a new line before the five characters, the key is padded with 'a'; Note that the new line is not a part of the key, but...

  • Write a program **(IN C)** that displays all the phone numbers in a file that match the area code...

    Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT