Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help public class Main { public static void main(String[] args) { // you can use this to test your code String line1 = You

please help

image text in transcribed

public class Main { public static void main(String[] args) { // you can use this to test your code String line1 = "You ain't nothin' but a hound dog, cryin' all the time"; String line2 = "Well, you ain't never caught no rabbit and you ain't no friend of mine"; String line3 = "Ah thank you, ah thank you very much"; String line4 = "Initiate Judgement Day"; // this is how RobotBouncer will be used // these errors should disappear eventually RobotBouncer rb = new RobotBouncer(line1, line2, line3); Robot r1 = new Robot("One", null, line1); Robot r2 = new Robot("Two", r1, line2); Robot r3 = new Robot("Three", r2, line3); Robot r4 = new Robot("skynet", r3, line4); r1.makeNewFriend(r4); System.out.println(r1.speak()); System.out.println(r1.friendSpeak()); System.out.println(r2.speak()); System.out.println(r2.friendSpeak()); System.out.println(r3.speak()); System.out.println(r3.friendSpeak()); System.out.println(r4.speak()); System.out.println(r4.friendSpeak()); // fixing robots r1 = rb.fixRobot(r1); r2 = rb.fixRobot(r2); r3 = rb.fixRobot(r3); r4 = rb.fixRobot(r4); // should have no bad Robots here System.out.println("~~~~~~~~~~~~~~~~~~~~~"); System.out.println(r1.speak()); System.out.println(r1.friendSpeak()); System.out.println(r2.speak()); System.out.println(r2.friendSpeak()); System.out.println(r3.speak()); System.out.println(r3.friendSpeak()); System.out.println(r4.speak()); System.out.println(r4.friendSpeak()); } }
Problem 5.1- Uh oh, we have an imposter robot masquerading as one of our Robots. We need a bouncer to only allow the Robots on the guest list' in. To do this, we will create a RobotBouncer class that will ask every Robot for its line before it is allowed to proceed. The RobotBouncer will fix any Robots saying scary things. The specifications for the RobotBouncer class are as follows: 1. A RobotBouncer has three attributes: String linol, String linc2, String lines. These are the accepted lines, and they should be provided via a single constructor (i.e. RobotBouncer has only one constructor). 2. RobotBouncer has a method called tixrobot() . This method takes a single parameter of type Robot: the Robot being tested, and possibly fixed. This method should check if the Robot's line is equal to any of the accepted lines. o If the Robot being tested has a friend (ie the friend != null), fixkobot O must also check the friend Robot's line o If the Robot and the Eriond pass, the method returns the original Robot. o If the Robot passes and its friend fails, the friend should be removed as a friend from the original Robot by setting the attribute to null o If the original Robot fails, a new Robot must be made: Give the new Robot an acceptable line (i.e. either line 1/2/3). You can choose this arbitrarily. The new Robot should have its original name with a " - fixed" tagged on. For example, if the deviant Robot named "skynet", the new Robot should be named "skynet - fixed". The new Robot must still have the original Robot's friend. However, fixkubul() must check this Robot's line as well. If the original Robot's friend's line is not acceptable, the new Robot's friend attribute should be set to null as previously stated. o In a nutshell, bad Robots should have all references to them removed. And good Robots should remain completely unchanged, with the exception of the friend attribute if the friond is a bad Robot. Hint 1 You must check if two Strings are equal using the equals() method. stringl.equals(string) => true/talze. Hint 2 You will need to define some more accessor methods for Robot in Robot.java

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_2

Step: 3

blur-text-image_3

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago