Identify and use the correct syntax of a common programming


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 starting code provided; and

• Complete the analysis, design, implementation and debugging of a small program that is pre- dominantly procedural in nature;

Understanding and Enhancement of a Simple Menu Driven Program

Application Overview

For this assignment you have been provided with incomplete starter code that you must understand, modify and add to. The system provided simulates the collection, modification and reporting of game characters. The game characters have a unique id created in the program and have a number of attributes including a health rating and a power value. The system is run within the Eclipse IDE and provides a menu through the IDE console. The user must enter a pre-defined number of game characters before any of the other functionality can be used. At present, the following menu items are working:

• Create your characters;

• Display formatted information of all characters;

• Display a particular character;

• Display total legs and power for all characters; and

• Empower your character.

One function listed on the menu is not working:

• Display entered information of all characters You must write the code for the missing function.

Additionally, there are some changes required to the existing code. These changes are required to demonstrate the variety of ways of dealing with sequencing, selection and repetition and also demonstrate your capabilities for understanding and changing the code.

PART A - Code Comprehension

The sample code provided in the GameCharacters.java class should be used to answer the following questions. Familiarise yourself with the operation of the application by running it and choosing the working options - 1,3,4,5,6:

1. Identify in the code the way in which users interact with the program. Identify the object and list the lines of code where the object is used to receive information from the user. Also list the lines of code where the program sends output to the user.

2. What is the purpose of the "\t" in some of the literal Strings presented in the code?

3. How many game characters can be entered for this system? How many attributes does each character have? Identify the three lines of code where this information is established.

4. Currently, if the user enters an incorrect menu selection, what happens? Explain why the error message is displayed and what method and line of code is responsible and why.

5. The method menuSystem() is replaced with the code below. What would be shown for option 3 - display formatted information of all characters - if you had not yet entered any data (menuSelection ==1)? Where did the information displayed come from?

6. Explain in your own words what is happening on each line of the method createCharacterCode(int x).

7. After entering the required number of game characters, choose option 3 to display formatted information of all characters and complete the following table of variable values after executing each line of the method decodeCharacterCode(int _code, int _row). Use a _row value of 1 and if a variable is not defined at any stage, use the text ‘not defined':

8. Now change the value of the FACTOR constant to 1000. Compile and run the application entering another set of game characters and choose option 3 to display the information. The code and studentID are incorrect on the report. What has gone wrong?

9. In the createCharacterCode(int x) method, line 212 has the operation almostCharacterCode = almostCharacterCode * FACTOR; What would happen if you changed the "*" to a "/"? What primitive data type is almostCharacterCode and what would a more appropriate data type be if you changed the "*" to a "/"?

10. In the displayCharacterDetails(int _a) method a switch statement has been used to assist in assembling the String that lists the attributes of each character. The break keyword is used in this switch statement. What would happen if the break statement was removed after the first case (line 297)? You should discuss what generally happens with a switch statement when you remove the break and what actually happened here from an application perspective. What java error occurs?

11. When entering characters, how many times is the createCharacterCode(int x) method executed? In the method itself, the condition if (almostCharacterCode == 0) exists. What other variable could have been used instead of almostCharacterCode to achieve the same outcome?

12. Explain the purpose of the boolean variable finished in the addPowerToCharacter () method and how it is used.

PART B - Programming Requirements

1. Provide the code for the displayAllCharactersRaw () method. You are expected to just list what has been entered by the user in "raw" form as well as the generated character code without any interpretation (i.e. the data as stored in the two dimensional array). In your solution you must use nested for loops and the constants for array dimensions. You must also only have one print statement in the outer loop detailing the attributes for the current character. This is done by using a String and concatenating to it. Look at the charAttrs variable in the displayCharacterDetails(int _a) method for an example of this.

2. Add any functionality required to allow two new power types to be added. Hint: you do not need to write any new lines of code. The power types and their values should be unique to each student.

3. In the createCharacters () method, change the while loop for obtaining the studentID to a priming read while loop. Look at your lecture notes for week 4 for information on this.

4. In the displayCharacterDetails(int _a) method, replace the switch statement with a series of if/else if combinations to achieve the same functionality.

5. In the displayTotalLegsAndPower() method replace the for loop with a while loop. Look at your lecture notes from week 5 for information about this.

6. In the obtainCharacterAttribute(String _introText, String[] _typesText, int _min, int _max) method change the while loop to a do while loop.

PART C - Testing

An important part of verifying what you have done is testing. As per your lecture notes from week 5 you should consider:

• Ensuring that the program is what the client is asking for (you have to be both client and programmer here);

• Testing the design of the program to check that it meets the requirements;
• Desk checking the code written; and
• Testing the implementation of the code.

When testing, you should be able to distinguish between syntax, runtime and logic errors. Syntax errors are expected to be eliminated before submission (Eclipse IDE helps with this). Runtime and Logic errors are also expected to be eliminated if sufficient testing has occurred.

You should at this early stage satisfy yourself and provide evidence that any changes you have made in PART B work as they should and have not had any adverse impact on other components.

As a minimum you should provide evidence of the output of the system and its various functions before the changes and evidence of this after the changes. It is suggested that you make use of tables to display the data and testing.

Attachment:- GameCharacters.rar

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Identify and use the correct syntax of a common programming
Reference No:- TGS01223984

Now Priced at $75 (50% Discount)

Recommended (92%)

Rated (4.4/5)

A

Anonymous user

2/25/2016 4:22:05 AM

The assignment is mainly belongs to java programming. Be sure to read all the instructions carefully and perform the tasks as per instructions. 1) Give the code for the displayAllCharactersRaw () method. You are estimated to just list what has been entered via the user in "raw" form and also the generated character code devoid of any interpretation (that is, the data as stored in the 2-dimensional array). In your answer you should make use of nested for loops and the constants for the array dimensions. You should as well only encompass one print statement in the outer loop explaining the attributes for the current character. This is completed by employing a String and concatenating to it. Look at the charAttrs variable in the displayCharacterDetails(int _a) method for an illustration of this. 2) Add any functionality needed to allow two new power types to be added. 3) In createCharacters () method, modify the while loop for getting the studentID to a priming read while loop.