## CS 1401 Assignment #4

Date Assigned: Wednesday, February 9, 2005

Due Date: Wednesday, February 16, 2005, before the beginning of your lab section.

Goals: to learn how to design objects and value-returning methods.

Points: This assignment is worth a total of 20 points. No late assignments will be accepted, but credit will be given for partially completed assignments turned in on time. Hand your assignments to your TA.

Assignment: In this assignment, we will deal with the same new building assignment as in Assignment 3, with the following difference:

• in Assignment 3, we asked you to design one application; the emphasis was on making things work;
• in this assignment, instead of placing everything into a single method main, we ask you to make your code more in line with the object-oriented paradigm; the emphasis now is on designing objects and methods.

Reminder: One of our alumni suddenly became rich, so he donated money to build a new Computer Science building. This new building will include new TA offices, new faculty offices, and new student lounges. Two companies will be constructing the building: an El Paso-based US company will be building the walls, and a Cd. Juarez-based Mexican company will place hardwood floors in every room. To help in constructing this building, we need to design an application that would, given the width and depth of every room (in feet):

• compute the floor area of the room (in square feet),
• compute the cost of building this room by a US contractor by multiplying its cost-per-square-foot by the room area,
• compute the cost of constructing this room by a Mexican contractor by first converting the area into square meters and then multiplying its cost-per-square-meter by the room area in square meters;
• both companies agrees to provide a 15% discount to the rooms cost - provided that we help them by designing such an application.
The US contractor price per square foot is \$30, the hardwood floor cost price is 2,000 pesos per square meter, the discount is 15%, I foot is 0.3048 meters, and 1 peso is 0.08941 dollars. These values should be stored as named constants, to make it easier to change them later on.

Desired structure: define three classes:

• class User whose objects are users, and
• class Office whose objects are offices.

Class User should contain:

• a field for the first name,
• a field for the last name,
• a constructor method for defining a new user object based on two strings containing, correspondingly, the user's first name and the user's last name;
• a method firstName that returns the user's first name;
• a method lastName that returns the user's last name;
• a method fullName that returns the user's full name.

Class Office should contain:

• a field for the office width (in feet);
• a field for the office depth (in feet);
• a constructor method for defining a new office based on the two real numbers that describe this office's width and depth;
• a method area that returns the area in square feet;
• a method areaInMeters that returns the area in square meters;
• a method usPrice that returns the US contractor price (before the discount);
• a method mexPriceInPesos that returns the Mexican contractor price in pesos (before the discount);
• a method mexPriceInDollars that returns the Mexican contractor price converted to dollars (before the discount);
• a method usPriceDiscount that returns the US contractor price after the discount;
• a method mexPriceDiscount that returns the Mexican contractor price after the discount;
• a method totalPriceDiscount that returns the overall cost of building this office (after the discount).
Named constants related to offices and costs (price per square foot, price per square meter, feet-to-meters, pesos-to-dollars, and the discount) should be defined in the class Office.

The application class should do the following:

• ask a user (TA of faculty):
• for his or her first name,
• for his or her last name, and
• for the width and depth of the room that this user wants;
• based on the answers, construct the corresponding objects of type User and of type Office;
• use the methods defined for such objects to print a receipt that displays:
• the name of the person who will be using this office,
• the cost of building the walls of this office (before the discount),
• the cost of building the walls of this office after the 15% discount,
• the cost of the hardwood floor in dollars (before the discount),
• the cost of the hardwood floor after the 15% discount,
• the total cost of constructing this office.

Deliverables: as announced in the labs and explained in the handouts given to you in the labs.