RAINFALL CLASS
Write a RainfallDriver class that has the following methods:
• main which creates an array of rainfall values for a year. Use the following to do so:
double[] rain = {.5,.3,.7,1.2,.1,.8,2.1,.5,3.3,2.8,.9,1.2};
• a method that calculates and prints the total rainfall for the year named total()
• a method that calculates and prints the average monthly rainfall named average()
• a method that determines and print the maximum rain in any one month named max()
• a method that determines and prints the minimum rain in any one month named min()
Each of the last four methods will need to define the array as a parameter that is passed in on the method call.
After you create the array in main, call each of the four methods so that they can print their information.
Sample output:
The total rainfall for the year is: 14.4
The average monthly rainfall is: 1.2
The maximum monthly rainfall is: 3.3
The minimum monthly rainfall is: 0.1
13. To do:
a. Take the Cookies and CookieDriver from itp120Mod4.Ex3.classes package from our previous module. Copy these into your package for module 5.
b. Now change the driver for the program. Store the cookies in a single array of type Cookies of unknown size (we have examples of how to handle arrays of unknown size in our mod5wolff01arraysPrimitive package of this module). NOTE: it MUST be an array – not an ArrayList. Let’s assume that we will not have over 20 types of Cookies so make your program to handle any number of cookie types up to 20 (you do not need to write an increaseSize() method).
c. Remove lines 34-44 since we now can do these processes after all of the data is read into the program. The main loop should just be reading in the cookies and placing them in the array
d. Create methods for
i. printing the array elements
ii. calculating the total number of boxes
iii. calculating the total cost of the cookies
e. After your loop in main(), call the three methods in d. above to print out the data and summaries.
Sample output
What type of cookie?
oatmeal
How many boxes?
12
How much does each box cost?
3.00
More sales? (yes/no)
yes
What type of cookie?
chocolate chip
How many boxes?
3
How much does each box cost?
3.50
More sales? (yes/no)
no
oatmeal cost $3.00 each and you ordered 12 for a total order of $36.00
chocolate chip cost $3.50 each and you ordered 3 for a total order of $10.50
Total boxes: 15
Total cost: $46.50
15. An alternative way to store a set of objects is in an ArrayList. This is part of the Java Collections and is found in the java.util package. ArrayLists have a rich set of methods as we saw briefly at the end of the chapter in your text. Watch the Collaborate movie on ArrayLists.
16. Remember to be able to utilize methods, we need to know a) the name b) the parameter(s) c) the return type. All of this is obtainable if we just know how to read APIs.
17. Look at the samples in the mod5wolff04ArrayLists package. Look at Ex1Grades. ArrayLists are collections if reference data types – not primitives! If I want to maintain an ArrayList of whole numbers, I need to use the Integer wrapper class (we discussed wrapper classes previously). But with boxing and unboxing, Java allows implicit casting from int to Integer, double to Double, etc. With this, we can define the ArrayList to be the wrapper class but add primitive values to it. Note that this ArrayList is defined as containing Integers but line 16 adds the primitive int input from the keyboard to it.
18. Look at Ex2ALDogs. The example we studied earlier used an array of Dog instances. This one takes that code and converts it over to an ArrayList. note how that was done.
19. Also look at the Ex3BookDriverAL that uses the Book blueprint. Keep studying these blueprints so you can write them in your sleep!
20. To do: Look at the Ex4Birds. Convert this program from an array collection to an ArrayList. Make certain to include the Bird blueprint in your jar file that you submit.
21. Look at the code for Ex5BaseballPlayers as you look at the APIs. Study the code and match each method call for the name, parameter(s) and return type.
22. To do: Now add code to Ex5BaseballPlayers to complete the comments in the code.
23. Check out the mod5wolff05SalesArrayList version of our Sales program using an ArrayList in place of the array.
24. Let’s look at another association that utilizes ArrayLists. Now we will rent some wrecked cars. Here is the UML diagram for our application (found in the mod5wolff06rentawreck package.
25. Some of our business rules for the rentals:
• All rentals are $15.00/day (I wish!)
• We give a 15% discount if they rent for over 6 days.
• We give Gold Card members an extra 10% a day.
• We need to hard code some data into the program. I have a table of data for you to use.
26. Note the associations in this application (the Rental contains a Customer and an Auto).
27. To do: Finish the Rentals class (see the comments with “TO DO”) and the WreckDriver class. You can make changes to the other two if you like, but do not need to. Sample output is below.
28. Now we need to document our hard work!! Look at my Customer class in the SalesArrayList application. I have added JavaDocs for the class, each field and each method. You do the same for the Sales class. In production, this is required as the standard documentation for every class.
29. Go to http://agile.csc.ncsu.edu/SEMaterials/tutorials/javadoc/ and http://www.mcs.csueastbay.edu/~billard/se/cs3340/ex7/javadoctutorial.html for information on how to write Javadocs. Look at JavaDocEclipse.doc (in this module assignment in Blackboard) for information on how to add them and generate them in Eclipse.
30. Then generate the JavaDocs. Send me JUST THE .HTML file for the blueprint for the Sales class (NOT THE INDEX.HTML FILE!!) along with your jar file for the module.
Your final jar file that you submit to me needs to have 10 programs total in a single package named dwolffmod5 (except with your name):
• Step 12: RainfallDriver
• Step 13: Cookies and CookieDriver
• Step 20: Ex4Birds and Bird
• Step 22: Ex5BaseballPlayers
• Step 27: Rentals, Customer, WreckDriver, Auto
Remember to also attach your Sales.html file.
Sample output from the wreck:
Customers:
1 Brett Farve (custID: 100)
2 Bruce Springsteen (custID: 101)
3 Mickey Mouse (custID: 102)
4 Peyton Manning (custID: 103)
5 Donald Duck (custID: 104)
Which customer? 2
This customer is a gold card member so we will treat him well!
The following cars are available to rent…
1. a 2009 Ford Mustang with a VIN# of ABC123 and a mileage of 1256.54
2. a 2010 Chevy Camero with a VIN# of QWI459 and a mileage of 33.98
3. a 1970 Pink Cadillac with a VIN# of 950AKH and a mileage of 212874.51
4. a 2007 Lotus Elise MkII with a VIN# of 1A2D3F and a mileage of 12859.9
Which auto? 3
How many days do you wish to have this beautiful vehicle? 10
Bruce Springsteen (custID: 101) rented a 1970 Pink Cadillac with a VIN# of 950AKH and a mileage of 212874.51 for 10 days.
The cost was $112.50
This person was both a gold card member and rented over six days and received a a 25% discount
More rentals (true/false)? true
Customers:
1 Brett Farve (custID: 100)
2 Bruce Springsteen (custID: 101)
3 Mickey Mouse (custID: 102)
4 Peyton Manning (custID: 103)
5 Donald Duck (custID: 104)
Which customer? 4
This customer is a gold card member so we will treat him well!
The following cars are available to rent…
1. a 2009 Ford Mustang with a VIN# of ABC123 and a mileage of 1256.54
2. a 2010 Chevy Camero with a VIN# of QWI459 and a mileage of 33.98
3. a 1970 Pink Cadillac with a VIN# of 950AKH and a mileage of 212874.51
4. a 2007 Lotus Elise MkII with a VIN# of 1A2D3F and a mileage of 12859.9
Which auto? 4
How many days do you wish to have this beautiful vehicle? 1
Peyton Manning (custID: 103) rented a 2007 Lotus Elise MkII with a VIN# of 1A2D3F and a mileage of 12859.9 for 1 days.
The cost was $13.50
This person was a gold card member and received a a 10% discount
More rentals (true/false)? true
Customers:
1 Brett Farve (custID: 100)
2 Bruce Springsteen (custID: 101)
3 Mickey Mouse (custID: 102)
4 Peyton Manning (custID: 103)
5 Donald Duck (custID: 104)
Which customer? 1
This customer is not a gold card member
The following cars are available to rent…
1. a 2009 Ford Mustang with a VIN# of ABC123 and a mileage of 1256.54
2. a 2010 Chevy Camero with a VIN# of QWI459 and a mileage of 33.98
3. a 1970 Pink Cadillac with a VIN# of 950AKH and a mileage of 212874.51
4. a 2007 Lotus Elise MkII with a VIN# of 1A2D3F and a mileage of 12859.9
Which auto? 1
How many days do you wish to have this beautiful vehicle? 15
Brett Farve (custID: 100) rented a 2009 Ford Mustang with a VIN# of ABC123 and a mileage of 1256.54 for 15 days.
The cost was $191.25
This person rented over six days and received a 15% discount
More rentals (true/false)? false
Rental summary:
Bruce Springsteen (custID: 101) rented a 1970 Pink Cadillac with a VIN# of 950AKH and a mileage of 212874.51 for 10 days.
The cost was $112.50
This person was both a gold card member and rented over six days and received a a 25% discount
Peyton Manning (custID: 103) rented a 2007 Lotus Elise MkII with a VIN# of 1A2D3F and a mileage of 12859.9 for 1 days.
The cost was $13.50
This person was a gold card member and received a a 10% discount
Brett Farve (custID: 100) rented a 2009 Ford Mustang with a VIN# of ABC123 and a mileage of 1256.54 for 15 days.
The cost was $191.25
This person rented over six days and received a 15% discount