ITECH1000 Programming
Development of a Simple Program Involving Multiple Classes
Project Specification
Please read through the entire specification PRIOR to beginning work. The assignment should be completed in the stages mentioned below. The objectives of this assignment are for you to:
• Write your own classes from a specification
• Instantiate objects of these classes
• Perform required tasks by creating and manipulating objects in the code of one class through the public interfaces (methods) of the classes of the objects being manipulated.
The context for this assignment will be creating a software system to support a lending library, which has items of various types available for borrowing (books, videos, magazines, academic journals, software discs etc).
Resources Required
The following files/links are available on Moodle:
• An electronic copy of this assignment specification sheet
• A sample program with similar features to the assignment requirements involving multiple classes
• Starter code for some of the classes which you will need to create
Note: If you use any resources apart from the course material to complete your assignment you MUST provide an in-text citation within your documentation and/or code, as well as providing a list of references in APA formatting. This includes the use of any websites, online forums, books, or text books. If you are unsure of how to do this please ask for help.
Design Constraints
Your program should conform to the following constraints.
• Use a while-loop when the number of iterations is not known before loop execution.
• Use a for-loop when the number of iterations is known before loop execution.
• Indent your code correctly to aid readability and use a consistent curly bracket placement scheme.
• Use white space to make your code as readable as possible.
• Validation of input should be limited to ensuring that the user has entered values that are within correct bounds. You do not have to check that they have entered the correct data type.
• Comment your code appropriately.
Part A – Code Comprehension
A Sample program is provided that creates a list of shapes stored in an array. This program uses classes: Shapes, Square, Rectangle and ShapesList. The main method is in the class: TestingShapesListClass. Conduct a careful examination of this code. 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: Shapes, Square, Rectangle and ShapesList provided, answer the following questions:
1. Draw a UML diagram of each of the Shapes, Rectangle and Square classes using the code that has been provided. Complete this using the examples that have been provided in the lecture slides.
2. Draw a UML diagram of the ShapesList class using the code that has been provided. Complete this using the examples that have been provided in the lecture slides.
3. Copy the code from ShapesList.java into your report document, and add appropriate comments into the file to explain all the methods. 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. Explain the role of the switch statement in readFromFile() in ShapesList.java.
5. Briefly explain the code in bubbleSort() in the ShapesList class. What attribute are the shapes being sorted by? Name the sort algorithm that is being used. Explain in words how it works, using an example. Why do we need to use two for loops?
6. Briefly name and describe one other sorting algorithm that could have been used.
7. The Square and Rectangle class implement both a calcArea() and getArea() method. Are both of these necessary? Explain why or why not.
8. Examine the lines to open the output file and write the outputString in the ShapesList 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.
9. Examine the code in the exportToFile method. What is the purpose of the ‘\r\n’ in the toString() method that is used to produce the output string?
10. 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
Your first coding task is to implement and test a class that represents a LibraryItem. A LibraryItem object has the following attributes: a title, an ID code, a year of publication, an indicator of whether it is on loan or not, and a replacement cost
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 LibraryItem in a file called LibraryItem.java. Starter code has been provided with this assignment, copy this starter code into your LibraryItem.java file. Complete the constructors that will create a LibraryItem object.
3. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram.
4. Ensure that your LibraryItem class includes the following validation within the mutator (set) methods:
a. The title of the LibraryItem cannot be null nor an empty String (ie “”). If an attempt is made to set the title to an invalid value the method should return false.
b. The replacementCost of the LibraryItem must be greater than zero. If an attempt is made to set the value of the year of publication to an invalid value the method should return false and not change the value of the attribute.
Part C – Development of extended Classes using inheritance
Your second coding task is to implement and test a class that represents a specific type of borrowable item, a Book. A Book is a LibraryItem with the following additional attributes: author name,number of pages,
whether it is a hardback, whether it is fiction or non-fiction, and a publisher’s name.. A Book isA LibraryItem. The Book class will extend the LibraryItem class, so the title, ID_Code, yearOfPublication, onLoan and replacementCost attributes and their related methods will be inherited from the LibraryItem class. After you have created the Book class, you are asked to create a similar class for another type of library item that you choose (e.g. video, music CD, magazine, software disc etc.). This class must add at least three additional attributes to those inherited from LibraryItem.
To complete this task you are required to:
1. Use the UML diagram provided to implement the class Book in a file called Book.java. Ensure that you adhere to the naming used below as this class will be used by other classes that you will develop. Make sure that your Book class extends the LibraryItem class.
2. Ensure that your class includes the following validation within the mutator (set) methods:
a. numPages cannot be less than one. If an attempt is made to set the numPages to an invalid amount, then the method should set the numPages to one and return false, otherwise set the numPages as given and return true.
b. The author cannot be a null or empty String. If an attempt is made to set the value of the author to an invalid value the method should set the author to be “Unknown” and return false.
3. Write additional methods for toString() and a method to check equality with another book (equality should be based on the title and author being the same for both books).
4. Select two Books that you will create. Choose values for each of the data attributes for each book. Write a class called TestClass (starter code is provided to copy from) and within the main method write code that will :
a. Instantiate an instance of the Book class for one of the Books you selected using the Book() constructor
b. Sets all of the instance variables to the appropriate values using the mutator methods (set)
c. Change the yearOfPublication to increase the yearOfPublication of the first Book by 10 years.
d. Instantiate an instance of the Class Book for a second different book using the Book constructor which has parameters.
e. Display both of the Books that you have created using the toString() method
f. Display both of the Books that you have created using individual accessor (get) methods in a print statement
5. Now create a second class representing another library item (e.g. video, CD etc.) in a similar fashion to the way you created the Book class. (The Book class is similar to the Square class in the sample code provided. The square class extends the Shapes class. The Rectangle class also extends the Shapes class. Your second library item type is similar to the Rectangle class. Your library item e.g. Video will extend the LibraryItem class.)
a. Decide on your library item type and then choose at least 3 attributes particular to that item type that will be instance variables
b. Draw a UML class diagram for your new class
c. Create your new class in a new file named appropriately e.g. Video.java
d. Make sure your new class extends the LibraryItem class
e. Write get and set methods for your new class
f. Write a toString() method for your new class
g. Test your new class by writing code to create an object based on this class in your TestClass class
h. Test your object by modifying one of the instance variables using a set method then display the object
Part D – Development of the Library class
Using the UML diagrams provided and the information below you are required to implement and test classes that represent a Library object. For this assignment a Library contains multiple LibraryItems up to a specified capacity. (This may be modeled on the ShapesList class in the sample code. The ShapesList class contains multiple Shapes in an array. Your Library will in a similar way contain multiple LibraryItems in an array.)
1. You have been provided with starting point in Library.java Write get and set methods as well as an addItem method. addItem should return false if an attempt is made to add an item after the Library has already reached its maximum capacity.
2. Create a method for sorting the LibraryItems in the Library (model this on the ShapesList bubblesort method)
3. Update the class TestClass adding in code to:
a. Create an instance of the Library class
b. Add at least two Books created to the Library class using the addItem() method
c. Add at least two other items (e.g. Video, CD etc) to the Library class
d. Display the details of the library that you have created using the toString() method in the Library class – these should be accessed via the instance of the library class that you have created
Part E – Using the Classes
Create a new class called LibrarySystem.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 Library object. The menu should include the following options:
1. Populate the Library
2. Display LibraryItems in the Library
3. Sort LibraryItems data
4. Import data (ITECH5000 students only)
5. Export data (ITECH5000 students only
6. Exit
To get assignment help, please contact to our live chat adviser