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 a servlet that displays a form when the doget method

Create a Servlet that displays a form when the doGet method is invoked. The form will contain a post action that directs the form post back to the same servlet, which in the doPost method will append the form data to a random access file. After th..

  Cse-241 advance programming conceptspoint of sale

cse-241 advance programming conceptspoint of sale terminalin this assignment you will be tested on the concepts related

  1 create a recursive factorial program that prompts the

1. create a recursive factorial program that prompts the user for an integer n and writes out a series of equations

  Create a temperature sensor simulator

create a temperature sensor simulator. First, display a menu that will ask the user what season to simulate (1) winter (2) spring (3) summer (4) fall or (5) to exit. Once the use selects the season your program should ask the user how many simulation..

  Design a program to help a videorental store

Design classes (class video, class customer, etc) based on your analysis above, using LINKED LISTS for the database elements read into the main memory.

  Method to calculate all primes in the range [2..n]

One commonly used method to calculate all primes in the range [2..n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and m..

  String as its parameter and returns the length

Write a method named longestWord that accepts a String as its parameter and returns the length of the longest word in the string.A word is a sequence of one or more non-space characters (any character other than the space character).

  Part - a1nbsp to compile and run a java source file

part - a1.nbsp to compile and run a java source file hello.java that contains a main method which of the following are

  What are bufferedinput/outputstreams

What are BufferedInput/OutputStreams and why are they used? Write some Java code to illustrate how to create a BufferedInputStream.

  What are the benefits of documenting

What are the benefits of documenting our programs in Java?

  Create an abstract employee class

We are going to create an abstract Employee class and an abstract calculatePay method. The abstract Employee class will prevent a programmer from creating an object based on Employee

  Write a program that lets the user click on the panel

Write a program that lets the user click on the panel to dynamically create points. Initially, the panel is empty. When a panel has two or more points, highlight the pair of closest points. Whenever a new point is created, a new pair of closest po..

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