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:

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,

  1. 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
  2. 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


SUBMIT   /   Check