Robot.javapublic class Robot {private final int serialNumber;private boolean flies;private boolean autonomous;private boolean teleoperated;/*** @param serialNumber* @param...

Hi I have my code written out already for this project and need assistance to fix the compilation errors and test it against the tester to see if it passes the 9 test cases.


Robot.java public class Robot { private final int serialNumber; private boolean flies; private boolean autonomous; private boolean teleoperated; /** * @param serialNumber * @param flies * @param autonomous * @param teleoperated */ public Robot(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated) { //super(); this.serialNumber = serialNumber; this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } public void setCapabilities (boolean flies, boolean autonomous, boolean teleoperated) { this.flies = flies; this.autonomous = autonomous; this.teleoperated = teleoperated; } /** * @return the serialNumber */ public int getSerialNumber() { return serialNumber; } public boolean canFly() { return flies; } /** * @return the autonomous */ public boolean isAutonomous() { return autonomous; } /** * @return the teleoperated */ public boolean isTeleoperated() { return teleoperated; } public String getCapabilities () { String str=(canFly()?"canFly":"")+(isAutonomous()?" isAutonomous":"")+(isTeleoperated()?" isTeleoperated":""); return str; } @Override public String toString() { return "ID: "+serialNumber+", Capabilities: "+getCapabilities(); } } Drone.java public class Drone extends Robot{ public Drone(int serialNumber) { super(serialNumber, true, false, true); } } Vacuum.java public class Vacuum extends Robot { public Vacuum(int serialNumber) { super(serialNumber, false, true, false); } public boolean canClean() { return true; } @Override public String getCapabilities () { String str=super.getCapabilities()+(canClean()?" can clean":""); return str; } } MovieRobot.java public abstract class MovieRobot extends Robot { protected String catchphrase; /** * @param serialNumber * @param flies * @param autonomous * @param teleoperated * @param catchphrase */ public MovieRobot(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated, String catchphrase) { super(serialNumber, flies, autonomous, teleoperated); this.catchphrase = catchphrase; } /** * @param serialNumber * @param flies * @param autonomous * @param teleoperated * @param catchphrase */ public MovieRobot(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated) { this(serialNumber, flies, autonomous, teleoperated, null); } public abstract boolean canSpeak(); @Override public String getCapabilities () { String str=super.getCapabilities()+(canSpeak()?" can speak":""); return str; } @Override public String toString() { return super.toString()+(canFly()?"\'"+catchphrase+"\'":""); } } HAL9000.java public class HAL9000 extends MovieRobot { public HAL9000(int serialNumber, boolean autonomous, boolean teleoperated) { super(serialNumber, true, autonomous, teleoperated, "I can't let you do that Dave."); } @Override public boolean canSpeak() { if(super.catchphrase!=null) return true; return false; } } ModelB9.java public class ModelB9 extends MovieRobot{ public ModelB9(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated) { super(serialNumber, flies, autonomous, teleoperated, "Danger, Will Robinson!"); } @Override public String getCapabilities () { String str=super.getCapabilities()+" can flail"; return str; } @Override public boolean canSpeak() { if(super.catchphrase!=null) return true; return false; } //@Override public boolean canFlail() { return true; } } WALL_E.java public class WALL_E extends MovieRobot{ public WALL_E(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated) { super(serialNumber, flies, autonomous, teleoperated); } @Override public boolean canSpeak() { return false; } @Override public String getCapabilities () { String str=super.getCapabilities()+" can clean"; return str; } } Overview: 1. Define a base class named Robot, used to define the capabilities of various types of robots. 2. Derive classes Drone, Vacuum, and MovieRobot each of which describe a specific type of robot, and which redefine certain Robot behaviors appropriately. 3. Derive more specific MovieRobot classes called HAL9000, ModelB9, and WALL_E which each have different capabilities. 4. Download and use a tester module to ensure that your programs are correct. The programs can also be tested using Dr Java's interactive window. Robot Class The term "robot" (at least in popular usage) can refer to a very broad category of things, and yet there is a common image that we often have in mind when discussing robots in general: machines that interact with the world. Usually, we categorize different types of robots based on their capabilities. Let's create a general class that identifies some common capabilities that different robots might have, with the possibility that new capabilities might be added in the future. The Robot class we are about to write will be a general class which we can use to describe any type of robot - we won't worry about the specifics yet, and instead we'll use subclasses to describe those. Our Robot class will include the following: · A constructor, with the parameters int serialNumber, boolean flies, boolean autonomous, boolean teleoperated. The serialNumber is a number which uniquely identifies the robot, while the remaining parameters all represent different capabilities a robot can have: if flies is true, the robot can move through the air, autonomous is true when the robot can act on its own without a human operator, and teleoperated indicates whether a human can operate the robot manually. · A void method called setCapabilities for setting the capabilities after object creation with the parameter list boolean flies, boolean autonomous, boolean teleoperated. · A getter called getSerialNumber for the serialNumber. We do not need a setter because we do not expect to change the serial number after it is set (it may even make sense to declare the method and the corresponding field final). · Methods canFly, isAutonomous, and isTeleoperated, each of which take no parameters and return boolean. These method indicate which capabilities the robot supports. They may be redefined in subclasses, but for now, each of these methods should return whatever the capabilities were set to. · A getCapabilities method that takes no parameters and which returns a String containing each of the capabilities of the robot separated by spaces. For example, if canFly returns true, isAutonomous returns false, and isTeleoperated returns true, then getCapabilities should return the string "canFly isTeleoperated" (order and case are important). If all three returned true the string should be "canFly isAutonomous isTeleoperated". If none of them return true, the empty string should be returned (""). NOTE: in order for this method to work correctly for subclasses, you should use the previously defined canFly, isAutonomous, and isTeleoperated methods rather than access any data members directly. · A toString method which returns a String in the format "ID: , Capabilities: " (replacing with actual serial number and list of capabilities). Drone Class Our simplest type of robot will represent a drone. Even though many different types of drones exist, they all have the same basic functionality, at least for the purposes of this project. All drones can fly, are teleoperated and not autonomous. To implement this subclass, we need to define the following: · Extend the Robot class. · An overloaded constructor with just a single parameter: int serialNumber. · An overridden canFly method which always returns true. · An overridden isAutonomous method which always returns false. · An overridden isTeleoperated method which always returns true. NOTE: this class does not define or override the getCapabilities method, but it is still inherited by this subclass, and it should still give the correct output when on instances of this subclass. If you've followed the note above, this will be the case. Vacuum Class Our next type of robot is the humble vacuum, a consumer product which autonomously vacuums your house. All vacuums have the same basic capabilities: they can't fly or be teleoperated, but they are autonomous, and they also have the ability to clean. To implement this subclass, we need to define the following: · Extend the Robot class. · An overloaded constructor with just a single parameter: int serialNumber. · A new method, canClean which takes no arguments and returns true. · An overridden getCapabilities method which returns a string in the same format as the parent class Robot, but with the additional canClean capability at the end. · Overridden versions of each of three boolean methods from the parent class, as was done for the Drone class. MovieRobot Class In addition to robots that exist in the real world, there is a rich (if not technically accurate) history of robots in film. The capabilities of these robots vary widely from film to film, so unlike the previous two subclasses we won't "hard code" the capabilities, but we will introduce a new capability that most movie robots have: speech. Invariably, whenever a MovieRobot is capable of speech it will have a catchphrase, so we'll store that in our class as well. Lastly, since there are no examples of generic MovieRobots - only robots from specific movies - we'll make MovieRobot an abstract class. · Extend the Robot class. · An overloaded constructor with the parameters int serialNumber, boolean flies, boolean autonomous, boolean teleoperated, String catchphrase. Note: you can use the parent class' constructor to set the other capabilities first, and then set the robots catchphrase. · An overloaded four argument constructor which by default sets the catchphrase to null. Note: if you followed the previous note, you can chain constructors to accomplish this in one line. · Add a new abstract method, canSpeak which takes no arguments and returns a boolean. The subclasses of MovieRobot will need to make sure this method returns true when they have a non-null catchphrase. · An overridden getCapabilities method which returns a string in the same format as the parent class Robot, but with the additional canSpeak capability at the end (if true). · An overridden toString method which returns a string in the same format as the parent class Robot, and if the robot can speak appends a space followed by the catchphrase surrounded by quotation marks. (If the robot cannot speak, nothing should be appended) MovieRobot Subclasses Once we've made a subclass, we can keep building off of it by making new classes which derive from the subclass. We'll create three subclasses of MovieRobots from iconic films (all three of these classes should be concrete): · A HAL9000 subclass which extends MovieRobot, which flies and has the catchphrase "I can't let you do that Dave." · A ModelB9 subclass which extends MovieRobot, which has the catchphrase "Danger, Will Robinson!" and the additional capability flail. · A WALL_E subclass which extends MovieRobot, which cannot speak, but can also clean. For each of these subclasses, make sure you override and add methods where appropriate, as you did in the previous subclasses. The easiest way to make sure the catchphrase for each subclass is correct is by overriding (not overloading) the MovieRobot constructor. Testing: Download the following (if you don't already have it): · junit-cs211.jar · P3Tester.java This is a unit tester that you can use to test to see if your classes are working correctly. Note that the autograder which is used to evaluate your submission for a grade will include additional tests, and your code will be manually inspected to ensure compliance with all of the class and assignment guidelines. When you think your classes are ready (you can try them even without the tester), do the following from the command prompt to run the tests. On Windows: javac -cp .;junit-cs211.jar *.java java -cp .;junit-cs211.jar P3Tester On Mac or Linux: javac -cp .:junit-cs211.jar *.java java -cp .:junit-cs211.jar P3Tester In Dr Java: · open the files, including P3Tester.java, and click the Test button. In Eclipse: · create a new JUnitTest Case (File --> New --> JUnit TestCase) · Name it P3Tester · Copy/paste the content of P3Tester.java in the new file · Save the file · Right click on the P3Tester.java on the Package explorer · Chose Run As -->JUnit Test I have my code written already and I’ve posted my code below. I posted the file for the tester below and I need to see if my code passes the tester Can you please help me with it?
Oct 12, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here