Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.awt.Color; import java.io.PrintStream; public class Hero { // CLASS FIELDS ======================================= // CLASS CONSTRUCTORS ================================= /** * Default Constructor */ public Hero() { }

image text in transcribed

image text in transcribed

image text in transcribed

import java.awt.Color; import java.io.PrintStream;

public class Hero { // CLASS FIELDS =======================================

// CLASS CONSTRUCTORS ================================= /** * Default Constructor */ public Hero() { } /** * Custom Constructor #1 * * @param x * @param y */ public Hero(double x, double y) { } /** * Custom Constructor #2 * * @param x * @param y * @param body * @param engines */ public Hero(double x, double y, Color body, Color engines) { } // CLASS METHODS ====================================== /** * This method is provided for you (DO NOT EDIT) * it can be used to output the state of a Hero object * * Assumes that class fields exist and are created as * per the UML diagram in the lab3 pdf (part 1) * */ public String toString() { String result = ""; result = "Hero @ (" + this.x + ", " + this.y + "): "; result += " [ width= " + this.width + ", height= " + this.height + " ] "; result += " [ body= " + this.body + " ] "; result += " [ engines= " + this.engines + " ] "; return result; }

public static void main(String[] args) { /* * * In this task, you are to create a class to support the positioning, size * and color of a Hero object (the player's icon in a SpaceInvaders-like game) * * To achieve this, you will need to: * * 1. create class variables as per the UML diagram given in Exercise01 in the lab3 pdf * * 2. create a default constructor as per the UML diagram given, where: * - the default position is (0,0) * - the default width is 50 * - the default height is 40 * - the default bodyColor is black * - the default engineColor is red * * 3. create 2 custom constructors as per the UML diagram given, where: * - any arguments not provided are set to default values as per * the default constructor outlined in item 2 above * * * 4. Use your main method as a client application to test the above by: * - constructing a Hero object called "shooter1" using the default constructor * print out its state using toString() * * - constructing a Hero object called "shooter2" using the default constructor: * directly increase its y position by 100, * change its body color to cyan, * print out its state using toString() * * - constructing a Hero object calls "shooter3" & "shooter4" using the custom constructors: * * shooter3 should have default size, body & engines, and be at (x,y)=(300,400) when instantiated * - modify shooter3 after creation, to give it gray engines * - print out shooter3 using toString() * * shooter4 should have default size and be at (x,y)=(580,340), and * have a magenta body, and pink engines when instantiated * - print out shooter4 using toString() */ } }

After running your main, you should have the following output: Hero e (0.0, 0.0): I width-50.0, height- 40.0 [ body- java . awt . Color [ r-o , g-o , b-o ] ] I engines- java.awt.color r-255,g-0, b- Hero e (0.0, 100.0): I width- 50.0, height- 40.0 I body- java.awt.Color[r-0,g-255,b-255] 1 I engines- java.awt.Color[r-255,g-0,b-0] Hero e (300.0, 400.0) width-50.0, height- 40.0 avaavat avolool oro.-128bg-128,b-128 [ engines- java . awt . Color [r-128 , g-128,b-128 Hero e (580.0, 340.0) I width- 50.0, height- 40.0 I body- java.awt.color[r-255,g-0, b-255] ] I engines- java.awt.Colorlr-255,g-175,b-175]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

Students also viewed these Databases questions