Starting from:

$35

KIT101 Programming Fundamentals Assignment 2 Solved

KIT101 Programming Fundamentals Assignment 2


Aims of the assignment
The purpose of this assignment is to:

  Give you experience at:

 Reading Java code and identifying the essential components - instance variables, method declarations, local variables

Reading and writing Java code that uses the following concepts:

 solving problems by using nesting, looping and branching constructs solving problems by sending messages to objects of suitable classes declaring new classes (declaring methods and instance variables) parameter passing to methods use of return values from methods   Writing appropriate documentation

  Forms to request extensions of time to submit assignments are available from the ICT Discipline office.  Requests must be accompanied by suitable documentation and should be submitted before the assignment due date.

Assignment Submission
There will be two parts to the submission. You must submit both of these:

 Electronic submission of the source code file (the PirateDog.java file)  See below for details of the method for electronic submission.

Paper submission of the external documentation specified. See  below for details.

Marking
This assignment will be marked out of 60. There will be marks for both the program and the external documentation. The breakdown of marks is shown below.

 This will be 15/40 (37.5%) of the marks for the in-semester component of assessment in the unit.

Remember, to pass the unit you must obtain at least 45% of the total possible marks for the insemester component of assessment.

The programming task -- Find your dogs!

You have two Yorkshire Terriers, let's call them Bistol and Poo (to protect their identities). They're on

https://mylo.utas.edu.au/content/enforced/169021-AW_EAI_16S2_1…SessionVal=Eh1HhJ5Ci7WInD9orSTzKEvrp&ou=169021&d2l_body_type=3

the run from Deputy Prime-Minister and HiFi store magnate Jarnaby Boyce, and you've got to find them before he does!

You will search the states of Australia for your beloved doggies. When you see them you'll try to catch them so that they're safe. To do this you have to lure them towards you. But they're playful and will only come the third time you call. If, however, you encounter Jarnaby while looking for them: you're in trouble buddy! You'll be so hurt by his rebuke that you will be dazed for two moves -- run into him again while you're dazed and go home Yankee, go home! You can call the dogs while dazed but you will stay dazed; you must move twice to clear your head. But dazed or not, you can only erroneously call out to the puppies three times -- if you shout in the wrong direction three times, you will be found by Jarnaby and deported. And who will look after the puppies then Captain? Game over. Indeed.

When you are not dazed it is possible for you to have some idea of your location, the states around you, and the location of your dogs (because their continuous annoying yapping gives their location away).

The on-line version of this document has a link to some sample output of both a stage 2 and stage 4 implementation of this game.

The completed implementation will consist of three files, only one of which must be written by you.

These files are:

  AssigTwo216.java This is the driver program (with a main() method). The code of this is complete and it MUST NOT be changed (unless Stage 4 is reached). The code in this file is very simple -- it declares and instantiates an object of the PirateDog class and calls its play() method. (The on-line version of this document has a link to the code.)

  R2JCD2.java This is a library class and this file contains resources that you are to use in developing your implementation of the task. The code is complete and MUST NOT be changed.

(The on-line version of this document has a link to the code.)

  PirateDog.java This is an organiser class and is the file that you are to write; the on-line version of this document has a link to a 'skeleton' version of the code -- use this as the starting point for your program.

 There will be no main() method in the class, it will contain methods that organise the task.

This will include all the interactions with the user.

You should make sure that you do the following:

  Create and use object(s) of the R2JCD2 class. You will LOSE MARKS if you write code in PirateDog.java that duplicates things that could be done using methods of the

R2JCD2 class.

 Use the trace() method (provided in the skeleton) to include tracing messages in your program -- switch the messages off before submission.

Use separate methods to implement the separate activities within the task. Use instance variables to store data that is used or changed by more than one method and/or needs to persist for the life of the object.

Use local variables to store the data that is used by just one method.

This program (like all programs) should be developed in stages, with each stage fully implemented and tested before the next stage is attempted. To provide you with some guidance about this, the detailed specification below is divided into four stages, you should aim to submit a program that implements at least stage 1.

A program that correctly implements stage 1 and provides all the required external documentation, both to a high standard will be able to score a maximum of 48 of the 60 marks. This is 80% -- a high distinction. If you have done all of this in plenty of time and want to try for an even higher mark, then you should begin to implement stage 2, and if you have time stages 3 and 4. Note that you will receive NO marks for your attempts to implement later stages if the marker finds that your implementation of earlier stages does not function as specified in this document.

VERY IMPORTANT: You must state in the header comments of your source code which stage of implementation your program has reached. If you do not do this then the marker may assume that you have only implemented stage 1 and you may not receive any marks for implementation of any other stages.

Details - Stage 1
(Note: even within stage 1, you should plan, implement, and test your program in sub-stages. It is part of your task to work these sub-stages out yourself.)

Write code in PirateDog.java to do the following:

  "Housekeeping" tasks -- PirateDog()

 Instantiate the R2JCD2 and Scanner classes.

Switch on the debugging/tracing messages in the PirateDog and R2JCD2 classes. (Switch them off before you submit your program for assessment.)

 Introduction -- explain()

Provide the user with a general explanation of the game.

 Play the game -- the user is prompted to make "moves" until the game is over.

The game will end when any one of the following happens:

 You try to move to the state occupied by Jarnaby while you are dazed.

You call the dogs when they're not there three times.

You call the dogs successfully three times.

You choose to quit the game.

  Before each move you are provided with information. If you are dazed then you are only reminded that you need to find the dogs, otherwise you are told:

 Your current location in Australia.

The numbers of the four connecting states.

The number of times you have called the dogs both successfully and unsuccessfully. Any available information about the location of the dogs -- i.e. whether you can hear their barking.

Any available information about the location of Jarnaby -- i.e. whether music from JB's HiFi can be heard.

  You will be asked what you want to do for this turn. The options are:

  Fly into another state (by number).

 You will be asked to enter the number of the state you want to fly into.

If the state is not connected to your current location you will not be able to fly, and should be told so.

 Otherwise if the state is connected to you current location, you will enter the new state and if the new state doesn't contain the dogs or Jarnaby the game will continue (with you becoming slightly less dazed if you were dazed) if the new state does contain Jarnaby and you were already dazed then the game is over, otherwise you become dazed and Jarnaby leaves to give a press conference.

  if the new state does contain the dogs then they will run away.

  Call into another state (by number).

 You will be asked to enter the number of the state you want to shout into.

If the state is not connected to your current location, you will be told this. If the state is connected and contains the dogs then it is noted that they have been called and the game continues. When this occurs for the third time, the dogs come to you and the game ends, otherwise the dogs run away.   If the state is connected but doesn't contain the dogs then it is noted that you've drawn attention to yourself unnecessarily and the game continues. When this occurs three times, the Australian Federal Police will arrest you and deport you and the game ends.

  Reset the Game.

  If this option is chosen then many game parameters are reset:

  your position is changed.

 the dogs' position is changed. Jarnaby's position is changed. your head is cleared (i.e. you are not dazed) the shouting tallies are reset to 0.

  Quit the game.

  The game will end.

Details - Stage 2
Remember

 You should only consider implementing this if you have completed and tested stage 1 and have time to spare.

You must state in the header comments of your source code that you have implemented stage 2.

Extra functionality at this stage:

 Before playing, you are asked whether or not you want to play, if not, there is no game played.

After each game is over, you are asked whether you want to play again.

The numbers of the states that the user enters should also be remembered (to a maximum of 20 moves and then the most recent 20 should be remembered). These values (in chronological order) should be displayed at the end of the game. See sample output for more information. Details - Stage 3

Remember

 You should only consider implementing this if you have completed and tested stage 2 and have time to spare. There is a lot of extra work in this Stage for very few marks.

You must state in the header comments of your source code that you have implemented stage 3.

Extra functionality at this stage

  Design and build a graphical user interface (GUI) for the output of the program (display of messages after each move, and the final messages). The input (including prompts to the user) will be from the console (using methods of the Scanner class) (as in stages 1 and 2).

  NOTE: You are not expected to, and should not attempt to write your own code to open, position, arrange, or close the GUI.

Write extra code in PirateDog.java (which should now extend QuickGUI)

  "Housekeeping" tasks -- PirateDog()

  Create the GUI (consisting of Fly, Call, Reset, and Quit buttons, and (perhaps) a read-only text field and two ordinary text fields).

   Show the information to the player and present them with their choices -- paintComponent() Add the functionality of displaying the user's status on the GUI within a new method:

paintComponent().

Place calls to repaint() within the program.

You may find some Tutorials helpful.

Details - Stage 4
Remember

 You should only consider implementing this if you have completed and tested stage 3 and have time to spare. There is a huge amount of extra work in this Stage for very few marks.

You must state in the header comments of your source code that you have implemented stage 4.

Extra functionality at this stage

  Make the graphical user interface interactive, that is all interaction between the user and the program should be through the GUI.

  NOTE: You are not expected to, and should not attempt to write your own code to open, position, arrange, or close the GUI.

Write code in PirateDog.java (which should now also implement ActionListener) to do the following:

  "Housekeeping" tasks -- PirateDog()

Ensure ActionEvents will be listened for by the buttons and a text field.

Comment out the call to play() in the AssigTwo216.java file.

   Manage the pressing of buttons and typing in the text field -- actionPerformed()

If the user has elected to fly, shout, reset, or quit

  Manage this appropriately (similar to the play() method).

repaint() the screen.

You may find some Tutorials helpful.

Planning and Documentation
The first thing that you need to do is to understand what uses can be made of objects of the R2JCD2 class. To do this:

   Read the code carefully, making sure that you can identify instance variables

methods - read the header comments and the code of these and work out what they do (fill in a table like the one shown below as you do this).

 Write a driver program to instantiate an object of the R2JCD2 class and call its methods (to check that they behave the way that you think they do).

Complete a table showing what you have deduced about the R2JCD2 class. This table must:

 Have the columns shown below.

Have a row for each method in the R2JCD2 class.

Be submitted for assessment.

The on-line version of this document has a link to a word document that can be used for this table.

method

identifier
return type
parameters
instance variables used by this method
what does the method do?
 
 
 
 
 
 
 
 
 
 
   Plan how to write code to "organise" the "PirateDog" activity (using object(s) of the R2JCD2 class) Work out the subtasks that will be needed (each of these should be implemented as a method).

Work out the data that will need to be "shared" by more than one method. These will usually be implemented with instance variables.

For each method work out:

 the data it will need to have passed in (parameters) the data it will need to pass out (return value) the algorithm for doing the subtask

 Implement each step after you have planned it -- a little bit at a time -- compile and test the implementation as you go.

Complete (as you go) a table documenting your plan and progress. This table must:

 Have the columns shown below.

Have a row for each instance variable in your PirateDog class.

Have a row for each method in your PirateDog class.

Be submitted for assessment.

The on-line version of this document has a link to a word document that can be used for

this table.

Instance variables
 
identifier
type
What is this used for?
Which methods used this variable?
 
 
 
 
 
 
 
 
methods
 
identifier
return type
parameters
what does the method do?
instance variables used
Development history for this method
implementation

of code (of this method)

date coding completed
testing of code (of this method)

date testing completed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Program Style
The code you write for this assignment must be a single class called PirateDog, with the code in a file called PirateDog.java. This class should not have a main() method, execution of the code will be initiated from the "driver" program AssigTwo216.java (supplied). It is expected that the code in PirateDog.java will instantiate an R2JCD2 object (code supplied) and will call its methods.

 Your program should follow the coding conventions introduced in this unit, especially: Variable identifiers should start with a lower case letter final variable identifiers should be written all in upper case and declared before non-final variables

All local variables (with the exception of loop counters in for loops) should be declared at the start of methods and before any other Java statements

Every if-else statement should have a block of code for both the if part and the else part (if used)

Every loop should have a block of code

The program should use final variables as much as possible

Opening and closing braces of a block should be aligned

All code within a block should be aligned and indented 1 tab stop from the braces marking this block

Commenting:

 There should be a block of header comment which includes at least   file name, student name and ID, stage of development reached

Each variable declaration should be commented

There should be header comments for each method indicating:

 What the method does

The purpose of the parameters (if there are any)

What the return value (if any) is for

What and how to submit      NOTE: You must make both paper and

electronic submissions
Paper submission

 A signed cover page (blanks can be collected from the ICT Discipline office or from the ICT Discipline web site)

A print out of the source code file for the program (PirateDog.java). ESSENTIAL -- your assignment will not be fully marked unless this is present.

  The header comments of this source code must indicate the stage of implementation your program has reached.

 Stage 1

Stage 2

Stage 3

Stage 4

  It is suggested that you print your program in landscape orientation.

 A completed version of a table showing your deductions from reading the code of R2JCD2.java. A table of the methods you planned and implemented in PirateDog.java

Electronic submission

 The source code file which must be named PirateDog.java

NOTE: This is the only file that is to be submitted. Your program will be tested using the files AssigTwo216.java and R2JCD2.java that are identical to the ones provided (as links from the online version of this document).

Submission Method:

NOTE: You must make both paper and electronic submissions by the due date

Paper submission: Submit the required documents by the due date (3:00 pm Monday 10 October, 2016)

To complete the paper submission:

 Firmly staple together all of the required documents (with the signed cover page on top) Place them in the appropriate submissions box (in the corridor near the Discipline Help Desk).

Electronic submission: Submit the file by the due date (3:00 pm Monday 10 October, 2016)

NOTE: The source code file must be named PirateDog.java

To submit this file for marking, place it in the Assignment 2 Dropbox on MyLO by the due date.

In order to protect yourself, keep the original file safe and do not edit it after the due date. This file might be required should there be questions about your submission.

Marking scheme:

Task/Topic
Maximum mark
Stage 1: Program operates as specified
 
User is shown information about the game at the start
1
User is prompted correctly for each turn (dazed and otherwise)
2
Fly option works correctly
4
https://mylo.utas.edu.au/content/enforced/169021-AW_EAI_16S2_1…SessionVal=Eh1HhJ5Ci7WInD9orSTzKEvrp&ou=169021&d2l_body_type=3

 

 new state not connected new state connected and empty

new state connected and containing dogs (oops) state connected but containing Jarnaby (big oops)
 
 Call option works correctly state not connected

state connected but empty (deported) state connected and containing dogs (success)
3
Reset Game option works
1
Game ends if user quits
1
Stage 2: Program operates as specified - this will not be assessed unless the header comments indicate that Stage 2 has been implemented
Players can play as many games as they like (including 0)
2
Move history correctly shown
2
Stage 3: Program operates as specified - this will not be assessed unless the header comments indicate that Stage 3 has been implemented
GUI created
1
GUI displays output messages
3
Stage 4: Program operates as specified - this will not be assessed unless the header comments indicate that Stage 4 has been implemented
GUI is fully interactive
4
Program & Coding Style

NOTE: To obtain any of the marks for this section you must submit a copy of your source code
Uses R2JCD2 methods wherever possible
3
Separate methods for separate parts of the task (additional methods beyond those named are required).
3
Instance variables to share data between methods
2
Locally used data declared local to the method
2
Uses final variables (constants) where possible
2
Logic of code can be followed
3
Correctly uses the Java naming conventions
2
Always uses blocks for branch and loop constructs
2
Internal Documentation
Alignment of code and use of white space makes code readable
2
 
 
Meaningful identifiers
2
Header comments for the program (author, date etc) including implementation stage reached
2
Each instance variable declaration is commented
1
Header and body comments for each method
2
External Documentation
 
Table showing methods in R2JCD2 is supplied and complete
4
Table documenting PirateDog is supplied and agrees with program
4
 

Help and hints:

 Read the specification carefully and make sure that you know what your program needs to do.

Work out some pencil and paper examples.

 Break the problem down into subtasks. For each of these tasks Produce an algorithm before writing any code.

When you start to code add only a small amount of code at a time.

Compile and run to check that this part is working before proceeding.

Test thoroughly to see that the program you have written performs this task correctly.   You will waste a lot of your time  if you do not follow a step-by-step method of solving a problem such as this. It is a mistake to think that this step-by-step method is slower than trying to tackle the whole problem at once.  It never is.

 Once you think you have completed your program, test it thoroughly to ensure it works correctly.

Repeat these tests if you make any modifications to your program.

DO NOT neglect your tutorial work in the unit to work on the assignment.  Some of the tutorial activities may lead you to see what needs to be done in the assignment.

You may seek help with this assignment in normal consultation times for this unit or via email to your lecturer.  Here are some hints to make best use of help.

 Make sure you know (or think you know) what your problem is.

Have details of the work you have done so far and the progress you have made on hand when you seek help.

The more specific you can be in your request for help the more immediately useful the help is likely to be.

Plagiarism and Cheating:

Practical assignments are used by the Discipline of ICT for students to both reinforce and demonstrate their understanding of  material which has been presented in class. They have a role both for assessment and for learning.  It is a requirement that work you hand in for assessment is substantially your own.

Working with others

  One effective way to grasp principles and concepts is to discuss the issues with your peers and/or friends. You are encouraged to do this. We also encourage you to discuss aspects of practical assignments with others. However, once you have clarified the principles, you must express them in writing or electronically entirely by yourself. In other words you must develop the algorithm to solve the problem and write the program which implements this algorithm yourself.

Cheating

 Cheating occurs if you claim work as your own when it is substantially the work of someone else.

Cheating is an offence under the Ordinance of Student Discipline within the University.

Furthermore, the computing profession has ethical standards in which cheating has no place.

Cheating involves two or more parties.

 If you allow written work, computer listings, or disks to be viewed, borrowed, or copied by another student you are an equal partner in the act of cheating.

You should also be careful to ensure that your work is not left in a situation where it may be stolen by others.

  Where there is a reasonable cause to believe that a case of cheating has occurred, this will be brought to the attention of the unit lecturer. If the lecturer considers that there is evidence of cheating, then no marks will be given to any of the students involved. The case will be referred to the Head of School for consideration of further action.

More products