Question: Create a new Java class called Droid in the space package. 2 . Create the instance variables and constructor for Droid based on the fact

Create a new Java class called Droid in the space package.
2. 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.
3. Add a toString method to your Droid class that returns a string containing the aliens name,
class, size, and direction (labeled nicely).
2024 Elizabeth Wilcox Reproduction prohibited without author consent 1
CS1(CSC 212) Programming Challenge #7 Fall 2024
4. Add a getter for each variable, including class.
5. 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 3!) with different values for the variables and
test that the toString and getter methods work as they should.
6. 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.
7. 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.
8. 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.
9. 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
may 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.
10. 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 it. The Droid Testing Skeleton
1 package space ;
2
3 import painter . SPainter ;
4 import javax . swing . SwingUtilities ;
5
6 public class DroidTester {
7
8 public DroidTester (){
9// Create some Droid instances to test with !
10}
11
12 public static void main ( String [] args ){
13 SwingUtilities . invokeLater ( new Runnable (){
14 public void run (){
15 new DroidTester () ;
16}
17}) ;
18}
19}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!