Part A

The Order class is an abstraction of customer orders. You are asked to code only ONE static method for this class. Most of the class has been implemented by someone else. You can use some of those methods to code the static method.

The static method prompts the user to enter a customer name at one line and a delivery address at another line. It returns an Order object that contains the customer name and the relevant parts of the delivery address. The user will always use this format: a street name, followed by a city name, followed by a province code, and followed by a zip code. For example, 70 The Pond, Toronto,,,ON,, M2M1Q5. Please note that one or more commas are used to separate a street name, a city name, a province code and a zip code. At least one comma will precede a group of blank spaces. A city name will never include a white space or a comma. A province code always consists of two or three letters in upper case. A zip code always consists of six alphanumeric characters. (Note: You must use a regular expression to code the static method.)

The following features have already been implemented for the Order class:

  • a default constructor and a two-argument constructor,
  • setters: setAddressName, setCityName, setProvinceCode, setZipCode, set CustomerName,
  • getters: getAddressName, getCityName, getProvinceCode, getZipCode, getCustomerName,
  • the equals method,
  • the toString method.

Part B

The Carrier class is an abstraction of companies that provide delivery service for customer orders. When a Carrier object is created, it is provided with the name of a company (e.g. UPS, DHL Express, Purolator and CanPar). There is no limit on the total number of customer orders that a company can deliver. You can use the Order class from Part A.

You are not required to code a complete Java class. However, you must write down Java code for the following requirements:

  • Declare all instance variables in the Carrier class.
  • Code the constructor that takes one argument, namely the name of the company. (Note: You should not create any Java array here.)
  • Code the instance method: boolean addOrder ( Order z ). This method is used to place a new customer order with the company. You are not required to check for duplicates. It returns false if z is a null reference. Otherwise it returns true.
  • Code the instance method: Order [ ] removeOrders ( String provinceCode ). The method returns an array of customer orders whose delivery addresses have the same province code as “provinceCode” (e.g. “ON”). All these customer orders are removed from the company. It returns a null reference if no matching is found.

Here is a snapshot of a company that has received five customer orders.

Company name: DHL Express
5 customer orders:

Mary Ashton, 123 Green Lane, Thornhill, ON M8W2R4
Peter Kok, 111 Rose, Vancouver, BC E1F4X5
Lisa Kuhn, 467 Brook, Red_Deer, ALB R1W9U2
Paul Chan, 98 Sand, Halton, NFL V1Y4M8
John Doe, 70 The Pond, Toronto, ON M2M1Q5

If the method removeOrders is called with “ON”, it will return an array that has the following two customer orders:

Mary Ashton, 123 Green Lane, Thornhill, ON M8W2R4
John Doe, 70 The Pond, Toronto, ON M2M1Q5

Note: The company has only three customer orders for delivery

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.