Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 01 (working with constructors - Ghost1.java): Goal: To create a class Ghost1, that stores the properties (position, size, colour, frightened & eaten states, and

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 01 (working with constructors - Ghost1.java): Goal: To create a class Ghost1, that stores the properties (position, size, colour, frightened \& eaten states, and direction) of a Ghost character that might be used in a Pacman game. Typically, a generic ghost (in its normal state), would look something like the following (constructed from a combination of layered filled ovals and rectangles): Where a ghost is enclosed withing a square of (size * size), and positioned at the coordinate (x,y), which represents the top left corner in the app window coordinate system (i.e. image coordinates, where 0,0 is the top left of the RasterImage window). The eyes each have a radius (eyeRad) for the whites of the eyes, and a radius (pupilRad) for the blacks of the eyes. The ghost has a direction (which reflects which direction it is currently moving which influences the position of the pupils in the eyes, and finally, two booleans to represent the state of the ghost (to indicate if it is "frightened" or "eaten") - which also influence its visual appearance. airections maicatea dy pupis ( frightened (top right), and eaten (bottom right) The Ghost1 class should support 3 constructors, that each create and store the basic properties of a ghost (as provided in the UML diagram below): 1. A default constructor (no arguments) a. Default position (x,y)=(0,0) b. Default size is 100 c. Default eyeRad =1/8th the size d. Default pupilRad =1/2 the eyeRad e. Default normalCol = CYAN ( use constant from java.awt.Color) f. Default frightened = false g. Default eaten = false h. Default direction = EAST (i.e. 0 degrees see/use constants in Game class) 2. Two custom constructors (according to the UML diagram below) a. Where values not provided as arguments are set to defaults as per (1) above 2. Two custom constructors (according to the UML diagram below) a. Where values not provided as arguments are set to defaults as per (1) above th be sure to use the "this" keyword in your constructors (see Lecture7/8) UML representation of aggregati "Ghostl aggregates a Color obje. Use your main method (in Ghost 1.java) as a client to test the above manually by: - constructing a Ghost 1 object called "scarey1" using the default constructor - print out its state using the tostring() method provided in the shell code - constructing a Ghost 1 object called "scarey2" using the default constructor: - directly increase its y position by 100 , - change its body color to red, - print out its state using tostring() - constructing a Ghost1 object called "scarey3" \& "scarey4" using the custom constructors: - scarey3 should have be instantiated with (x,y)=(300,400) and size =200 (with the remaining properties according to defaults) - modify scarey3 after creation, to give it a light gray body colour (see Color class) - print out scarey 3 using tostring() - scarey4 should have be instantiated with (x,y)=(580,340), and size =180, have a magenta body, and direction SOUTH (see Game class for direction constants) - print out scarey4 using tostring() ** you may also run the PartialTester.java file to run some partial junit tests to check the functionality of methods in this lab After running your main, you should have the following output: ** Note, if scarey 4 was set to have frightened=true, eaten=false its output would be: Ghost e (580,340) : [ size =180180] [ colour = java.awt. Color [r=255,g=0,b=255]] [ state = frightened ] If scarey4 was set to have frightened=true and eaten=true, its output would be: Ghost (580,340) : [size=180180][colour=java.awt.Color[r=255,g=0,b=255]][state=eaten] For all other cases of eaten (if frightened=false), the state would remain "normal" package lab3; import java.awt. Basicstroke; public class Ghost1 \{ // CLASS FIELDS // CLASS CONSTRUCTORS / * Default Constructor / public Ghost1() \{ \} // * Custom Constructor #1 */ public Ghost1(int x, int y, int size) \{ \} /** * Custom Constructor \#2 / public Ghost1(int x, int y, int size, Color body, int direction) \{ \} // CLASS METHODS / * A method that outputs the state of a Ghost1 object (as per the lab3 pdf output examples) */ public String tostcing() \{ \} // MAIN METHOD public static void main(String[] args) \{ / \} Custom Constructor #2 public Ghost 1 (int x, int y, int size, Color body, int direction) \{ \} / CLASS METHODS ================================ A method that outputs the state of a Ghost 1 object (as per the lab3 pdf output examples) / public String tostring 2 \{ \{ \} // MAIN METHOD =============== public static void main(String[] args) \{ / * In this task, you are to create a class to support the positioning, size, * color of a Ghost object (to mimic the ghost characters in a pacman-like game) * To achieve this, you will need to: 1. create class variables as per the UML diagram given in Question01 in the lab3 pdf 2. create a default constructor as per the UML diagram given (see lab3 pdf) 3. create 2 custom constructors as per the UML diagram given, (see lab3 pdf) 4. Use your main method as a client application to test the above (see lab3 pdf for instructions) 5. Run the PartialTester.java to check the functionality of these classes \}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

To create the Ghost1 class with the specified constructors and methods well follow the steps outlined in the prompt Lets walk through the implementati... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago