Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask PHP Expert

Tasks

This section describes each piece of functionality you must implement, and the order in which they must be implemented. These tasks must be completed in the order listed below. Please read Section "Marking Scheme" for more details on how these tasks would be marked.

Task 1: Classes and fields

Read the following system description and identify the classes and their fields. There are 3 classes of objects A game has 1 player and 3 dots (called dot1, dot2 and dot3). The player has an x and y value (both integers) which together describe the position of the player. The coordinate system of the x and y position is as follows: the x-coordinate increases from left to right, and the y-coordinate increases from top to bottom. Theplayer also keeps a counter of the number of dots collected (called collectedDots). Each dot has an x and y position with the same coordinate system as the player, and also has a boolean status called "exists" which is initially true and is set to false whenever the dot has been collected by the player.

In a new BlueJ project, define some classes and fields based on the above description. The names of your classes and fields should exactly match the noun phrases mentioned in the above system description, and must follow Java's naming conventions (i.e. class names begin with an uppercase letter, field names begin with a lowercase letter, compound nouns are joined without a space and the second word begins with an uppercase letter).

This is a multi-class program. You may find it helpful to refer to examples of "compositional" class designs in lecture 3 and tutorial 3.

All classes must be public and all fields must be private (taught in week 4).

Submit your project to PLATE now to receive your marks and feedback. You can resubmit unlimited times before the due date. Use the feedback from plate to improve your code and then resubmit to improve your mark.  


Task 2: Constructors

In this task, you will add constructors to each class to initialise the program.

2.1 Dot

Define a constructor for class Dot that takes the initial x and y values as parameters, and copies these initial values into the x and y fields.

The Dot constructor should also initialise the "exists" field to true.

2.2 Player

Define a constructor for class Player that takes the initial x and y values as parameters, and copies these initial values into the x and y fields. The collectedDots fields should also be initialised to 0.

Submit your code to PLATE to receive marks for this part and do the same for each subsequent part below. You are required to submit your progress to plate while you are making progress.

2.3 Game

Define a constructor for class Game that takes the initial x and y positions of the player as parameters and creates and initialises the player, dot1, dot2 and dot3 fields. The player should be created at the position given by the parameters. dot1, dot2 and dot3 must be created at positions (1,1), (2,2) and (3,3) respectively.

Preamble to Task 3 and Task 4

Tasks 3 and 4 can mostly be completed in any order. It is recommended that you do the easy parts first and leave the hard parts (labelled "advanced") until after you have completed the easy parts.

Task 3: move() method

Review the examples of class composition in the week 3 lecture notes and tutorial notes before attempting this task.

Compositionally define a move() method in class Game taking two int parameters called dx and dy. This method should tell the player to move by the given relative distance (dx,dy). That is, if the player is currently at position (x,y), the player should be moved to position (x+dx, y+dy). For example, if the player is currently at position (3,4) and the move method is used with parameters dx=2 and dy=3, then the player should move to position (5,7).

Advanced: (You can try this after completing the easy part of Task 4) The move() method should also tell the player to collect a dot if possible. The player can collect a dot only if the player is at the same position as the dot. When the player collects a dot, the player's "collectedDots" count should be increased by 1, and the dot should disappear. When a dot disappears, its "exists" field should be set to false.

Try not to put too much code in one class. In a good compositional design, the responsibility should be distributed throughout the system.

Task 4: toString() function

Define a toString() function for class Game that returns (but does not print) a string of the form:
 
Player[0](0,0) Dot(1,1) Dot(2,2) Dot(3,3)

The above string indicates the positions of the player and 3 dots, as well as the number of dots collected by the player. Here, [0] indicates the player has collected 0 dots, and each (x,y) indicates the position of a player or dot.

Advanced: If the player moves to position (2,2) and collect dot2, the string should appear as follows:

Player[1](2,2) Dot(1,1) Dot(-,-) Dot(3,3)

Showing the dot's position as (-,-) indicates that the dot has been collected and has disappeared.

This function must be defined compositionally. That is, Game.toString() should call upon toString() functions in other classes:

-  Player.toString() should return a string such as "Player[0](0,0)".
-  Dot.toString() should return a string such as "Dot(3,3)"

PHP , Programming

  • Category:- PHP
  • Reference No.:- M9895938
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in PHP

Question develop a 5-6 page word document that describes

Question: Develop a 5-6 page Word document that describes the design for a small Web site that meets the following specifications. 1. The Web site includes four or more Web pages designed according to current usability g ...

Question continue to build on the skills of providing web

Question: Continue to build on the skills of providing Web page content and structure with HTML and Web page style and layout using CSS. Demonstrate the skill of creating a dynamic Web page that includes JavaScript clien ...

Question using the course software and week one template as

Question: Using the course software and Week One Template as a starting point, create a new HTML webpage and include the following: • Write the code to display your name in the largest-size heading element. • Write the m ...

Final project assignment -requirements specifications -1

FINAL PROJECT ASSIGNMENT - REQUIREMENTS / SPECIFICATIONS - 1. For the final project, you will have to make good use of your CMS using PHP and MySQL for the content delivery. You will have to be able to deliver the conten ...

In php write a simple addtion calculator that reads in two

In PHP write a simple addtion calculator that reads in two values and then add them together and display the output. Be sure to validate both inputs and ensure that it can add 0+0 = Sum: 0. The user should be able to inp ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As