![]() |
![]() |
|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
At Amazin'.com, you can order books and other goods. When you check out, an order is created. Think of how the web page has you type in these various pieces of info:
public class OrderInfo {
private Name recipient;
private double price;
private Address shipTo;
private CreditCard card;
private Address billTo;
private PhoneNum phone;
private Date orderDate;
private Date shipDate;
private Date expectedArrivalDate;
}
|
public class Name {
private String title; // Probably 'Mr.', 'Dr.', 'Ms.', etc.
private String fname;
private String lname;
public boolean equals( Name other ) {
return (this.getFname()).equals( other.getFname() )
&& (this.getLname()).equals( other.getLname() );
}
}
|
public class Address {
private String street1; // street address, P.O. box, etc.
private String street2; // apartment number, suite number, etc.
private String city;
private String state; // A two-character String
private String zip; // 9-digit, or 5-digit? Either?
public boolean equals() {
return (this.getStreetAddr()).equals( other.StreetAddr() )
&& (this.aptNum()).equals( other.aptNum() )
&& (this.city()).equals( other.city() )
&& (this.state()).equals( other.state() )
&& (this.zip()).equals( other.zip() )
// How to handle for correct zip-comparison (5 vs 9 digit)?
&& (this.aptNum()).equals( other.aptNum() );
}
}
|
public class PhoneNumber {
private String countryCode;
private String areaCode;
private String exchange;
private String extension;
/** PhoneNumber constructor.
* @param numWithHyphens The phone number, 10 digits with hyphens,
* e.g. "540-841-0000".
* Note that the country-code for the U.S. is 011; we will currently
* presume all numbers to the constructor are US numbers, but if we ever
* get an international customer we can come back and modify the implementation
* of this method.
*/
public PhoneNumber( String numWithHyphens ) {
}
public String toStringInternational() {
// ??
}
public String toStringDomestic() {
// ??
}
}
|
class CreditCard {
String number;
Date expiration;
String securityField;
}
|
We have already seen a class Date. What would class Address look like? (Define its fields, and sketch the constructor and write one getter.)
task: Write canCombine. Two orders can be combined if they have the same receipient (up to title), and the same destination address, and the order-placed date is before the ship-date of another.
How should we tell when two OrderInfos are the exact same order?
Here is part of one possible solution.
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.21 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarland |
![]() |