RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

lect09c-soln
A Design Exercise
Amazin' Orders

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:

For each of these pieces of information, Draw a picture of an OrderInfo object, based on your brainstorming.


Solution: Thinking just about fields only:
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() );
      }
  }
(Does comparing the zip code make the city/state irrelevent? Or conversely, does the same street1, street2, city, and state mean that the zip-code is redundant? Do we want a method probablyEqual? Are there multiple ways to compare a street-address, or a city? (“Main St.” vs “Main Street”? Ignore case? “NYC” vs. “New York” vs. New York City? “B'burg”? )
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.

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2008, Ian Barland, Radford University
Last modified 2008.Mar.21 (Fri)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme