Question: 1 . Create a new Java class called Droid in the space package. 2 . Create the instance variables and constructor for Droid based on
Create a new Java class called Droid in the space package.
Create the instance variables and constructor for Droid based on the fact that droids have a
name, a class, a size, and a direction that they are facing.
Use a variable of boolean type to store the direction a Droid faces.
The class of your Droid should be a static final String variable describing the kind of
droid you have modeled. The value of this variable should be the same for all instances
of your Droid class. You are welcome to make up the class, if you are unfamiliar with
kinds of droids from pop culture.
Think about what data types make sense to use for the other variables. Remember that the
purpose of a constructor is to initialize the instance variables.
Add a toString method to your Droid class that returns a string containing the aliens name,
class, size, and direction labeled nicely
Elizabeth Wilcox Reproduction prohibited without author consent
CSCSC Programming Challenge #Fall
Add a getterfor each variable, including class.
Remember that classes are developed, not written, so create a Java main class file to test
your Droid class. There is a skeleton at the bottom of this assignment to use. Instantiate
several instances of your Droid class at least with different values for the variables and
test that the toString and getter methods work as they should.
In the Droid class, write a couldCollide method that takes a second Droid as its parameter
and returns true if the input Droid is facing the opposite direction of the Droid calling the
method, false otherwise.
Now add to the testing skeleton, testing whether or not your couldCollide method works
as it should. If it does not, go back and tweak until you are satisfied and the testing skeleton
demonstrates the correctness of the programming for the couldCollide method.
We now wish to paint our droidss. Add another instance variable to your Droid class for
color, and initialize it with a random color at the appropriate point in your code.
Add a method called paint to your Droid class that takes an SPainter for a parameter.
In this method, paint your droid. Make use of the defined size and direction variables. You
use SCircles, SRectangles, SSquares, or even SPolygons for drawing your droids. Use
your imagination your droid doesnt have to look like any of mine or even one from Star
Wars! Be sure to use good practices with regards to problem decomposition and
invariance.
Test your Droid class by enhancing your tests from before. Youll need to make an SPainter
to pass to the Droids paint method. Iterate on your design until you are happy with itThe Droid Testing Skeleton
package space ;
import painter SPainter ;
import javax swing SwingUtilities ;
public class DroidTester
public DroidTester
Create some Droid instances to test with
use the example image to see what the output should be similar to
public static void main String args
SwingUtilities invokeLater new Runnable
public void run
new DroidTester ;
;
use the image as an example of what the output should be similar to using the Sshape types refer
ed make an image similar while following the given guidlines
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
