Define a constructor for class game that takes the initial x

Assignment Help PHP Web Programming
Reference no: EM13316626

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)"

Reference no: EM13316626

Questions Cloud

Determine the inlet volumetric flow rate for the ammonia : The magitude of the power input to the compressor is 7,5kW and there is heat tranfser from the compressor to the surroundings at a rate of 0.15kW. Kinetic and potential energy are negligible.
What is the intial velocity of the projectiles : Two identical launchers fire projectiles with the same initial velocity. One launcher is 3.54m above the ground and fires horizontally. what is the intial velocity of the projectiles
Determine what is the manometer reading at b : Given the manometer reading at A is 100 kPa, D = 10 cm, d = 5 cm, VA = 2 m/s, and specific weight of water is 9800 N/m3, what is the manometer reading at B. Note that flow rate (Q) is constant and Q = VA
Calculate the resistivity of nichrome in this situation : The heating element of a simple heater consists of a 2.2-m-long, 0.65-mm-diameter nichrome wire. calculate the resistivity of nichrome in this situation
Define a constructor for class game that takes the initial x : 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.
Why anthonys performance is slipping : Anthony’s performance has been lower in the last six months than his average in the previous three years. Anthony’s supervisor wants to understand why Anthony’s performance is slipping. It is obvious that Anthony’s ability has not changed, so the sup..
Find the pressures in the two horizontal pipes : A liquid is flowing through a horizontal pipe whose radius is 0.0216 m. What volume flow rate will keep the pressures in the two horizontal pipes the same
What is lowest grade possible for the constant-grade section : A tangent section of highway has a -1.0% grade and ends at station 4+75 and elevation 82 ft. It must be connected to another section of highway that has a -1% grade and that begins at station 44+12 and elevation 131.2 ft.
What is the total impedance : A series RCL circuit driven at angular frequency %u03C9 = 505 rad/s has a capacitive reactance XC = 851 %u03A9, What is the total impedance

Reviews

Write a Review

PHP Web Programming Questions & Answers

  Prepare an ajax enabled web form

Prepare an AJAX enabled web form utilising a ListView control that will allow logged-in staff to list, edit, delete, insert magazine details for magazines from a selected magazine category.

  Online banking application

Designing and developing a web applications The company you are working has secured a contract with a local banking group to develop an ONLINE BANKING APPLICATION using PHP and MySQL.

  Create a web site for an apple farm

Create a web site for an apple farm. Create an HTML5 form allowing visitors to create an account with the site. Account details are to be stored in your MySQL database. Information should be stored in a secure way.

  Need an php script that redirect the visitor to url

Need an php script that redirect the visitor to url or dir based on their ip address if the visitor from Germany -

  The average score and all the scores above the average score

print all the scores below the average score and all the scores above the average score in php.

  Functions and code to test array of strings in php

Write, test and debug PHP scripts for specifications which follow. Write functions and code to test them. Parameter: An array of strings.

  Php script and then saves the form

Create a simple survey form that posts to a PHP script and then saves the form inputs to a file. The program should then respond with a display of the information contained in the file including the latest post

  Create a data structure containing a list of degrees

Create a data structure containing a list of degrees available (i.e. PhD, MS, MA, BS, etc) and a price for each degree.

  What are two php development tools

what are two PHP Development tools What is their cost? What platform do they run on? What is their purported 'claim-to-fame'?

  Create a table in your database server

Write a PHP script to create a table in your database server to hold your user data - Create a nicely formatted (based on formatting topics we've covered so far) web page with a form to collect user data

  Design a dynamic database

Design a dynamic database using Mangodb, html , and php.

  Design a phishing pages

An assignment to design a Phishing Pages for a popular website "Apple" Phishing pages like this first page:

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