Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4. (16 pts) You have been asked to write the preliminary code for a spaceship for a game. Write the code for a class named

image text in transcribed
4. (16 pts) You have been asked to write the preliminary code for a spaceship for a game. Write the code for a class named SpaceShip with the following parts: a) 3 properties: an int named speed, an int named direction that tells what direction the spaceship is heading in (from-360 to 360 degrees-hint: you can use remainder division (%) by 360 to keep in this range), and a String named spaceShipName with a default value of "Command Ship" b) a no-arg constructor to create a generic spaceship c) a constructor to create a new spaceship with a specific name, speed, and direction d) a method to turn spaceship right (change direction by 5) and a method to turn left (change direction by 5 in other direction) e) a method to accelerate spaceship (increase speed by 10) and a method to decelerate (decrease speed by 10) f) a method to fire blasters, which just prints "Bang!" on screen 5 (8 pts) Write a public class named SpaceShipTestClass to test the SpaceShip class you created above. The SpaceShipTestClass should: a) b) c) d) e) Contain a main method (same as we've used since chapter 1) Create a new SpaceShip using the class you created above (you can choose spaceship name) Accelerate the spaceship you just created Print on the screen the speed of your spaceship Fire blasters on your spaceship using method previously created

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

Bachelors degree in Information Systems or Statistics

Answered: 1 week ago