Creates a list of shapes stored in an array

Assignment Help JAVA Programming
Reference no: EM13943405

Purpose

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.

Learning Objectives

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.

General Requirements
• 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.

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 ‘\r\n' 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.

Character

~ day: int

~ month: int

~ year: int

~ eyeColour: int

~ power: int

~ healthiness: int

• add PowerToCharacter(): void
• Character()
• createC ha racterCode(int): void
• decodeCharacterCode(): int
• displayCharacterDetails(): void
• displayOneCharacter(): void
• getLegs(): int
• getP ower(): int
• setDay(int): void
• setEyeColour(int): void
• setHealthiness(int): void
• setLegs(int): void
• setMonth(int): void
• setPower(int): void
• setYear(int): void
• toString(): String

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

Game

- END_REPORT: String =" - End o... {readOnly}
- NCHARACTERS: int = 3 {readOnly}
- ListOfCharacters: Character ([])
- listOFCharactersFilled: boolean = false
- studentlD: int = 0

• Game()
• createCharacters(Scanner): void
• displayAllCharactersRaw(): void
• displayAllCharactersForrnatted(): void
• toString(): String
• displayTotalLegsAndPower(): void
• obtainCharacterAttribute(Scanner, String, Stringfl, int, int): t

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:

Menu
====
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

Attachment:- Assignment.rar

Reference no: EM13943405

Questions Cloud

Key points on the ethical culture in your organization : Ethical Business Cultures- Share key points on the ethical culture in your organization or organizations you have observed
Develop a use case model : Selecting a Design for the Presentation
Explain what is meant by unconditional stability in a op-amp : The open-loop response of an uncompensated op-amp. Compensation is to be applied to the amplifier to make it unconditionally stable. Estimate the frequency at which the breakpoint of the compensated response must occur.
Identify burger king resources and capabilities : Discussion: Based on the Case Study "Burger King.", complete the following requirements: Utilizing the Addendum, identify Burger King's resources, capabilities, and core competencies
Creates a list of shapes stored in an array : Identify and use the correct syntax of a common programming language (Java) - describe program functionality based on analysis of a given program;
Discuss different viewpoints regarding works of literature : Discuss different viewpoints regarding the works of literature. Explore and evaluate how the theme is demonstrated or portrayed in two different forms of literature.
Search for a dss to find the optimal solution. : Your objective is to provide your procurement VP with a tool that will help him determine the least costly alternative so that all three plants are in continuous operation for the next 12 years.
How would the following ratios be affected by the accounting : In a period of rising prices, how would the following ratios be affected by the accounting decision to select LIFO, rather than FIFO, for inventory valuation?
Find diameter of wire d when no mechanical force is applied : Thin Manganin wire of the length l = 0.5 m is glued to the electrically insulating rod. The insulating rod is subsequently stretched by applying axial mechanical force. Prior to stretching the resistance of Manganin wire was R0 = 10 ? and after a..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a recursive boolean method named ismember in java

Write a recursive boolean method named isMember in Java. The method should accept three arguments: an array, a value to search for, and the size of the part of the array being searched.

  Create a world class that contains a 2d array

You have to create a world class that contains a 2d array then create an abstract class called organism that contains move() method the organism should move randomly one step at the time.

  Minimal spanning tree decreasing edge

minimal spanning tree decreasing edge dismissalreverse-delete algorithm. develop an implementation that computes the

  Create an abstract class called aqualife.

Fish has an attribute which stores whether the fish is an herbivore or a carnivore. Its eats method checks whether herbivore or carnivore, and prints 'This fish eats veggies' for herbivores and 'This fish eats other fish' for carnivores. Its procr..

  Class to initialize values

Create a constructor that allows a user of the class to initialize values. Also create a method named SetJustSold()(Hint ++) that increments the number of hot dogs the stand has sold by one and should also increase the TotalSold by one

  Determine java application on web and structure functions

Determine the Java application on Web and explain how program structure functions. Explain the application in as much detail as possible.

  List data structures to be used in solution

write a program that will prompt the user for an input file name to read from. The Input file will consist of records made up of first name, last name and an account balance of individuals and store the individuals in an ArrayList.

  Drags html list items to and from a javascript array

1.Write a program which drags html list items to and from a javascript array.2. if an identical list item is already in the array, prevent the list item from dropping in the array. Give an error saying that the list item already exists in the array

  Which announces whether or not the player has won the game

2D graphics, instead of text, to display the Xs and Os in the grids of the square- shaped buttons decision logic or recursion in order to determine whether or not a player wins the games. Display a message which announces whether or not the player ha..

  Design a program in pseudocode

Design a program in pseudocode that solves this problem. You are required to generate only the pseudocode - No charting or analysis section is required, but you may have to incorporate the bubble sort algorithm to determine the minimum and maximum..

  Complete the recursive method matchstring x string y in the

complete the recursive method matchstring x string y in the code below which will determine whether or not two strings

  Compare string values

Write a program that reads two strings from the keyboard and compares them and prints whether they are equal or not.

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