part a -code comprehensionusing the uncommented


Part A -Code Comprehension

Using the uncommented sample code has been provided in Moodleanswer 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. Explain in what the purpose of the call to hasNext() in readFromFile. 

4. Briefly explain the code in sortInventory.  What is the inventory being sorted by?  What is the sort algorithm that is being used.  Explainin words how it works. Why do 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. Explain the use of the return value (result) of the compareTo method in the Shoe class. 

8. 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?

9. 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'?

10.   Briefly explain why a throws has included in the code to read from the file.  Remove this from the code and take note of the error.  Re-add the line and investigate what happens if the "orders.txt" file is not present.

Part B - Development of a basic Class

Your first coding task is to implement and test a class that represents a City.  For this assignment aCity has a name, population (in millions eg 1.5F is 1.5 million), an elevation above sea level and an indication of whether the city is a capital.

To complete this task you are required to:

1. Use the UML diagram to implement the class City in a file called City.java.  You are to ensure that you adhere to the naming used below as this class will be used by other classes that you will develop.

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

a. The name of the City cannot be null nor an empty String (ie "").If an attempt is made to set the name to an invalid value the method should return false.

b. The population of the City must be greater than or equal to 1.  If an attempt is made to set the value of the population to an invalid value the method should return false.

3. Select two cities contained in the sample data within the Appendix - ensure that these two cities are in the one country.  Write a class called TestClasses and within the main method write code that will :

a. Instantiate an instance of the Class city one of the cities you selected using the City() constructor

b. Sets all of the instance variables to the appropriate values using the mutator methods (set)

c. Increase the population of the city by 10%.

d. Instantiates an instance of the Class city for a different city contained in the table below using the City(initName: String, initPopulation: float, initElevation: int, initIsCapital: boolean)  constructor

e. Decrease the population of the city by 5%

f. Display both of the cities that you have created using the toString() method

g. Display both of the cities that you have created using accessor (get) methods

Part C - Development of the Country and World classes

Using the UML diagrams provided and the information below you are required to implement and test classes that represent Country and World objects.  For this assignment a Country contains multiple cities up to a specified capacity.  The World contains multiple countries up to a specified capacity.

1. You have been provided with starting point in Country.java .  You are to ensure that you adhere to the naming used below as this class will be used by the World class that you will also develop.

2. Ensure that your class includes the following validation within the mutator methods:

a. The name of the Country cannot be null nor an empty String (ie "").  If an attempt is made to set the name to an invalid value the method should return false.

b. The population of the city must be greater than or equal to 1.

c. The number of cities added to the Country class cannot be greater than the capacity.

d. As a City is added to the Country the instance variable numCities should be increased by 1.

e. As a City is deleted (removed) from the Country the instance variable numCities should be decreased by 1.

3. Update the class TestClasses  adding in code to:

a. Create an instance of the Country class using one of the countries contained in the table in the Appendix

b. Add the two Cities created to the Country class using the addCity(City) method

c. Display both of the cities that you have created using the toString() method - these should be accessed via the instance of the Country class that you have created

d. Display both of the cities that you have created using accessor methods - each city should be accessed via the instance of the Country class you have created

Part D - Using the Classes

Create a new class called WorldDriver.  This class is to be used to implement a basic menu system.  The menu should include the following options:

1. Populate the World

2. Display Data

3. Sort World data

4. Runqueries

5. Exit

  • Populate the World - use the data provided and at least 3 Countries from the table below and an addition 2 cities of your own selection
  • Display Data - display the data of all countries and their cities contained within the World.
  • Sort data should utilise some form of sorting algorithm to sort the Countries of the World into alphabetical order.
  • Run queries should:
  • Display the Details of the cities with a population of 1 million or more
  • Display the Names of the cities with more than one word in their name
  • Delete all Australian cities with an elevation below 100m"
  • Allow the user to search for a city and/or country

Download:- Java.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: part a -code comprehensionusing the uncommented
Reference No:- TGS0497357

Now Priced at $40 (50% Discount)

Recommended (95%)

Rated (4.7/5)