Briefly explain the code in sort inventory

Assignment Help JAVA Programming
Reference no: EM13847809

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) <<create>>
+ 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

Reference no: EM13847809

Questions Cloud

Annual dividend-required rate of return : Last week, Railway Cabooses paid its annual dividend of $1.20 per share. The company has been reducing the dividends by 10% each year. How much are you willing to pay to purchase stock in this company if your required rate of return is 14%?
Write a program in Java to check if a number is even : Write a program in Java to check if a number is even or odd in Java?
What is maximum price per share schultz should pay for arras : Schultz Industries is considering the purchase of Arras Manufacturing. Arras is currently a supplier for Schultz, and the acquisition would allow Schultz to better control its material supply. The current cash flow from assets for Arras is $7.4 milli..
The new class has the attributes of: name - type string age : Here is my current assignment I got the cat file to work I'm just having trouble with the driver file. You must create two Java files called LastNameFirstNameUnit6Prog.java, and Cat.java. Ensure you include ALL files required to make your program com..
Briefly explain the code in sort inventory : Draw a UML diagram of the Shoe class using the code that has been provided - 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..
First withdrawal in order to meet his retirement goal : Harry plans to start saving to provide for his retirement. Beginning one month from now, he will begin depositing a fixed amount each month into a retirement savings account that will earn 8.4% APR, compounded monthly. How much must Harry deposit int..
Fixed-rate : You are applying for a 30-year, fixed-rate (APR 6.50%), monthly-payment-required mortgage loan for a house that sells for $80,000 today. The mortgage bank will ask you for 20% initial down payment (in cash, paid immediately) of the house value
What reasons might exist for initiating an evaluation : What reasons might exist for initiating an evaluation? When might an evaluation be inappropriate? What steps or activities are involved in planning how to conduct an evaluation
How much will it cost the company to pay off their debt : As a financial manager, you need to raise capital for your company. Your bank will not give you the terms needed to initiate a project. You need to raise $10,000,000.00 and don't want to pay more than 6% annual interest (paid bi-annually) so you deci..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create the class airplane

Your missions is to create the class Airplane. Each Airplane object should store the following information (fields):

  Aimthe problem and implementing the design using principles

aimthe problem and implementing the design using principles of correct syntax program structure and

  Write a method named validate to help a local banker

write a method named validate to help a local banker. Your method will need to utilize two input parameters and the method's return value (for its output).

  Problem 1write a java class called problem1 implement the

problem 1write a java class called problem1. implement the following method in your classpublic static int

  Writing a program that computes the average salary

The first programming project involves writing a program that computes the average salary for a collection of employees of different types. This program consists of four classes

  Given a hash function hkey prepare a java simulation

given a hash function hkey prepare a java simulation program to determine each of the subsequent quantities after

  Which parts of the assignment were you not able to complete

Which parts of the assignment were you not able to complete fully? For each, explain why you were unable to complete this part and what steps you took to attempt to complete it. Give me as much detail as possible such that I may award partial cred..

  Write java application that asks user to enter two integers

Write a Java application that asks a user to enter two integers (A and B) and then display the results of A/B. Catch any division by zero errors and prompt the user to reenter the value of B. Be sure your code compiles and runs as expected. Name y..

  Using a linked implementation of graph write a method that

using a linked implementation of graph write a method that takes two nodes as input and returns true if joining an edge

  Data streams and how are they used to facilitate storage

What are Java data streams and how are they used to facilitate storage and retrieval of persistent objects?

  Explain the types of malware and the potential impact they

write a 200- to 300-word short-answer response to the following bull describe the types of malware and the potential

  Write a java program to store four records

You will handle student records in a file named "student_record". Each record in the file consists of student number of integer type and student name of 32 characters, so the size of each record is 36 bytes. You need to write a Java program to sto..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd