Lab3

advertisement
COMP 111
Lab 3 – Winter 2010
Scenario
Monday
The day has been long. You finished Version 2 of the Station project and left Sam Snake a
voicemail last Friday. But you heard nothing back from him. Your company-issued smart
phone chirps with notice of a text message. It is from the CIO!
Good work on V2! I am at an OO conference – learning new programming
language. I will be in touch soon. -Sam
You respond.
Thanks.
Need direction on next version.
What language RU learning?
Later, as you pack up to go home, there’s a response.
Python!
LOL.
-Sam
Tuesday
Soon after you arrive at work, there’s another message from Sam.
Did you find what I left you in your top drawer?
-Sam
I think you will enjoy it!
A deep dread washes over you as you recall previous “gifts” from the CIO. You recoil from
your desk – pushing your wheeled chair so fast that it slams into the opposite wall of your
cubicle. After you recover, you slip on your winter gloves and slowly slide out the top drawer.
There is a single sheet of paper – with carefully typed notes. You take it out, wipe the sweat
from your face, and study what Sam has left you:
Gasoline
Biobutanol
Ethanol
Propane
Biodiesel
BTUs per gallon
115400
104800
75670
83500
127250
BTUs per Gallon of FUEL TYPES
Exx
Ethanol Blend
Bxx
Biobutanol Blend
PROPANE
BIODIESEL
=
=
=
=
=
GASOLINE_BPG
BIOBUTANOL_BPG
ETHANOL_BPG
PROPANE_BPG
BIODIESEL_BPG
p * ETHANOL_BPG + (1 – p) * GASOLINE_BPG
p * BIOBUTANOL_BPG + (1 – p) * GASOLINE_BPG
No blend – use PROPANE_BPG
No blend – use BIODIESEL_BPG
NOTES
 where p is the fraction represented by xx viewed as a percentage
(e.g. for E85, p is .85)
 to get the conversion factor to GGE for a fuel type divide GASOLINE_BPG by the BTUs per
gallon of the fuel type
-1-
Not long after, there is another text from Sam Snake.
We need to track the fuel type at each station. Use fuel types designators I
left you. Calc price per GGE based on fuel type. Can you figure it out? -Sam
You do some research and find that it common in the industry to use E80, E85, E100, etc. to
refer to different blends of ethanol and gasoline. For example, E85 is 85% ethanol and 15%
gasoline. The BTUs per gallon of E85 can be found by adding together:
 .85 times the BTUs per gallon on ethanol
 .15 times the BTUS per gallon of gasoline
So the formulas Snake left you make sense. You start by taking out the work you had done on
Station for Version 2. You add a String instance variable for the fuel type, and several final
constants for the fuel types. For:
 ethanol you will look for the ‘E’
 biobutanol you will look for the ‘B’
 propane and biodiesel you will look for “PROPANE” and “BIODIESEL”
You also add final constants for the BTUs per gallon of the pure forms of the fuels (using the
numbers in Sam’s notes). You add skeleton methods for the getter and setter for the fuel type
and wipe out the previous implementation of pricePerGGE. You also, adjust the constructors
to account for the new instance variable. You make some notes on what you will need to do
when implementing pricePerGGE:
1. Decode the fuel type
2. For ethanol and biobutanol blends, figure the BTUs per gallon for the blend (using
Sam’s formulae)
3. For propane and biodiesel, use the final constant values for BPG
4. Calculate a GGE conversion factor (using Sam’s formula)
5. Finally, multiply the price per gallon by the conversion factor from the previous step
With that done, you tap out a message to Sam.
I think I got it. I still need to figure out how to turn the string after E
or B (e.g. B100, E85) into a number I can use in the calculations.
After you send it, you feel a bit sheepish about texting your boss such a detail. As you are
getting ready to leave for the day, you get another text from Mr. Snake
Cant help you. Ask your instructor at Franklin. The Location class is great
– let’s remove the Station constructor with latitude and longitude.
You remove that constructor from the skeleton Station class you are developing. Then –
another text:
I am at a bar.
cleanest?
How about this one?
What kind of snake keeps its car the
You figure this isn’t worth responding to, so you snap off the light and leave.
-2-
Wednesday
You find a text message from Sam – time stamped 3 a.m.
A windshield viper!
Hah.
LOLA. -Sam
You take out the StationTest class from Version 2 and adjust the test methods (and add some
new test methods) corresponding to the changes you made yesterday to the Station class.
Your phone alerts you to another message from Sam.
We r going to have our customers rate our stations (1 to 4). Add the
capability to accumulate ratings and calculate the average rating. -Sam
You pause to think about this. To calculate the average rating at any point in time, you will need
to accumulate the total of the ratings and a count of how many ratings there are. You add some
additional integer instance fields for the ratings total and the ratings count. You add a method to
record a single rating and another method to calculate the average rating. You don’t include a
getter and setter for these as the values for these fields are determined by the sequence of method
calls to record a single rating, but you note that you will need to properly initialize the total and
count instance fields in constructors.
After adding skeleton test methods in StationTest for the new methods you added to
Station, you text the boss.
Sam.
I have figured out how to deal with the ratings.
Should I get started?
Sam replies in a few minutes.
Great. ur fast! Can you adjust toString to also include the fuel type and
the rating (something like a 4-star rating)? No fractions. -Sam
You are not quite sure what he means, so you include an integer average rating (rounding to the
nearest integer) in the toString method. You will figure out later what he means by “stars.”
You hear another text arrive – it is from Mr. Snake.
Thanks for your good work and quick responses.
test methods? -Sam
How about the test class and
This seems to be one of Snake’s favorite questions. As you reply, you are pleased that you have
anticipated it and developed a skeleton test class corresponding to the changes you made to
Station.
Sam.
I am ready to go with the test class.
Should I get started?
Sam takes less than a minute to reply.
It’s a go. I’ve learned a lot this week.
create objects? -Sam
BTW, how does the CIO of Snake Oil
You scratch your head. What’s with all the riddles? Before you think of a smart reply there is
another text.
I use a BOA CONSTRUCTOR!!!!!
-3-
Assignment
1. A BlueJ starter project will be provided to you. It contains one completed class –
StationDriver and two “skeleton” classes – Station and StationTest. You will
need to add code to the latter two – consistent with the requirements described in this write
up – so look through the skeleton classes to identify the methods you need to complete.
While the Location class is not visible in the BlueJ project window, it is available to be
accessed (see note 12 below).
2. To help you, there are some hints and guiding directives in the code in the form of comments
(e.g. // HINT: Call on a Location class method to perform the
calculation”, // replace this comment with your code, etc.). Please
remove such comments before submitting.
3. You must use the provided BlueJ starter project and develop your solution using the BlueJ
IDE.
4. Do NOT change the name, return type, or parameter order/type of any of the domain class or
test class methods. These are used by Web-CAT to grade your submission, and you will end
up losing points if they are changed.
5. Each constructor and method of a domain class (in this assignment, Station) should be
tested by a unit test method in the test class (in this assignment, StationTest). Besides
serving to verify that your code is accomplishing what you intended, examining and writing
the unit test methods will help you understand how the domain objects should behave (how
the domain class methods create, access, and mutate an object). That is, writing/reviewing
the test methods helps you code the domain classes.
6. Follow these steps to complete this assignment:
a. Review the first JUnit test method, completing the code if necessary. Understand
what behaviors of domain class constructors and methods are being checked in
the unit test method. Note that proper testing may include manual calculation of
expected values to check against the actual values resulting from a method.
b. Once you feel the unit test method is a valid and robust test of the domain
method’s expected behavior, review the corresponding domain class constructor
or method and complete the coding if necessary.
c. Run the JUnit test. If it does not pass, figure out how to correct domain class
constructors/methods called in the JUnit test method.
d. When the test passes, continue in like manner for the next and subsequent JUnit
test methods, iteratively reviewing tests and developing your domain class
methods. All domain class methods must be tested.
7. All classes must compile cleanly.
8. Check your programming style using the “Checkstyle” tool provided within BlueJ (Tools 
Checkstyle).
9. Document the overall project in the README file as directed in the Action Items for the
Lab. Note there are some questions that need to be completed before the final submission to
WebCAT.
-4-
10. Submit your completed lab to Web-CAT using BlueJ (Tools  Submit) and review the WebCAT results for errors. Repeat the above steps as needed to resolve any errors.
11. Note that the driver class StationDriver included in the project file demonstrates the use
of the Station class, calling on its constructors and methods and displaying results. While
it supports your understanding of the lab, it is not part of the actual solution. You can modify
it if that is helpful to you, but the driver class will not be examined by Web-CAT nor graded
by your instructor.
12. When you unzip the Lab3 starter project, note that a library jar file for the Location class is
in the +libs folder. This allows the project access to that class. Although you will not be
able to see the source code for the class, you will be able to use the documentation contained
in the doc folder underneath +libs to review the support class public interfaces. Open the
index.html file in a browser to view the API for the class.
-5-
Download