Draw a uml diagram of the shoe class using the code that


Part A - Code Comprehension

A Sample program is provided. Make sure you understand this code as it will help you with your own programming for this assignment. Using the uncommented sample code for classes provided, answer the following questions:

1. Draw a UML diagram of the Shoe class using the code that has been provided. Complete this using the examples that have been provide in the lecture slides.

2. Draw a UML diagram of the Store class using the code that has been provided. Complete this using the examples that have been provide in the lecture slides.

3. Copy the code from Store.java into your report and appropriately comment the code. At a minimum, explain the purpose of each method. For the more complex methods reading input from a file, sorting the data and exporting data to the file, insert comments to explain the code.

4. Briefly explain the code in sort Inventory. What is the inventory being sorted by? What is the sort algorithm that is being used. Explain in words how it works. Why do you need to use two for loops?

5. Briefly explain what other sorting algorithms could have been used.

6. What method of searching for shoes has been used in the program? What other algorithm could have been used.

7. Examine the lines to open the output file and write the outputString in the ShoeStore class:

File file = new File("export.txt");
System.out.println(file.getAbsolutePath());
output = new BufferedWriter(new FileWriter(file));
output.write(outputString);

Where is the output file located? Find BufferedWriter in the Java API documentation and describe the use of this object.

8. Examine the code in the exportToFile method in the ShoeShop.java file. What is the purpose of the ‘\r\n' in the toString() method that is used to produce the output string?

9. Explain the use of the return value (result) of the compareTo method in the Shoe class.

10. Briefly explain why the line to open the input file:

Scanner inputFile = new Scanner(new File("C:\\orders.txt"));

has two \\ in the filename specification. Where is the file located? What happens if only one \ is used? Is there another option that would not require these?

11. Examine the code in the saveToFile method. How could this be improved for readability of the output file? What is the purpose of the ‘\r\n'?

12. Briefly explain why a try and catch clause has been included in the code to read from the file. Remove this from the code and remove the input file and take note of the error. Re-add the line and investigate what happens if the input file is not present. Record your observations in your report.

Part B - Development of a Basic Class - Person

Your first coding task is to implement and test a class that represents an Apartment. An Apartment object has the following attributes: number of bedrooms, number of bathrooms, the size of the apartment, the number of living areas, an indication of whether the apartment is available for rent, the owner of the apartment and the amount of rent per week. To complete this task, you are required to:

1. Create a new package in eclipse named assignTwoStudentNNNNN where NNNNN is your student number. You will author a number of classes for this assignment and they will all be in this package.

2. Use the UML diagram provided to implement the class Person in a file called Person.java. Starter code has been provided with this assignment, copy this starter code into your Apartment.java file. Complete the constructors that will create a Person object.

a. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram.

Person
- String name;
- String address;
~ Person(name:String, address:String)   
+ getName():String
+ setName (_aName:String):boolean
+ getAddress():String
+ setAddress (_anAddress:String):boolean
+ toString():String

3. Update the class TestClass.java adding in code to:

a. Create an instance of the Person class
b. Set the name and address of the instance
c. Display the details of the Person that you have created using the toString() method in the Person class.

Part C - Development of a Basic Class - Apartment

1. Use the UML diagram provided to implement the class Apartment in a file called Apartment.java adding the class to your package assignTwoStudentNNNNN. Starter code has been provided with this assignment, copy this starter code into your Apartment.java file. Complete the constructors that will create an Apartment object.

a. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram.

b. Ensure that your Apartment class includes the following validation within the mutator (set) methods:

i. The owner of the Apartment cannot be null.

ii. The rent per week of the Apartment must be greater than zero. If an attempt is made to set the value of the rent to an invalid value the method should return false and not change the value of the attributes.

Apartment
- int numberOfBedrooms;
- int numberOfBathrooms;
- int numberOfLiving;
- int floorNumber;
- char apartmentLetter;
- Person owner;
- boolean available;
- double rent;

~ Apartment(numberofBedrooms:int,, numberOfBathrooms:int, numberOfLiving:int,, owner:Person, available:boolean, rent:double)
+ getOwner():Person
+ setOwner (_aPerson:Person):boolean
+ getNumberOfBedrooms():int
+ setNumberOfBedrooms(_numBedrooms:int)
+ getNumberOfBathrooms():int
+ setNumberOfBathrooms(_numBathrooms:int)
+ getNumberOfLiving():int
+ setNumberOffLivings(_numfLiving:int)
+ getAvailable():boolean
+ setAvailable(_available:boolean)
+ getRent():float
+ setRent(_rent:double):boolean
+ toString():String

4. Update the class TestClass.java adding in code to:

a. Create an instance of the Apartment class

b. Create an instance of the Person class

c. Set all of the instance variables of the instance of the Apartment class that you have created including the owner (using the Person created in b. above)

d. Display the details of the Apartment that you have created using the toString() method in the Apartment class.

Part D - Development of the Building class

Using the UML diagrams provided and the information below you are required to implement and test classes that represent a Building object. For this assignment a Building contains multiple Apartments up to a specified capacity. (This may be modeled on the classes in the sample code. Your Building will in a similar way contain multiple Apartments in an array.)

Building.java
Building
- name: String
- apartments: Apartment[]
- numberOfApartments: int
- capacity: int
~ Building (initName: String, capacity: int) <>
+ getName():String
+ getNumberOfApartments():int
+ setName(newName: String): boolean
+ addApartment(newApartment: Apartment): boolean
+ sortApartments()
+ numberEmpty(): int
+ exportToFile() //itech5000 students only
+ readFromFile() //itech5000 students only
+ toString():String

1. You have been provided with starting point in Building.java - add the provided class to your package assignTwoStudentNNNNN.. Write get and set methods as well as an addApartment method. addApartment should return false if an attempt is made to add an apartment after the Building has already reached its maximum capacity.

2. Create a method for sorting the addApartment in the Building

3. Update the class TestClass.java adding in code to:

a. Create an instance of the Building class

b. Add at least two Apartments created to the Building class using the addApartment () method

c. Add at least two other Apartments to the Building class

d. Display the details of the Building that you have created using the toString() method in the Building class- these should be accessed via the instance of the Building class that you have created

Part E - Using the Classes

Create a new class called Driver.java . This class is to be used to implement a basic menu system. You may find some of the code you have already written in the TestClass.java can be copied and used with some modification here. You may also find the menu code from assignment one helpful as an example of a menu, although in this case you should use a switch statement to process the menu options. Each menu item should be enacted by choosing the appropriate method on the Building object. The menu should include the following options:

1. Populate the Building

2. Display Apartments in the Building

3. Sort Apartment data

4. Reports

5. Import data

6. Export data

7. Exit

Attachment:- code Seg.zip

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Draw a uml diagram of the shoe class using the code that
Reference No:- TGS01128000

Now Priced at $120 (50% Discount)

Recommended (98%)

Rated (4.3/5)