3) Class name: ExpensesFile.java (main program) and Expenses.java (class file) This is a continuation of Exercise...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
3) Class name: ExpensesFile.java (main program) and Expenses.java (class file) This is a continuation of Exercise 2 from week 5 practical exercises. Import a copy of Expenses.java that you developed for Exercise 2 Week 5 into your week 7 project in Eclipse. You will write a new main program for this exercise. Make the following changes to the Expenses class: Kevin Malone has realised that it would be easier for him to enter the weekly sales and expenses figures for each month into a text file that your program could then process. This will allow Kevin to store the data for several months in one file and process all months without re-entering data into the program each time he runs it. To achieve this, some changes are needed to the Expenses class and a new main program will need to be written. a. Add a data field named month - the name of the month for the expenses [a string] b. Add accessor and mutator methods for the month data field C. Add a constructor that takes a single argument (the name of the month) and sets all other data fields to 0 Write a main program named Expenses File.java that reads the data from the text file MalonesCones.txt instead of from the keyboard (ie, your program will no longer ask the user for the month name, number of weeks in the month or the weekly sales and expenses values since these are now in the text file), and that instantiates an Expenses object for each month that is read from the file. To do this, read the name of the month from the file; instantiate an Expenses object (using the constructor you created in part c. above) for the month; read sales and expenses data for each week of the month from the file; display the month name, balance, the total of income, total of expenditure, and Keleven from the month's expense object as shown in the example output of Figure 2. Note: Even though there are multiple months of data in the text file there is no need to 'remember' all Expenses objects that are created, hence, an array/arraylist is not to be used. An example of the file MalonesCones.txt has been included in this week's practical zip file. MalonesCones.txt contains data in the following format (suggestion: open the file in a text editor to confirm that you understand the structure and organisation of the data in the file): February 4 200 300 300 450 month name<space>number of weeks in month<eoln> sales week 1<space>expenses week 1<eoln> sales week 2<space>expenses week 2<eoln> sales week 3<space>expenses week 3<eoln> sales week 4<space>expenses week 4<eoln> <repeat pattern for subsequent months> 350 250 275 275 Make sure that your Java program checks that the file exists before attempting to read from it. If the file does not exist then handle this situation by informing the user that the file does not exist and then obtain a new file name/location from the user. You should also ensure that your code works correctly for different length files (ie, the input files used for marking your program may contain more or less lines of text than the example file provided). Figure 2 For Month of February: Balance: Total Sales: Total Expenses: Keleven: $-150.00 $1125.00 $1275.00 $150.00 For Month of March: Balance: Total Sales: Total Expenses: Keleven: $25.00 $1325.00 $1300.00 $0.00 For Month of April: Balance: $-256.80 Total Sales: $1103.05 Total Expenses: $1359.85 Keleven: $256.80 2. One of the accountant's at Dunder Mifflin, Kevin Malone, investigates the option of obtaining a bank loan to help pay off his gambling debt (https://www.youtube.com/watch?v=a86Pkl|WbnM). He tells the bank that he intends to use the loan to start an ice-cream business, named Malone's Cones, which will sell delicious ice- cream such as Fudge the Magic Dragon. Kevin needs a simple program that keeps track of his monthly expenditure for the business so that he doesn't accidently spend too much of the money - the balance at the end of the month should be either 0 or a positive value if he sells at least as much as he spends. Write an Expenses class that stores the monthly balance [a double], total of income (total of all sales or incoming moneys) for the current month [a double], total of expenditure (total of all outgoing money) for the current month [a double]. The class should have a set method for the balance data field and get methods for all data fields. The class should also have methods for adding the amount of a sale to the balance, subtracting the amount of an expenditure from the balance, accumulating the total of all incoming money in the month, accumulating the total of expenditure in the month. The class will also need a method to calculate Keleven to be able to balance the expenses if necessary (see note below). What is Keleven? Even though Kevin wants the balance to be 0 or positive at the end of the month he recognises that sometimes he may have essential purchases at different times (for example, pizza, hot dogs or pie) which means he may spend more than he earns from the ice-cream sales (ie, the balance will be less than 0). To balance the accounts in his daytime job at Dunder Mifflin Kevin employs a unique accounting method he calls a Keleven; he believes that a Keleven can be used in your program to balance his expenses each month when needed. Keleven is the amount added to the balance at the end of the month to ensure that the balance becomes 0. Write a program to test the Expenses class by: creating an expense object for the current month with a starting balance of $0, entering sales and expenditures on the expense object for each week in the month. At the end of the month display the balance, the total of income, total of expenditure, and Keleven from the expense object. Ensure that appropriate validation of user input is implemented. Figures 3, 4, 5 represent example executions of the program to assist you understand what the program needs to do: ● How many weeks this month? Sales & Expenditure for week 1: 200 300 Sales & Expenditure for week 2: 300 450 Sales & Expenditure for week 3: 350 250 Sales & Expenditure for week 4: 275 275 Month Balance: $-150.00 Total Sales: $1125.00 Total Expenses: Keleven: $1275.00 $150.00 Figure 3 How many weeks this month? 5 Sales & Expenditure for week 1: 200 200 Sales & Expenditure for week 2: 150 150 Sales & Expenditure for week 3: 350 400 Sales & Expenditure for week 4: 400 350 Sales & Expenditure for week 5: 200 200 Month Balance: $0.00 Total Sales: Total Expenses: Keleven: $1300.00 $1300.00 $0.00 4 Figure 4 How many weeks this month? Sales & Expenditure for week 1: 300 200 Sales & Expenditure for week 2: 450 300 Sales & Expenditure for week 3: 250 350 Sales & Expenditure for week 4: 275 275 Month Balance: $150.00 Total Sales: $1275.00 Total Expenses: $1125.00 Keleven: $0.00 Figure 5 3) Class name: ExpensesFile.java (main program) and Expenses.java (class file) This is a continuation of Exercise 2 from week 5 practical exercises. Import a copy of Expenses.java that you developed for Exercise 2 Week 5 into your week 7 project in Eclipse. You will write a new main program for this exercise. Make the following changes to the Expenses class: Kevin Malone has realised that it would be easier for him to enter the weekly sales and expenses figures for each month into a text file that your program could then process. This will allow Kevin to store the data for several months in one file and process all months without re-entering data into the program each time he runs it. To achieve this, some changes are needed to the Expenses class and a new main program will need to be written. a. Add a data field named month - the name of the month for the expenses [a string] b. Add accessor and mutator methods for the month data field C. Add a constructor that takes a single argument (the name of the month) and sets all other data fields to 0 Write a main program named Expenses File.java that reads the data from the text file MalonesCones.txt instead of from the keyboard (ie, your program will no longer ask the user for the month name, number of weeks in the month or the weekly sales and expenses values since these are now in the text file), and that instantiates an Expenses object for each month that is read from the file. To do this, read the name of the month from the file; instantiate an Expenses object (using the constructor you created in part c. above) for the month; read sales and expenses data for each week of the month from the file; display the month name, balance, the total of income, total of expenditure, and Keleven from the month's expense object as shown in the example output of Figure 2. Note: Even though there are multiple months of data in the text file there is no need to 'remember' all Expenses objects that are created, hence, an array/arraylist is not to be used. An example of the file MalonesCones.txt has been included in this week's practical zip file. MalonesCones.txt contains data in the following format (suggestion: open the file in a text editor to confirm that you understand the structure and organisation of the data in the file): February 4 200 300 300 450 month name<space>number of weeks in month<eoln> sales week 1<space>expenses week 1<eoln> sales week 2<space>expenses week 2<eoln> sales week 3<space>expenses week 3<eoln> sales week 4<space>expenses week 4<eoln> <repeat pattern for subsequent months> 350 250 275 275 Make sure that your Java program checks that the file exists before attempting to read from it. If the file does not exist then handle this situation by informing the user that the file does not exist and then obtain a new file name/location from the user. You should also ensure that your code works correctly for different length files (ie, the input files used for marking your program may contain more or less lines of text than the example file provided). Figure 2 For Month of February: Balance: Total Sales: Total Expenses: Keleven: $-150.00 $1125.00 $1275.00 $150.00 For Month of March: Balance: Total Sales: Total Expenses: Keleven: $25.00 $1325.00 $1300.00 $0.00 For Month of April: Balance: $-256.80 Total Sales: $1103.05 Total Expenses: $1359.85 Keleven: $256.80 2. One of the accountant's at Dunder Mifflin, Kevin Malone, investigates the option of obtaining a bank loan to help pay off his gambling debt (https://www.youtube.com/watch?v=a86Pkl|WbnM). He tells the bank that he intends to use the loan to start an ice-cream business, named Malone's Cones, which will sell delicious ice- cream such as Fudge the Magic Dragon. Kevin needs a simple program that keeps track of his monthly expenditure for the business so that he doesn't accidently spend too much of the money - the balance at the end of the month should be either 0 or a positive value if he sells at least as much as he spends. Write an Expenses class that stores the monthly balance [a double], total of income (total of all sales or incoming moneys) for the current month [a double], total of expenditure (total of all outgoing money) for the current month [a double]. The class should have a set method for the balance data field and get methods for all data fields. The class should also have methods for adding the amount of a sale to the balance, subtracting the amount of an expenditure from the balance, accumulating the total of all incoming money in the month, accumulating the total of expenditure in the month. The class will also need a method to calculate Keleven to be able to balance the expenses if necessary (see note below). What is Keleven? Even though Kevin wants the balance to be 0 or positive at the end of the month he recognises that sometimes he may have essential purchases at different times (for example, pizza, hot dogs or pie) which means he may spend more than he earns from the ice-cream sales (ie, the balance will be less than 0). To balance the accounts in his daytime job at Dunder Mifflin Kevin employs a unique accounting method he calls a Keleven; he believes that a Keleven can be used in your program to balance his expenses each month when needed. Keleven is the amount added to the balance at the end of the month to ensure that the balance becomes 0. Write a program to test the Expenses class by: creating an expense object for the current month with a starting balance of $0, entering sales and expenditures on the expense object for each week in the month. At the end of the month display the balance, the total of income, total of expenditure, and Keleven from the expense object. Ensure that appropriate validation of user input is implemented. Figures 3, 4, 5 represent example executions of the program to assist you understand what the program needs to do: ● How many weeks this month? Sales & Expenditure for week 1: 200 300 Sales & Expenditure for week 2: 300 450 Sales & Expenditure for week 3: 350 250 Sales & Expenditure for week 4: 275 275 Month Balance: $-150.00 Total Sales: $1125.00 Total Expenses: Keleven: $1275.00 $150.00 Figure 3 How many weeks this month? 5 Sales & Expenditure for week 1: 200 200 Sales & Expenditure for week 2: 150 150 Sales & Expenditure for week 3: 350 400 Sales & Expenditure for week 4: 400 350 Sales & Expenditure for week 5: 200 200 Month Balance: $0.00 Total Sales: Total Expenses: Keleven: $1300.00 $1300.00 $0.00 4 Figure 4 How many weeks this month? Sales & Expenditure for week 1: 300 200 Sales & Expenditure for week 2: 450 300 Sales & Expenditure for week 3: 250 350 Sales & Expenditure for week 4: 275 275 Month Balance: $150.00 Total Sales: $1275.00 Total Expenses: $1125.00 Keleven: $0.00 Figure 5
Expert Answer:
Answer rating: 100% (QA)
PROGRAMCODE Note All Java files and MalonesConestxt must be in same directory or location to get Currect Output Expensesjava public class Expenses private String month private double monthbalace 0 pri... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Write a literature review for your study. See below for an example of a literature review. Your literature review should provide both analysis and synthesis of previous studies as related to the...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Every real number is either a/an number or a/an_______ number.
-
Sparrow Company uses the retail inventory method to estimate ending inventory and cost of goods sold. Data for 2018 are as follows: The company records sales net of employee discounts. Discounts for...
-
Sue Lawlor is the management accountant at Tellie Manufacturing, an auto supplier that produces brake pads. Tellie's customers have high safety standards, and managers at Tellie believe they can gain...
-
In some people, the bones of the middle ear stiffen with age. This can result in deafness. Why?
-
Kingsport Containers, Ltd, of the Bahamas experiences wide variation in demand for the 200-liter steel drums it fabricates. The leakproof, rustproof steel drums have a variety of uses from storing...
-
Tangible and intangible factors are crucial to planning. You can form a financial decision by understanding what is influencing financial position. It also help categorize or separate your financial...
-
Following is partial information for the income statement of Timber Company under three different inventory costing methods, assuming the use of a periodic inventory system: Required: 1. Compute cost...
-
Determine how much of the total loan payment applies toward principal and how much applies toward interest for a student loan of $60,552 at a fixed APR of 6% for 13 years.
-
A 13-year, 6 percent coupon bond pays interest semiannually. The bond has a face value of $1,000. What is the percentage change in the price of this bond if the market yield to maturity rises to 5.7...
-
Below is a list of company monthly costs: Direct materials: $50,000 Direct Labor wages (hourly rate based): $30,000 Salary of factory supervisor: $5,000 Factory insurance cost: $1,000 Salary of HR...
-
Sally works for a company that needs to sell 10 mio EUR and buy Norwegian Krona (NOK) for delivery exactly three months from now (now is today, time zero). The current spot rate is 5.21 NOK = 1 EUR....
-
While going through PowerShell to organize files, Julie noticed an unknown data file. She proceeds to assign a value using the equal symbol, which further organizes the file setup. What did Julie...
-
Write an algorithm to reverse the elements of a stack using the stack's basic operations(push and pop).
-
Saddle Inc. has two types of handbags: standard and custom. The controller has decided to use a plantwide overhead rate based on direct labor costs. The president has heard of activity-based costing...
-
We all experience emotions, but some people disguise their true feelings better than others. Do you think this is a helpful or harmful thing to do? Under what conditions do you think it would be most...
-
If you wanted to pretend that you could do psychic readings, you could perform cold readings by inviting people you do not know to allow you to tell them about themselves. You would then make a...
-
The journal article reporting the experiment described in Case Study 21.1 (see ThysJacobs et al., 1998, in Chapter 21) compared the placebo and calcium-treated groups for a number of PMS symptoms,...
-
Refer to the previous exercise. In each case, state the null and alternative hypotheses. a. Researchers want to know if there is a relationship between having graduated from college or not and voting...
-
How can speakers use anxiety to their advantage?
-
What are common psychological, physical, and behavioral reactions associated with speech anxiety?
-
Describe strategies for making people the focus of your presentations.
Study smarter with the SolutionInn App