Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C. F22 - Budget App In the main method , write a loop that asks whether the entry is a D eposit, an E xpense,

C. F22 - Budget App

In the main method, write a loop that asks whether the entry is a Deposit, an Expense, or X to exit. Then call a method called enterDeposit or enterExpense depending on the selection. Depending on the entry type, the methods should return an amount added to a total deposit or expense variable. Be sure to validate the entry type variable. When they enter X to exit, use printf to print the total deposits, the total expenses, and the net amount (deposits - expenses). In the enterDeposit method, ask what the deposit is for (ex: paycheck, refund, interest, etc), the date, and the deposit amount. Then, print the date, the description, and the amount using System.out.printf. Pass back the amount to main and add it to a total Deposit variable. In the enterExpense method do the same thing, ask what the expense is for (food, water, phone, rent, electric, etc), the date, and the amount of the expense. Then, print the date, the description, and the amount using System.out.printf. Pass back the amount to main and add it to a total Expense variable. We'll do something like this in Chapter 7 using the ArrayList (so don't do it now).

Sample Output:

Budget item Paycheck on 10/01/2022 for $2,000.00 Budget item House Payment on 10/01/2022 for $-1,000.00 Budget item Electric on 10/05/2022 for $-240.00 Budget item Paycheck on 10/15/2022 for $2,000.00 Budget item Water on 10/22/2022 for $-110.00 Budget item VISA on 10/20/2022 for $-750.00 Total Deposits = $4,000.00 Total Expenses = $-2,100.00 Net Amount = $1,900.00

Hints/Tips (Read the hints for this one, there are a lot of concepts I used to get better results)

      • Use JOptionPane to get data from the user so that your report isn't interrupted by getting the data.
      • This would be a good place for a While loop. You should ask for the entry type first, then get into the loop. If they put X on the first one, the loop exits without doing any statements. Because you ask for the entry type before the loop, you must ask for it again in the loop after you process the first entry.
      • I used switch to check the entry type. I included X as a case so I could use default to display a message for validating the method for a valid type.
      • Be sure to get the entry type for the next budget item after processing the prior entry
      • Ensure the expense amount shows negative when you print it, expecting the user to enter a positive amount. I put $- before the % to display it as negative. I subtracted the expense from the deposits since the expenses are entered as a positive number. On the description string, I put %15s, so it pads to 15 characters.
      • At the end of JOptionPane, put .toUpperCase().charAt(0), and it will return a char with the uppercase value of the data entered by the user. Thus, you don't have to check for upper or lower because it will be upper.
      • This took me almost an hour to do, but I changed and updated the assignment to make it clearer. I include some pseudocode here to help you with the program flow. // Declare variables // Ask user for input // Loop until user exits // Decision structure to either process deposit or expense or exit // Ask user for input // Print output (last 3 lines from sample) // Stop JOptionPane // Enter Deposit Method // Ask user for description, date, and amount // Print detail line (see sample) // Return amount // Enter Expense Method // Same actions as deposit

Rubric

      • Doesn't have method to enter deposits -50%
      • Doesn't have method to enter expenses -50%
      • Doesn't ask user for information -20%
      • Doesn't print deposit and expense details -25%
      • Doesn't print summary -15%
      • Doesn't validate user input for entry type -15%
      • Code not formatted/indented properly -2%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Programming questions

Question

Create a Fishbone diagram with the problem being coal "mine safety

Answered: 1 week ago

Question

Explain the basics of motivation. AppendixLO1

Answered: 1 week ago