A09
Due Date:
Friday, December 1
File(s) to be submitted:
MonthlyRevenue.java
Sample Output:
SampleOutput.html
Starter Files:
SUBMIT
/
Check
Employee (Arrays)
Summary
In this assignment,
we keep track of the amount of money a company generates
from its sales for every day of a given month.
Create a datatype class (MonthlyRevenue).
Include all appropriate instance variables and constants.
Your class needs to work with the driver program provided,
RevenueTester.java.
Note:
you will not be able to run the driver program
until you have created a MonthlyRevenue class with every method defined.
(Remember to start with stubs of all methods,
because it'd be a real pain
to have to write all that code
before you could test any of it!)
Details
You have been provided with a driver program (RevenueTester.java)
that tests a MonthlyRevenue class.
Your task is to write that class.
DO NOT CHANGE/SUBMIT RevenueTester.java.
The MonthlyRevenue class has two instance variables:
monthName (a String) and
dailyRevenues
(a double array to store their daily revenue values
(i.e., the dollar amount they have received by selling their products)
for all days of the month).
You also need to declare a constant called
DEF_NUM_DAYS
representing the array’s length,
which is set to 31.
The class has two constructors:
- Primary constructor takes initial values
for month name and the double array of values for revenues.
Note that when the passed array parameter has less than
DEF_NUM_DAYS elements,
the rest of the elements of
dailyRevenues will be set to
Double.NaN
(i.e., it means Not a Number).
For example,
for February,
the passed array parameter will probably have only 28 elements
which will be used to set the first 28 elements of
dailyRevenues
and the last 3 elements will be set to
Double.NaN.
- A secondary constructor takes only an initial value for
monthName,
and
dailyRevenues will be initialized to
Double.NaN for all its elements.
Note: Remember that the secondary constructor is supposed to call
the primary one!
You can pass an empty array to the primary constructor by using
new double[0] as the second argument.
The class has the following methods:
For more details,
see the sample output.
Note:
In getRevenue(int dayNum) method,
- if the requested dayNum is not between 1 and
DEF_NUM_DAYS
(e.g.,
dayNum is 32)
print the following error message:
ERROR: Invalid day number 32
and - if no number has been set for the corresponding element of
dailyRevenues
(e.g.,
dailyRevenues[28] is Double.NaN)
we will print something like:
No defined revenue amount for day#29
In both cases a) and b),
return Double.NaN after printing the message.
Similarly,
in setRevenue(int dayNum,
double value) method,
if the requested dayNum is not between 1 and
DEF_NUM_DAYS
(e.g.,
dayNum is 32)
print the following error message:
ERROR: Invalid day number 32
Hint: Utilize the Double.isNaN method to check whether a given element of
dailyRevenues is set to a number.
The method has a double parameter and returns true
if the argument is Double.NaN (not a number)
and false otherwise.
Grading Outline
- 7 (2+5) points: The program has 2 instance variables defined properly from appropriate data types.
- 3 points: The constant has been defined and set properly.
- 10 points: The primary constructor has been implemented properly to initialize both instance variables.
- 5 points: The secondary constructor has been implemented properly with a single line calling the primary constructor.
- 5 points: The method getMonthName works as expected.
- 5 points: The method getRevenue has been implemented properly
- 5 points: ... and functions correctly in case of invalid parameters or Double.NAN values
- 5 points: The method setMonthName has been implemented properly.
- 5 points: The method setRevenue has been implemented properly
- 5 points: ... and functions correctly in case of invalid parameters
- 5 points: The method setRevenue has been implemented properly
- 5 points: ... and functions correctly in case of invalid parameters
- 10 points: The method getMonthlyAverage works as expected.
- 10 points: The method getDayNumberWithHighestRevenue has been implemented properly.
- 10 points: The method toString has been implemented properly.
- 2 points: The opening Javadoc has been provided properly.
- 8 points: All methods have proper javadocs.
- 5 points: All style rules are followed including appropriate indentation, commenting and variable names.
SUBMIT
/
Check