We strongly encourage you and your partner to work together at all times, and alternate driving and navigating. You'll both benefit, even if it feels like it is taking longer.
The user of the program you will write will be run from DrJava's Interactions Pane. It will create air fill shops, chambers, breathers, and will cause these objects to interact. We'll more completely specify the program below, but first some rules:
/** * This declares i as an instance variable, and i represents * the number of widgits. */ private int i;Instead, here's what you should do (use the descriptive part):
/** * The number of widgits. */ private int i;
public class X {
JFrame theWindow= new JFrame();
/** Make a new X containing j. */
public X(JFrame j) {
this.theWindow= j;
}
}
/** class comment here */
public class X {
/** Instance variable comment here. Notice the preceding blank line */
private int i;
/** Method comment here. Notice the preceding blank line. */
public void m() {
// Put a blank line before comments in here. */
i= 4;
}
}
AirFillShop, Chamber, and
Breather, as well as AirFillShopTester,
ChamberTester, and BreatherTester, with
the following (complete, although informal) specification.
String, an income (a double), and a
price (in dollars) per litre of air (a double which
is never less than 1.00 --- monopolies have their advantages).
There are two ways to construct an AirFillShop:
double) and the
shop's name (a String).
String containing both pieces of
information, separated by a comma followed by a space; first
the price per litre and then the name. You'll need to use
String methods such as indexOf and
substring, and also
Double.parseDouble. Here's an example for a shop
called Last Gasp charging $13 per litre:
13.00, Last Gasp
sellAir method, which when
given an amount of money (a double) returns the
number of litres of air the money buys, rounded down to the
nearest int. Notice that this means that an air fill
shop routinely overcharges.
Air fill shops have a getName method, which returns
the shop's name, and a getMLPerDollar method, which
returns the number (a double) of millilitres that
this shop sells for a dollar (useful to make the shop's price
appear less expensive). They also have a toString
method, which returns a String of this form (no
newline):
Store name: x.yz millilitres per dollar.
(of course "Store name", and "x.yz" are replaced by the
appropriate data for this air fill shop). Here's an example using
Last Gasp and it $13 per litre price:
Last Gasp: 76.92307692307692 millilitres per dollar.
Note the colon (:) and the final period (.). Don't worry about
the number of decimal places to the right of the decimal.
You must use this exact format, including spaces.
The total income for all air fill shops is maintained in a
double static variable, which can be retrieved by
calling static method getTotalIncome
AirFillShopTester that has a single method
test with no parameters. This method should prompt
the user for air fill shop information (all on one line, as
specified by the second AirFillShop constructor).
Your test method should do this for two air fill
shops, and then your test method should call each
AirFillShop method to make sure they work as
specified.
String). Its method
getAddress returns this address (as a
String).
A chamber has an integer number of litres of air (at
standard temperature and pressure). This amount starts at 0
litres. Whenever some air is bought or breathed, you call the
chamber's adjustAirBy method with the number of
litres of air (an int, postive if some air has been
bought, negative if some has been breathed). The chamber's
getAvailableAir reports the number of litres of air
(an int) in the chamber.
There are two ways to construct a chamber:
String) and the nearest
AirFillShop.
String) only.
setNearestAirFillShop, which is given an
AirFillShop, and getNearestAirFillShop,
which returns this chamber's nearest AirFillShop.
Chambers also have a toString method, which
returns a String (all on one line, no newline
character) in this form:
Chamber: address, Air (in litres): xxx, Air fill shop: name.
...where you fill in "address", "xxx", and "name" with the
appropriate information for this chamber. For example:
Chamber: 19 Drury Lane, Air (in litres): 97, Air fill shop: Wheezers.
Note the commas, spacing, and the final period. You must
use this exact format, including spaces.
ChamberTester that has a single
method, test, with no parameters. This method should
prompt the user for two Chamber addresses and
information for two AirFillShops. Your
test method should create the four objects, and then
call each Chamber method to make sure they work.
Chamber, a name (a
String), a capacity (amount of air breathed per day
in litres --- an int), and money in dollars (a
double).
You can tell a breather to buy air for its chamber, using the
breather's buyAir method. The breather will buy as
much air as they can afford from their chamber's nearest air fill
shop, and put that air in their chamber, leaving their supply of
money at zero.
You can tell a breather to breathe for a day by
calling its breathe method. Assume that when
breathe is called there's enough air in the
chamber.
You can ask a breather if there's enough air for them to
breathe for a day, by calling canBreathe, which
returns true or false as appropriate.
You can give a breather more money by callings its
earnMoney method, which is given the amount of money
earned (a double).
You can move a breather to a different chamber by calling the
breather's move method, which is given the
Chamber it should move to. They leave behind the air
supply at their old chamber, and use the air supply at their new
chamber.
There are several ways to construct Breathers:
String), and capacity (an
int) (no chamber or money).
String), capacity (an
int), and money (a double) (no
chamber).
String, each
piece separated by a comma and a single space:
Adam, 5, 99.95
String), capacity (an
int), money (a double), and a chamber.
toString, which returns a
String in this form:
Adam, breathes at Paradise Chambers, has $1050.0, can breathe: true.Note the commas, spacing, punctuation, and the final period. You must this exact format, including spaces, and no newline.
This should appear on a single line, with no newline characters.
Again, don't worry about getting exactly two digits after the
period. Just use whatever value is in the double.
BreatherTester that has a
single method, test, with no parameters. This method
should prompt the user for information for two
breathers, two chambers, and information
for two air fill shops. Create the six objects. After
that, your test method should call each Breather
method to make sure they work.
.java files containing your
Chamber, Breather,
AirFillShop, ChamberTester,
BreatherTester, and AirFillShopTester
classes.