CS 1401 Assignment #4
Date Assigned: Thursday, September 22, 2005 or Friday, September 23, 2005.
Due Date: correspondingly, Thursday, September 29, 2005, or Friday, September 30, 2005, before the beginning of
your lab section.
Goals: to learn
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.
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: Many computer science students have complained
about the parking, so Bill Gates donated money to build a parking
garage for CS students at UTEP.
There are two competing plans: to place this garage near UTEP campus and
to place it across the border so that students will be able to take a
shuttle to school.
To help in constructing this garage, we need to
design an application that would,
given the width and depth of every floor (in feet) and the number of floors:
- compute the overall floor area of the garage (in square feet),
- compute the cost of building this garage
on the US side by
multiplying its cost-per-square-foot by the overall floor area,
- compute the cost of constructing this garage
on the Mexican side by first converting the area into square meters and
then multiplying its cost-per-square-meter by the floor area in square
meters;
- in both cases, we get a 10% discount
- provided that we help by designing such an
application.
Keep the price per square foot (at present, $30), the Juarez price per square meter
(at present, 200 pesos), and the
discount (at present, 10%) as named
constants,
to make it easier to change them later on.
It is also a good
idea to define FEET_TO_METERS = 0.3048 and PESOS_TO_DOLLARS = 0.1 (for simplicity)
as named constants.
Desired structure: define three classes:
- class Architect
whose objects are architects;
- class Design whose objects are designs, and
- an application class.
Class Architect should contain:
- a field for the architect's first name,
- a field for the architect's last name,
- a constructor method for defining a new architect object based on two
strings containing, correspondingly, the architect's first name and the
architect's last name;
- a method firstName that returns the architect's first name;
- a method lastName that returns the achitect's last name;
- a method fullName that returns the architect's full name.
Class Design should contain:
- a field for the width of the floor (in feet);
- a field for the depth of the floor (in feet);
- a field for the number of floors;
- a constructor method for defining a new design based on the two
real numbers that describe the width and depth of each floor and an
integer that describes the number of floors;
- a method areaOfOneFloor that
returns the area of one floor in square feet;
- a method overallFloorArea that
returns the overall floor area in square feet;
- a method overallFloorAreaInMeters that
returns the overall floor area in square meters;
- a method usGaragePrice that returns the price of a US-based garage (before the discount);
- a method juarezGaragePrice that returns
the price of a Juarez-based garage in pesos (before the discount),
- a method juarezGaragePriceInDollars that returns
the price of a Juarez-based garage converted to dollars
(before the discount),
- a method usGaragePriceDiscounted that returns
the price of a US-based garage (after the discount), and
- a method juarezGaragePriceDiscounted that returns
the price of a Juarez-based garage converted in dollars
(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 Design.
The application class should do the following:
- ask an architect:
- for his or her first name,
- for his or her last name,
- for the width and depth of each floor, and
- for the number of floors;
- based on the answers, construct the corresponding objects of type
Architect and of type Design;
- use the methods defined for such objects to
print a receipt that displays:
- the name of the architect,
- the price of a US-based garage (before the discount),
- the price of a Juarez-based garage in dollars (before the discount),
- the price of a US-based garage (after the discount), and
- the price of a Juarez-based garage in dollars
(after the discount).
Deliverables: as announced in the labs.