Question: CPT 1 8 7 - Willie's Widget Factory Willie's Widget Factory makes widgets. They have several widget maker machines that run 2 4 / 7
CPT Willie's Widget Factory
Willie's Widget Factory makes widgets. They have several widget maker machines that run except
for occasional daily down times. Willie would like a program that tracks the downtime of each machine.
He has asked you to create a class that can be used in a larger program. The class is to track the amount
of time that a machine is down. The downtime is always in hour increments, so a number between zero
and excluded will be sufficient to record the hours that the machine is down. In general, Willie
wants to see the data for a given quarter, though sometimes he may want to see the data for a longer
period. This means that the number of days that need to be stored will be different depending on the
period Willie wants to see.
There is also a cost associated with the down time. Willie would like to be able to get statistics about
that as well. Each machine has a different cost, so that will also need to be reflected in the class.
The class will need methods to get and set the hours that the machine is down for a given day. It should
also have methods to get the total down time for the machine, the cost of downtime for a specific day,
the day of the smallest and largest downtime and the average downtime per day.
The WidgetMaker class
The class is to be called WidgetMaker. Here is the UML for the class.
WidgetMaker
id: string
downtimeCost: double
downtime: int
WidgetMakerid:string, cost:double, period:int
getTotalDays:int
setDowntimeForDayday:int, hours:int:void
getDowntimeForDayday:int:int
getDowtimeCostForDayday:int:double
calculateAverageDowntimeCost:double
calculateAverageDowntime:double
calculateTotalDowntime:int
calculateTotalDowntimeCost:double
findMinDayIndex:int
findMaxDayIndex:int
Anything that is public MUST be implemented so that the class can be used in the larger program.
Failure to implement these classes exactly as described will cause the larger program to fail. If you find
that private methods are useful, you may add them. A description of the methods follows.
WidgetMaker The constructor accepts three parameters, the machine's id a String the downtime
cost double and the number of days the machine has worked an int The instance variables are set for
the first two values as usual; the down time array should be initialized to an array the size of the
numDays parameter. Make certain your code will work whether numDays is short eg days or long
eg days Note, the class does not need a numDays instance variable; see the next method to
understand why not.
getTotalDays returns downtime.length. This value should be used when filling the downtime from the
main method.
setDowntimeForDay The day number beginning at zero and number of hours worked for that day are
accepted as parameters. The method will use the day as the index into the array of downtime and set
the value at that index to the hours passed in
getDowntimeForDay The method accepts an integer as its parameter representing the day. It is used
as an index into the downtime array. The value at that index is returned to the caller.
getDowntimeCostForDay As above, the method accepts an integer for the day number. The cost for
the specified day is returned. This is just the hours times the down time cost.
calculateAverageDowntimeCost This method gets the total cost see below and divides that number
by the number of days worked to determine the average cost per day. It then returns that value.
calculateAverageDowntime Similar to the above method, this method divides the total number of
hours downtime by the number of days worked and returns that value.
calculateTotalDowntime Sums up all of the downtime and returns the sum.
calculateTotalDowntimeCost Returns the total cost of the downtime for the entire period.
findMinDaylndex Returns the index of the day with the least number of downtime hours. If there are
multiple days that have the same minimum number of hours, any of these indexes can be returned.
Depending on your code, it is likely to be the first or last one. Note: this method and the next return
the index, not the downtime. The main program will display both this index as well as the downtime.
findMaxDayIndex Just like the findMinDayIndex, but returns the index of the day with the most hours
worked.
The main class
The main class must test the class thoroughly. The logic itself is pretty simple, but it will test all of the
methods in the WidgetMaker class. Here is what it should do:
For a starting grade of B :
Create a WidgetMaker object. You must pass the machine id downtime cost and days the machine has
worked to the constructor. These should be named constants, of course. For example, TIMEPERIOD
could represent the days worked.
The rest of the program should simply be calling methods, passing the WidgetMaker object to each
method. This object should be the ONLY parameter passed to the methods. You can name the methods
appropriately. Each of the f
Display a daily list report for
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
