In this project you will be using classes to model a real world commerce entity. The top class in this hierarchy is the
Posted: Mon Jun 06, 2022 2:08 pm
In this project you will be using classes to model a real world
commerce entity. The top class in this hierarchy is the Building
class which will be an abstract superclass.
See UML Diagram on following pages:
Building
-type: String
-length: double
-width: double
-numFloors: int
Building( type: String, length: double, width: double,
numFloors: int):
+getType( ): String
+getLength( ): double
+getWidth( ): double
+getNumFloors(): int
+setLength(length: double): void
+setWidth(width: double): void
+setNumFloors(numFloors: int): void
+findArea(): double
+getBuildingDetails(): void
The Building class is
an abstract superclass and it holds features
that are common to all of its subclasses. All building have a
length, a width and the number of floors. Please only code for the
accessor and mutator methods that appear in the UML diagrams. There
is a utility method called findArea() which will determine the area
of each building based on the its length, width, and number of
floors. This method will return a double value rounded to one
decimal place.
The getBuildingDetails( ) method is
an abstract method which will be implemented by
each sub class of Building. Each building has its own unique
descriptions so we’ll over-ride this method in each sub
class.
Warehouse
-percentStorage: double
-numRooms: int
Warehouse( length: double, width: double, numFloors: int,
pStorage: double, rooms: int)
Warehouse(type: String, length: double, width: double, numFloors:
int, pStorage: double, rooms: int)
+getPercentStorage(): double
+getRooms(): int
+setPercentStorage(pStorage: double): void
+setNumRooms(rooms: int): void
+getBuildingDetails(): void
The Warehouse class is a sub class
of Building and represents more concrete type of
structure. These buildings are separated into storage and offices,
so we note the number of rooms there along with the amount of
building that is used for storage. It has a 5-arg and a 6-arg
constructor. The 5-arg constructor is used when you instantiate a
new Warehouse. The 6-arg constructor comes into play when you
create a sub class object to the warehouse.
The getBuildingDetails() method implementation for this class will
simply describe this building.
IndustrialPlaza
-numUnits: int
-usage: String
IndustrialPlaza(length: double, width: double, numFloors: int,
pStorage: double, rooms: int, units: int, usage: String)
+getNumUnits(): int
+getUsage(): String
+setNumUnits(units: int): void
+setUsage(usage: String): void
+getBuildingDetails( ): void
The IndustrialPlaza class is also a
sub class of Warehouse and represents a number of
warehouses together in an industrial subdivision. This industrial
plaza contains additional information beyond that of a warehouse
such as number of units and how the plaza is utilized.
The getBuildingDetails method will return all the details of the
super class method along with additional information explaining the
number of units and the use of the plaza. You will also have to
show the total area of all the units combined. This will be
displayed in the getBuildingDetails() method as well.
RowHouse
-numUnits: int
-numBeds: int
-numBaths: int
RowHouse(length: double, width: double, floors: int, unit: int,
beds: int, baths: int)
RowHouse(type: String, length: double, width: double, floors: int,
unit: int, beds: int, baths: int)
+getNumUnits(): int
+getNumBeds(): int
+getNumBaths(): int
+setNumUnits(units: int): void
+setNumBeds(beds: int): void
+set NumBaths(baths: int): void
+getBuildingDetails(): void
The RowHouse class is a subclass to
Building. There are two constructors. The 6-arg constructor is used
to create a RowHouse object. The 7-arg constructor is called by the
RowHouse’s direct subclass.
Over-ride the getBuildingDetails( ) for this class so that it
will return all of the details about the RowHouse.
Apartment
-numLevels: int
-parkingSpaces: int
Apartment(length: double, width: double, floors: int, unit: int,
beds: int, baths: int, levels: int)
+getNumLevels(): int
+getParkingSpaces(): int
+setNumLevels(levels: int): void
+setNumParkingSpaces(spaces: int): void
+getBuildingDetails(): void
The Apartment class inherits directly
from the RowHouse class and contains a number of levels over and
above what a RowHouse contains. When you create the 7 arg
constructor you will need to call the seven argument parent
constructor sending in the type which would be “Apartment”. In
order to populate the number of parking spaces variable you simply
multiply the number of levels by the number of units, and then you
add one extra space for every four units. Note the output on the
example page.
Testing What You Have Done:
Once you have all of the classes constructed, you can write a
driver class called ConstructBuilding.java to test your methods.
Include the following steps as comments in your code:
1) You are going to instantiate four buildings.
Ex:Warehouse myWarehouse = new Warehouse(130.3, 67.2, 3, 76.5,
5);
2) You need to come up with your own arguments for each of these
buildings.
3) Choose appropriate lengths, widths, number of floors,
percentage of storage space, and number of rooms for the Warehouse
object.
4) Provide your own values for length, width, floors, percentage
of storage space, number of rooms, number of units, and the usage
for the IndustrialPlaza object.
5 Provide your own values for length, width, floors, number of
units, number of bedrooms, and number of bathrooms for the RowHouse
object.
6) Provide your own values for length, width, floors, number of
units, number of bedrooms, number of bathrooms, and number of
levels. The number of parking spaces for the Apartment object is
calculated using the number of levels and number of units.
7) You will now create an array of type building that will hold
4 elements. This will be accessed to demonstrate Polymorphic
Behavior.
8) You will assign each building object you created to an
element of your building array.
(At this point, some of you are probably saying “Hey wait a
minute! Arrays can only hold objects of one type! Well, all of the
sub types here are members of the Building super class, and that is
the data type of your array, so it is not a problem. This is
another good example of the IS-A relationship that we have
mentioned in class. Isn’t inheritance neat?!?)
9) Set up a loop that will call the getBuildingDetails( ) method
on each of the objects in the array by referencing the array
element i.e. buildingArray[0].getBuildingDetails().
10) Go back to the original declaration of these four objects.
Access each of the mutator methods for the Apartment object and
change all the values.
11) After altering the Apartment object, recall the
getBuildingDetails() method for the Apartment object to see the
changes.
13) You will then print out each accessor method, along with the
findArea method for each separate object.
There is an example output on the following page to give you an
idea of what we are looking for…
Sample Screen Output of the ConstructBuilding.java Program
My Building Empire
******************
Building Type: Warehouse.
Unit Area: 26268.5 square feet on 3 floor(s).
Number of Rooms: 5 rooms with storage accounting for 76.5
percent of the space.
Building Type: Industrial Plaza.
Area: 12620.3 square feet on 2 floor(s).
Number of Rooms in each unit: 4 rooms with storage accounting
for 82.5 percent of the space.
We have 16 units with a combined total area of 201924.8 square
feet.
This Industrial Plaza is designated for manufacturing only.
Building Type: RowHouse which has 7 living units on one
level.
Unit Area: 1795.5 square feet on 3 floor(s).
Total area of all units on one floor is 12568.5 square feet.
Number of bedrooms: 3. Number of bathrooms: 2.
Building Type: Apartment which has 14 living units on one
level.
Unit Area: 501.2 square feet on 1 floor(s).
Total area of all units on one floor is 7016.8 square feet.
Number of bedrooms: 2. Number of bathrooms: 1.
This Apartment building has 19 levels for a total number of 266
units.
This complex has 332 parking spaces available.
Mutating the Apartment object:
Building Type: Apartment which has 18 living units on one
level.
Unit Area: 1298.0 square feet on 2 floor(s).
Total area of all units on one floor is 23364.0 square feet.
Number of bedrooms: 1. Number of bathrooms: 1.
This Apartment building has 25 levels for a total number of 450
units.
This complex has 562 parking spaces available.
Analyzing each element of each building.
Type of building: Warehouse
Unit length: 130.3
Unit width: 67.2
Number of floors: 3
Area of this unit: 26268.5
Number of rooms in this unit: 5
Storage space in this unit: 76.5
Type of building: Industrial Plaza
Unit length: 125.7
Unit width: 50.2
Number of floors in each unit: 2
Area of each unit: 12620.3
Number of rooms in each unit: 4
Storage space in each unit: 82.5
Number of units in this industrial plaza: 16
This industrial plaza is designated for manufacturing usage.
Type of building: RowHouse
Unit length: 28.5
Unit width: 21.0
Number of floors in each unit: 3
Area of each unit: 1795.5
Number of bathrooms in each unit: 2
Number of bedrooms in each unit: 3
Number of units: 7
Type of building: Apartment
Unit length: 29.5
Unit width: 22.0
Number of floors in each unit: 2
Area of each unit: 1298.0
Number of bathrooms in each unit: 1
Number of bedrooms in each unit: 1
Number of units on each level: 18
Number of levels in this apartment building: 25
Number of parking spaces available: 562
Note: your output does not have to be exactly like this,
but it should be close.
commerce entity. The top class in this hierarchy is the Building
class which will be an abstract superclass.
See UML Diagram on following pages:
Building
-type: String
-length: double
-width: double
-numFloors: int
Building( type: String, length: double, width: double,
numFloors: int):
+getType( ): String
+getLength( ): double
+getWidth( ): double
+getNumFloors(): int
+setLength(length: double): void
+setWidth(width: double): void
+setNumFloors(numFloors: int): void
+findArea(): double
+getBuildingDetails(): void
The Building class is
an abstract superclass and it holds features
that are common to all of its subclasses. All building have a
length, a width and the number of floors. Please only code for the
accessor and mutator methods that appear in the UML diagrams. There
is a utility method called findArea() which will determine the area
of each building based on the its length, width, and number of
floors. This method will return a double value rounded to one
decimal place.
The getBuildingDetails( ) method is
an abstract method which will be implemented by
each sub class of Building. Each building has its own unique
descriptions so we’ll over-ride this method in each sub
class.
Warehouse
-percentStorage: double
-numRooms: int
Warehouse( length: double, width: double, numFloors: int,
pStorage: double, rooms: int)
Warehouse(type: String, length: double, width: double, numFloors:
int, pStorage: double, rooms: int)
+getPercentStorage(): double
+getRooms(): int
+setPercentStorage(pStorage: double): void
+setNumRooms(rooms: int): void
+getBuildingDetails(): void
The Warehouse class is a sub class
of Building and represents more concrete type of
structure. These buildings are separated into storage and offices,
so we note the number of rooms there along with the amount of
building that is used for storage. It has a 5-arg and a 6-arg
constructor. The 5-arg constructor is used when you instantiate a
new Warehouse. The 6-arg constructor comes into play when you
create a sub class object to the warehouse.
The getBuildingDetails() method implementation for this class will
simply describe this building.
IndustrialPlaza
-numUnits: int
-usage: String
IndustrialPlaza(length: double, width: double, numFloors: int,
pStorage: double, rooms: int, units: int, usage: String)
+getNumUnits(): int
+getUsage(): String
+setNumUnits(units: int): void
+setUsage(usage: String): void
+getBuildingDetails( ): void
The IndustrialPlaza class is also a
sub class of Warehouse and represents a number of
warehouses together in an industrial subdivision. This industrial
plaza contains additional information beyond that of a warehouse
such as number of units and how the plaza is utilized.
The getBuildingDetails method will return all the details of the
super class method along with additional information explaining the
number of units and the use of the plaza. You will also have to
show the total area of all the units combined. This will be
displayed in the getBuildingDetails() method as well.
RowHouse
-numUnits: int
-numBeds: int
-numBaths: int
RowHouse(length: double, width: double, floors: int, unit: int,
beds: int, baths: int)
RowHouse(type: String, length: double, width: double, floors: int,
unit: int, beds: int, baths: int)
+getNumUnits(): int
+getNumBeds(): int
+getNumBaths(): int
+setNumUnits(units: int): void
+setNumBeds(beds: int): void
+set NumBaths(baths: int): void
+getBuildingDetails(): void
The RowHouse class is a subclass to
Building. There are two constructors. The 6-arg constructor is used
to create a RowHouse object. The 7-arg constructor is called by the
RowHouse’s direct subclass.
Over-ride the getBuildingDetails( ) for this class so that it
will return all of the details about the RowHouse.
Apartment
-numLevels: int
-parkingSpaces: int
Apartment(length: double, width: double, floors: int, unit: int,
beds: int, baths: int, levels: int)
+getNumLevels(): int
+getParkingSpaces(): int
+setNumLevels(levels: int): void
+setNumParkingSpaces(spaces: int): void
+getBuildingDetails(): void
The Apartment class inherits directly
from the RowHouse class and contains a number of levels over and
above what a RowHouse contains. When you create the 7 arg
constructor you will need to call the seven argument parent
constructor sending in the type which would be “Apartment”. In
order to populate the number of parking spaces variable you simply
multiply the number of levels by the number of units, and then you
add one extra space for every four units. Note the output on the
example page.
Testing What You Have Done:
Once you have all of the classes constructed, you can write a
driver class called ConstructBuilding.java to test your methods.
Include the following steps as comments in your code:
1) You are going to instantiate four buildings.
Ex:Warehouse myWarehouse = new Warehouse(130.3, 67.2, 3, 76.5,
5);
2) You need to come up with your own arguments for each of these
buildings.
3) Choose appropriate lengths, widths, number of floors,
percentage of storage space, and number of rooms for the Warehouse
object.
4) Provide your own values for length, width, floors, percentage
of storage space, number of rooms, number of units, and the usage
for the IndustrialPlaza object.
5 Provide your own values for length, width, floors, number of
units, number of bedrooms, and number of bathrooms for the RowHouse
object.
6) Provide your own values for length, width, floors, number of
units, number of bedrooms, number of bathrooms, and number of
levels. The number of parking spaces for the Apartment object is
calculated using the number of levels and number of units.
7) You will now create an array of type building that will hold
4 elements. This will be accessed to demonstrate Polymorphic
Behavior.
8) You will assign each building object you created to an
element of your building array.
(At this point, some of you are probably saying “Hey wait a
minute! Arrays can only hold objects of one type! Well, all of the
sub types here are members of the Building super class, and that is
the data type of your array, so it is not a problem. This is
another good example of the IS-A relationship that we have
mentioned in class. Isn’t inheritance neat?!?)
9) Set up a loop that will call the getBuildingDetails( ) method
on each of the objects in the array by referencing the array
element i.e. buildingArray[0].getBuildingDetails().
10) Go back to the original declaration of these four objects.
Access each of the mutator methods for the Apartment object and
change all the values.
11) After altering the Apartment object, recall the
getBuildingDetails() method for the Apartment object to see the
changes.
13) You will then print out each accessor method, along with the
findArea method for each separate object.
There is an example output on the following page to give you an
idea of what we are looking for…
Sample Screen Output of the ConstructBuilding.java Program
My Building Empire
******************
Building Type: Warehouse.
Unit Area: 26268.5 square feet on 3 floor(s).
Number of Rooms: 5 rooms with storage accounting for 76.5
percent of the space.
Building Type: Industrial Plaza.
Area: 12620.3 square feet on 2 floor(s).
Number of Rooms in each unit: 4 rooms with storage accounting
for 82.5 percent of the space.
We have 16 units with a combined total area of 201924.8 square
feet.
This Industrial Plaza is designated for manufacturing only.
Building Type: RowHouse which has 7 living units on one
level.
Unit Area: 1795.5 square feet on 3 floor(s).
Total area of all units on one floor is 12568.5 square feet.
Number of bedrooms: 3. Number of bathrooms: 2.
Building Type: Apartment which has 14 living units on one
level.
Unit Area: 501.2 square feet on 1 floor(s).
Total area of all units on one floor is 7016.8 square feet.
Number of bedrooms: 2. Number of bathrooms: 1.
This Apartment building has 19 levels for a total number of 266
units.
This complex has 332 parking spaces available.
Mutating the Apartment object:
Building Type: Apartment which has 18 living units on one
level.
Unit Area: 1298.0 square feet on 2 floor(s).
Total area of all units on one floor is 23364.0 square feet.
Number of bedrooms: 1. Number of bathrooms: 1.
This Apartment building has 25 levels for a total number of 450
units.
This complex has 562 parking spaces available.
Analyzing each element of each building.
Type of building: Warehouse
Unit length: 130.3
Unit width: 67.2
Number of floors: 3
Area of this unit: 26268.5
Number of rooms in this unit: 5
Storage space in this unit: 76.5
Type of building: Industrial Plaza
Unit length: 125.7
Unit width: 50.2
Number of floors in each unit: 2
Area of each unit: 12620.3
Number of rooms in each unit: 4
Storage space in each unit: 82.5
Number of units in this industrial plaza: 16
This industrial plaza is designated for manufacturing usage.
Type of building: RowHouse
Unit length: 28.5
Unit width: 21.0
Number of floors in each unit: 3
Area of each unit: 1795.5
Number of bathrooms in each unit: 2
Number of bedrooms in each unit: 3
Number of units: 7
Type of building: Apartment
Unit length: 29.5
Unit width: 22.0
Number of floors in each unit: 2
Area of each unit: 1298.0
Number of bathrooms in each unit: 1
Number of bedrooms in each unit: 1
Number of units on each level: 18
Number of levels in this apartment building: 25
Number of parking spaces available: 562
Note: your output does not have to be exactly like this,
but it should be close.