![]() |
![]() |
|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
Due Feb.22 (Fri) (20pts): only hardcopy is needed.
01. class Glarkzle { 02. 03. int MAX_ORDER_SIZE = 25; 04. 05. int numFloops; 06. String homePlanet; 07. 08. Glarkzle( int _numFloops, String _homePlanet ) { 09. |
the environment: +--------+ ____ | | +--------+(Note that the contents of the labeled-box should be empty, since you haven't initialized the variable yet.)
the environment: The object bench (the “heap”) +--------+ ____ | *---|-------\ +--------+ \ +-----------------------------+ \ | | \------> | | | | | | | | +-----------------------------+
Note that these questions all involve walking up to some particular String object and asking it a question. In the first case the input happens to be an int, and in the second case it happens to be another String, but otherwise the general task is the same.
Part (b) (20 pts) due Feb.25 (Mon):
turn in two printouts:
the documentation HotChocoBooth.html,
and the actual code for the test cases (HotChocoBoothTest.java
—
not the other way around!
(You'll presumably create those tests through BlueJ's
“Create Test Method…” feature;
when done recording, open the khaki test class and print.)
You should have a separate test case
for each of the methods mentioned below.
Your test cases for this course will no longer be written in comments.
On WebCT, attach HotChocoBooth.java (which has the documentation),
as well as HotChocoBoothTest.java (which has the tests).
Part (c) (20 pts) due Feb.27 (Wed). Turn in just HotChocoBooth.java (hardcopy and on WebCT).
The BCB (“Better Cocoa Bureau”) has hired you to help keep track of how Hot Chocolate booths do business. Every Hot Chocolate Booth has a capacity (how much hot chocolate they can possibly make per day), and a cash reserve. During a business day, a booth will:
![]() |
A fine, high-capacity samovar for piping hot chocolate |
HotChocoBooth cc = new HotChocoBooth( 340, 3 ); |
cc.doBusiness( 30 ); |
cc.doBusiness( 62 ); |
HotChocoBooth kk = new HotChocoBooth( 500, 2 ); |
kk.doBusiness( 30 ); |
kk.expandCapacity( 3 ); |
kk.doBusiness( 62 ); |
Write a class for HotChocoBooth. (What fields do you have? What named constants are involved?) Write getters and setters for your fields. Write a constructor. (What information is given to the constructor?)
Make sure you can compile your file, make instances, and call the getters/setters before proceeding.
Write a method double buySupplies(),
which decides how much to buy, updates the cash reserves accordingly,
and returns the number of liters of hot chocolate ready to sell.
When implementing this method (for Wednesday),
you'll either need an if-else statement,
or more perhaps some clever use of Math.max or Math.min2.
For (b), make sure you write the signature and record test cases before proceeding. When working on (c), make sure you pass the test cases for this method before proceeding.
Write a method void doBusiness(double temp), where temp is the temperature of a given day. Note that the first thing this method will do is buySupplies.
For (b), make sure you write the signature and record test cases
before proceeding.
When working on (c), make sure you pass the test cases for this
method before proceeding.
…Okay, I'll stop repeating this advice every time,
but still follow it at each step!
Write a void method void expandCapacity(int numLiters), which upgrades the size of the booth's pot (at the price of $100 per liter).
Write a method boolean moreCashThan(HotChocoBooth), which returns whether or not this booth is has more cash reserves than some other booth.
Challenge question: You start with $1000. what is the most money which can be made if the temperatures on five successive days turn out to be 40°, 60°, 20°, 60°, 30°? (Remember that you can expandCapacity any time you like.) Give a dollar amount, along with a series of method-calls which achieves that amount; 10pts extra credit to the highest score3
It's fine to work in a fractional amounts of a penny.
You can buy and sell a fractional number number of liters of hot chocolate.
When making a new booth, the starting-money is enough to cover the desired capacity.
You can assume that the temperature passed to doBusiness is never so warm that you have to pay people to drink your hot chocolate. 4
1So the primitive types you need to know are boolean, double, char, int (integers up to ±2 billion (approx)), long(integers up to ±10 quintillion (approx)). The primitive types which you don't need to know are float (single-precision floating-point), short (integers up to ±32767), and byte (integers up to ±128). ↩
2Or Java's conditional operator, ? :, which you can read about in the book. ↩
3 in case of a n-way tie, each winner will get Math.ceil(10/n) points). ↩
4 (With a bit of algebra you can compute at what temperature hot chocolate is free; we're saying that it will never get warmer than that temperature. What temperature is needed to break even, on the cost of supplies?) ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2008, Ian Barland, Radford University Last modified 2008.Mar.15 (Sat) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |