Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PROBLEM DESCRIPTION : 1) The Accounting Department needs your help to fix expense reports; apparently, something isn't quite adding up. Your task is to write
PROBLEM DESCRIPTION : 1) The Accounting Department needs your help to fix expense reports; apparently, something isn't quite adding up. Your task is to write a Java class named ExpenseCheck in a class file called ExpenseCheck.java. 2) The ExpenseCheck class contains a single attribute; an ArrayList of Integer values named expenses. 3) Write the following public methods as members of the ExpenseCheck class: a) A lone constructor that takes one argument, a String called filename. The constructor opens and reads from a text file specified by filename storing the results in the expenses attribute. i) The main method will provide the filename as the argument to the constructor call. ii) The file contains text representation of integer values, one per line. ii) All values in the file should be read as type int and stored in expenses. iv) Recall that, unlike an array, an ArrayList can implicitely "grow" to store all values within the file. v) If the file does not exist or an error occurs reading from the file, then an IOException is thrown by the method. b) A public method called calcProduct takes a single parameter of type int called sumValue. i) The method then determines the first two distinct entries in the expenses attribute that sum to sumValue. ii) The method returns the product of the two values; that is, the result when the two numbers are multiplied together. ii) If the method does not find two value that sum to sumValue, then null is returned. 4) For example, suppose for a given sumValue of 2020, an expense report contained the following values: 1721 979 366 299 675 1456 5) In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579. 6) Your submission should NOT contain a main method or any extraneous testing code. If you wish to include non-working code for insight into your thought process, make sure to contain it within comment blocks and ensure that submission successfully compiles
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started