ITECH1000 Programming 1, Semester 1 2015 Assignment 2 – Development of a Simple Program Involving Multiple Classes
ITECH1000 Programming 1, Semester 1 2015 Assignment 2 – Development of a Simple Program Involving MultipleClasses
To provide students with the opportunity to apply the knowledge acquired and skills developed during the 11 weeks of the Course. This assignment extends from the learning of the first six weeks in the areas of understanding of primitive data types and the concept of collections (in the form of arrays) as well as structured programming including sequence, selection and repetition to beginning to understand and implement object oriented concepts and basic file input and output as well as sorting algorithms.
In the process of this assessment task you will:
• Identify and use the correct syntax of a common programming language (Java);
• Describe program functionality based on analysis of a given program;
• Recall and use typical programming constructs to analyse, design and implement simple software solutions; and
• demonstrate debugging and testing skills whilst writing code.
• Provide evidence of code comprehension skills by answering questions relating to the code provided;
• Complete the analysis, design, implementation and debugging of a small program that is pre-dominantly object oriented in nature;
• Include components of analysis, design, implementation and debugging of code that includes file I/O and sorting algorithms.
Due date: Week 11, Friday, 4pm
Please see the Course Description for further information related to submission date, extensions for assignments and Special Consideration. It is your responsibility to submit the appropriate correct version of your files and assignment and report any issues with upload to Moodle as soon as possible.
Marks: This assignment has a total of 180 marks (ITECH1000) or 200 marks (ITECH5000) and it is worth 20% out of the total assessment.
Authorship: This assignment is an individual assignment and it should be completed by the individual student only. The final submission must be identifiably the work of the individual. To support this, you will be required to demonstrate your working code to your tutor in your tutorial class and explain a selection of your assignment answers.
Resources Provided: The following files are available on your Moodle shell:
• An electronic copy of this assignment
• Sample code – TestingShapesListClass and others – for code comprehension
• Links to relevant Federation University resources
Notes You are strongly advised to keep backup files as you work.
If you use any resources apart from the Course material to complete the assignment, you MUST provide an in-text citation within your documentation and/or code as well as providing a list of references in APA format.
Development of a Program Involving Multiple Classes
Please read through the entire specification PRIOR to beginning work. The assignment should be completed in the stages mentioned below.
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 provide 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 provide in the lecture slides.
3. Add appropriate comments into the file: ShapesList.java to explain all the methods. At a mimimum, 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 what the purpose of the call to hasNextLine() 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. Explain the use of the return value in the getArea() method in the Rectangle class. What is it returning? Where does the value come from?
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. In the TestingShapesListClass file, in testrun6, the exportToFile method is called with an argument of
ShapesList.toString(). What is the purpose of the ‘ ’ in the toString() method of the ShapesList class 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.
Part B – Development of a basic Class: Character
Your first coding task is to implement and test a class that represents a Character in a game. A Character object has properties relating to each character: the date of birth is stored in 3 instance variables: day, month, year; the eye colour, number of legs, power level and health level of the character are also stored. You may reuse significant parts of code from assignment 1’s GameCharacters.java.
To complete this task, you are required to:
1. Create a new package in eclipse named assignment2_Student_NNNNNNNN where NNNNNNNN 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 Character in a file called Character.java.
Figure 1: UML Diagram for the class Character (* Note a more detailed UML diagram is provided in appendix)
As you implement the Character.java code, consider that you are now writing object oriented code to act on ‘this’ character. Ensure that you add appropriate data validation code into your set methods. For example, your setLegs method will check that the integer argument passed in is between MIN_LEGS and MAX_LEGS before changing the value of the instance variable legs.
3. Create a constructor for the Character object that will give each character a unique characterNumber (e.g.
this.characterNumber = characterCount++;) and initialise all other attributes to zero value. In order for each character to have a unique character number value, characterCount should be declared as a static class variable initialised to zero.
4. Author all mutator and accessor (set and get) methods and the toString() as indicated in the UML diagram. Copy the other methods from the assignment 1 code and modify the code so that it is now referring to this character. For example, in assignment 1, you may have referred to a particular attribute by referencing a position in the array. In this current assignment, the attribute will be an instance variable on the Character object. For example, in assignment 1, you may have had code such as: tableOfCharacters[choice][POWER] whilst in the modified code for this assignment, you may use a list of character objects in an array so that you choose a particular character as :
Character chosenCharacter = listOfCharacters[choice] and you then refer to the power for the chosen character as: chosenCharacter.power
5. Ensure that your Character class includes the validation within the mutator (set) methods to check that each attribute is valid (i.e. between the MIN and MAX values stored as constants). You may copy the constants from assignment 1 code. The constants are shown in the more detailed UML diagram in Appendix A of this document.
Part C – Development of extended Classes using inheritance
Your next task is to think about the object oriented paradigm in programming and describe how you would implement a hierarchy of special characters. If for instance, you eventually wanted to have 2 types of special characters: Fighter characters and Healing characters, each with the basic character attributes plus additional attributes. The Fighter character might have an attribute that represents its ability to kill other characters whilst a Healing character might be able to administer first aid to improve the health of another character.
1. Considering this potential requirement, describe how you might implement 2 new character classes Fighter.java and Healer.java and how they would relate to the Character.java class.
2. Would you be able to insert such characters in your character array in the Game object?
In approximately 200 to 250 words discuss your answers to the above questions.
Part D – Development of related Classes
Your second coding task is to implement and test a class that represents a Game. In the Game class you will have a collection of Character objects. To complete this task you are required to:
1. Use the UML diagram provided to implement the class Game in a file called Game.java. In this class you will put all the code that is related to the collection (array) of characters. Eventually, you will create a Game object e.g. Game myGame = new Game(); and then you will be able to access all your characters in the array of Character objects: myGame.listOfCharacters
Figure 2: UML Diagram for the class Game
Part E – Development of the MenuSystem class
The menu system developed will provide the interface to the user but will only call methods on the myGame object to ‘enact’ the game. Within the menu system, you will need to create an instance object, myGame to reference the game. Create the menu system by creating a new class called MenuSystem.java . The UML class diagram in appendix A provides details on the methods that are in this class. This class is to be used to implement a basic menu system. You may find some of the code from assignment 1 can be copied and used with some modification here. Menu items should call the appropriate method on the myGame object. The menu should include the same options as your assignment 1 system:
Choose options to create, display or enhance your characters
Option 1: Create your characters
Option 2: Display entered information of all characters
Option 3: Display formatted information of all characters Option 4: Display a particular character
Option 5: Display total legs and power for all characters
Option 6: Empower your character
Option 99: Quit
Part F – Implementing a Sort algorithm
Your final coding task is to utilise some form of sorting algorithm to sort the characters in a game into ascending order based on their power. (Hint: look at the sort method in the ShapesList class. It sorts on the area of the shape.)
Add a new Option to your menu that implements a sort of the array of Characters:
Option 7: Sort characters based on power.
This option should call the sort method which you should implement in the Game class.
Part G – For students enrolled in ITECH5000 ONLY:
Add 2 new options to the menu that will enable creating the character array by reading the data from a file and saving the character data to a file:
• Import data – this menu should read in character data from the filed called CharacterData.txt.
• Export data – save the data to a new file ExportCharacterData.txt
The following criteria will be used when marking your assignment:
• successful completion of the required tasks;
• quality of code that adheres to the programming standards for the course; including:
• comments and documentation
• code layout
• meaningful variable names
You are required to provide documentation, contained in an appropriate file, which includes:
• a front page – indicating your name, a statement of what has been completed and acknowledgement of the names of all people (including other students and people outside of the university) who have assisted you and details on what parts of the assignment that they have assisted you with;
• a table of contents and page numbers
• answers to the questions from Part A
• answers to the questions from Part C
• list of references used (APA style); please specify if none have been used
• An appendix containing evidence of your testing
Using the link provided in Moodle, please upload the following:
1. All of the classes created in a single zip file – Surname_ StudentId _Assign2.zip
2. A copy of your report – Surname_ StudentID _Assign2.docx or Surname_ StudentID _Assign2.pdf
PART A – Code Comprehension
PART B – Character class (code correctness, comments)
PART C – Explanation of how to implement special characters
PART D – Game class (code correctness, comments)
PART E – Implementation of Menu system
PART F – Implementation of Sort in game class
PART G – ITECH5000 students only – File input/output /20
Quality of code created
Presentation of documentation and report showing evidence of testing
[contact-form-7 id=”232″ title=”Contact form 1″]