Annual Expense Estimator (Arrays) solution

Annual Expense Estimator (Arrays) solution

In this assignment, you will implement a simple “Annual Expense Estimator” to tabulate your expense items. Expenses are an important component of a personal income statement. The most accurate way of coming up with your income statement is to keep a record of all incomes and expenses. If year–round record keeping is not possible, professional financial advisers often
ask you to keep track of all income and expense records for 2-3 months, then the records can be used to estimate the annual value.
When no record is available at all, you can still estimate your annual expenses.

One way to estimate is to list expense items according to their occurrence frequencies and the estimated amount each time the expense occurs. Then you can calculate the annual total of each item and the grand total of all expense items. If you store expense items (amount and frequency) in
a 2-D array, you will use array notation to calculate the annual total of each expense item, e.g., expenses[i][0]*expenses[i][1].
Your program should produce formatted output similar to the following table. The “. . . ”
symbols here mean that additional items are omitted in the illustration. Your output should not have these “. . . ”. That is, the expense items in the table are for illustration purposes; you should use the opportunity to produce a list of items as complete as possible to best reflect your expenses. Identify and list at least six items. Item Frequency Times Amount Annual Total
Coffee Daily 365 5.50 2,007.50
Grocery Weekly 52 120.00 5,240.00
Phone Monthly 12 75.00 900.00
Tuition Semi-annually 2 6,500.00 13,000.00
… … … …
Total 31,408.50
1
Implementation Requirement
1. There must be no less than 6 expense items that occur at various frequencies.
2. Use a 1-D array to store the item names.
3. Use a 2-D array to store expense item’s amount and number of times it occurs in a year.
The array should have just 2 columns. Use double data type for the values in the array.
4. This program must be implemented with a class that includes three methods:
• void main(String[] arg). It is the entry point of the program with expense item
name, amount, and number of times occurred in a year hard coded and stored in
array variables with appropriate types. It calls the outputInfo method to produce the desired output.
• String getLabel(int times). The method returns a meaningful frequency label based on the value of the times parameter. For example, if times is equal to 365, return “Daily”; if it is equal to 12, return “Monthly”; and so on and so forth. You can use chained if … else
• void outputInfo(String item, int times, double amount). It produces the desired
output using printf method. It needs to call the getLabel method with times as
parameter to obtain the frequency label
5. The main method of the program should follow the process described below:
Declare and initialize the 1-D array for item names
Declare and initialize the 2-D array for item amounts and frequencies
Declare a variable for grand total and initialize it to 0
Begin for-loop
Add annual total to grand total
Output expense item ’s name , amount , frequency as a string , and annual
total
End for -loop
Output grand total
In the loop, you need to call outputInfo method. For example, if the 1-D array is names and
2-D array is expenses and the frequency is in the second column, you can invoke the method like
the following:
outputInfo (names[i],(int)expenses[i][1] , expenses[i][0])
Submission
Create your write-up using a word processor (e.g., Word). Make sure you include the following
parts:
• Title page. The title page should include the assignment information (e.g., Homework 1), your name, and a sentence summarizing what the program is about.
• Table of contents. List of all sections included in the submission. You do not need to have page number for each section.
• All sections. The required sections of this exercise include:
– Overview. A brief description of the program: its function, input (the input is tuition information hard-coded in the program), and output.
– Design and Implementation. A description of the design choices and structure of the program: class, methods, variables, and other notable functions used (e.g., printf).
Include a flowchart of the for–loop part of the main method. Also include a
UML class diagram of the class using the notation adopted in this course.
– Testing. Include screenshots to show the function (e.g., output) of the program.
– Discussion. Include the following discussions as subsections:
∗ Difficulties encountered and how you solved them.
∗ Sources of help you used.
∗ What did you learn in terms of programming?
∗ What did you learn in terms of personal finance?
∗ Any other lessons learned from the assignment.
– Source code. Include source code as text, not images. Include comments in the source code to document your understanding of the code.
Note: It is important for you to include all required parts. A working program only counts 60–70% of the points; documentation accounts for the rest of the points.

 
Powered by