Question

In: Computer Science

I was wondering is someone could tell me why my code isn't compiling - Java ------------------------------------------------------------------------------------------------------------...

I was wondering is someone could tell me why my code isn't compiling - Java

------------------------------------------------------------------------------------------------------------

class Robot{
int serialNumber;
boolean flies,autonomous,teleoperated;
public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){
this.serialNumber = serialNumber;
this.flies = flies;
this.autonomous = autonomous;
this.teleoperated = teleoperated;
}
public int getSerialNumber(){
return this.serialNumber;
}
public boolean canFly(){
return this.flies;
}
public boolean isAutonomous(){
return this.autonomous;
}
public boolean isTeleoperated(){
return this.teleoperated;
}
public String getCapabilities(){
StringBuilder str = new StringBuilder();
if(this.flies){str.append("canFly");str.append(" ");}
if(this.autonomous){str.append("autonomous");str.append(" ");}
if(this.teleoperated){str.append("teleoperated");}
return str.toString();
}
public String toString(){
return "ID: "+ this.serialNumber+", Capabilities: " + getCapabilities(this.flies,this.autonomous,this.teleoperated);
}
}

//Drone class

class Drone extends Robot{
public void Drone(int serialNumber){
this.serialNumber = serialNumber;
this.flies = true;
this.autonomous = false;
this.teleoperated = true;
}
public boolean canFly(){
return true;
}
public boolean isAutonomous(){
return false;
}
public boolean isTeleoperated(){
return true;
}
}

//Roomba class

class Roomba extends Robot{
boolean canClean = true;
public void Drone(int serialNumber){
this.serialNumber = serialNumber;
this.flies = false;
this.autonomous = true;
this.teleoperated = false;
canClean = true;
}
public boolean canClean(){
return true;
}
public boolean canFly(){
return false;
}
public boolean isAutonomous(){
return true;
}
public boolean isTeleoperated(){
return false;
}
public String getCapabilities(){
StringBuilder str=new StringBuilder();
if (this.flies){str.append("canFly");str.append(" ");}
if (this.autonomous){str.append("autonomous");str.append(" ");}
if (this.teleoperated){str.append("teleoperated");str.append(" ");}
if (this.canClean){str.append("canClean");}
return str.toString();
}
}

//MovieRobot class

class MovieRobot extends Robot{
String catchphrase;
public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated, String catchphrase){
this.serialNumber = serialNumber;
this.flies = flies;
this.autonomous = autonomous;
this.teleoperated = teleoperated;
this.catchphrase = catchphrase;
}
public boolean canFly(){
return this.flies;
}
public boolean isAutonomous(){
return this.autonomous;
}
public boolean isTeleoperated(){
return this.teleoperated;
}
public String canSpeak(){
return this.catchphrase;
}
public String getCapabilities(){
StringBuilder str = new StringBuilder();
if (this.flies){str.append("canFly"); str.append(" ");}
if (this.autonomous){str.append("autonomous"); str.append(" ");}
if (this.teleoperated){str.append("teleoperated"); str.append(" ");}
if (!(this.catchphrase).equals("")){str.append(catchphrase);}
return str.toString();
}
public String toString(){
return "ID: " + this.serialNumber + ", Capabilities: " + this.getCapabilities(this.flies, this.autonomous, this.teleoperated);
}
}

class HAL9000 extends MovieRobot{
String catchphrase="I can't let you do that Dave.";
}

class Terminator extends MovieRobot{
boolean canTimeTravel = true;
String catchphrase = "I'll be back.";
public void setCapabilities(boolean canTimeTravel, int serialNumber, boolean flies, boolean autonomous, boolean teleoperated, String catchphrase){
this.serialNumber = serialNumber;
this.flies = flies;
this.autonomous = autonomous;
this.teleoperated = teleoperated;
this.canTimeTravel = canTimeTravel;
this.catchphrase=catchphrase;
}
public boolean canTimeTravel(){
return this.canTimeTravel;
}
}

class WALL_E extends MovieRobot{
boolean canClean = true;
public void setCapabilities(boolean canClean, int serialNumber, boolean flies, boolean autonomous, boolean teleoperated){
this.serialNumber=serialNumber;
this.flies = flies;
this.autonomous = autonomous;
this.teleoperated = teleoperated;
this.canClean = canClean;
this.catchphrase = catchphrase;
}
public boolean canClean(){
return true;
}
}

Solutions

Expert Solution

Here is the solution to your question. I tried my best to solve your doubt, however, if you find it is not as good as expected by you. Please do write your further doubts regarding this question in the comment section, I will try to resolve your doubts regarding the submitted solution as soon as possible.

Please give proper indentation as shown in the screenshot

If you think, the solution provided by me is helpful to you please do an upvote.

Your code looks fine and it will get compiled if you change some code

1) In ToString() method of Robot.java , remove passed arguments of getCapabilities() as it does not require any parameter.

2) Simillarly in ToString() method of MovieRobot.java , remove passed arguments of getCapabilities() as it does not require any parameter.

Rest of the code is fine. Below is the code with proper changes that needs to be applied

class Robot {
  int serialNumber;
  boolean flies,
  autonomous,
  teleoperated;
  public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated) {
    this.serialNumber = serialNumber;
    this.flies = flies;
    this.autonomous = autonomous;
    this.teleoperated = teleoperated;
  }
  public int getSerialNumber() {
    return this.serialNumber;
  }
  public boolean canFly() {
    return this.flies;
  }
  public boolean isAutonomous() {
    return this.autonomous;
  }
  public boolean isTeleoperated() {
    return this.teleoperated;
  }
  public String getCapabilities() {
    StringBuilder str = new StringBuilder();
    if (this.flies) {
      str.append("canFly");
      str.append(" ");
    }
    if (this.autonomous) {
      str.append("autonomous");
      str.append(" ");
    }
    if (this.teleoperated) {
      str.append("teleoperated");
    }
    return str.toString();
  }
  public String toString() {
    return "ID: " + this.serialNumber + ", Capabilities: " + getCapabilities();
  }
}

//Drone class

class Drone extends Robot {
  public void Drone(int serialNumber) {
    this.serialNumber = serialNumber;
    this.flies = true;
    this.autonomous = false;
    this.teleoperated = true;
  }
  public boolean canFly() {
    return true;
  }
  public boolean isAutonomous() {
    return false;
  }
  public boolean isTeleoperated() {
    return true;
  }
}

//Roomba class

class Roomba extends Robot {
  boolean canClean = true;
  public void Drone(int serialNumber) {
    this.serialNumber = serialNumber;
    this.flies = false;
    this.autonomous = true;
    this.teleoperated = false;
    canClean = true;
  }
  public boolean canClean() {
    return true;
  }
  public boolean canFly() {
    return false;
  }
  public boolean isAutonomous() {
    return true;
  }
  public boolean isTeleoperated() {
    return false;
  }
  public String getCapabilities() {
    StringBuilder str = new StringBuilder();
    if (this.flies) {
      str.append("canFly");
      str.append(" ");
    }
    if (this.autonomous) {
      str.append("autonomous");
      str.append(" ");
    }
    if (this.teleoperated) {
      str.append("teleoperated");
      str.append(" ");
    }
    if (this.canClean) {
      str.append("canClean");
    }
    return str.toString();
  }
}

//MovieRobot class

class MovieRobot extends Robot {
  String catchphrase;
  public void setCapabilities(int serialNumber, boolean flies, boolean autonomous, boolean teleoperated, String catchphrase) {
    this.serialNumber = serialNumber;
    this.flies = flies;
    this.autonomous = autonomous;
    this.teleoperated = teleoperated;
    this.catchphrase = catchphrase;
  }
  public boolean canFly() {
    return this.flies;
  }
  public boolean isAutonomous() {
    return this.autonomous;
  }
  public boolean isTeleoperated() {
    return this.teleoperated;
  }
  public String canSpeak() {
    return this.catchphrase;
  }
  public String getCapabilities() {
    StringBuilder str = new StringBuilder();
    if (this.flies) {
      str.append("canFly");
      str.append(" ");
    }
    if (this.autonomous) {
      str.append("autonomous");
      str.append(" ");
    }
    if (this.teleoperated) {
      str.append("teleoperated");
      str.append(" ");
    }
    if (! (this.catchphrase).equals("")) {
      str.append(catchphrase);
    }
    return str.toString();
  }
  public String toString() {
    return "ID: " + this.serialNumber + ", Capabilities: " + this.getCapabilities();
  }
}

class HAL9000 extends MovieRobot {
  String catchphrase = "I can't let you do that Dave.";
}

class Terminator extends MovieRobot {
  boolean canTimeTravel = true;
  String catchphrase = "I'll be back.";
  public void setCapabilities(boolean canTimeTravel, int serialNumber, boolean flies, boolean autonomous, boolean teleoperated, String catchphrase) {
    this.serialNumber = serialNumber;
    this.flies = flies;
    this.autonomous = autonomous;
    this.teleoperated = teleoperated;
    this.canTimeTravel = canTimeTravel;
    this.catchphrase = catchphrase;
  }
  public boolean canTimeTravel() {
    return this.canTimeTravel;
  }
}

class WALL_E extends MovieRobot {
  boolean canClean = true;
  public void setCapabilities(boolean canClean, int serialNumber, boolean flies, boolean autonomous, boolean teleoperated) {
    this.serialNumber = serialNumber;
    this.flies = flies;
    this.autonomous = autonomous;
    this.teleoperated = teleoperated;
    this.canClean = canClean;
    this.catchphrase = catchphrase;
  }
  public boolean canClean() {
    return true;
  }
}

Related Solutions

I was wondering why my merger class isn't compiling - Java -------------------------------------------------------------------------------------------------------------------- public class Person{ private...
I was wondering why my merger class isn't compiling - Java -------------------------------------------------------------------------------------------------------------------- public class Person{ private String firstName; private String lastName; private int age; private String email; private String phone; private String address;       public Person(String firstName, String lastName, int age, String email, String phone, String address){ setFirstName(firstName); setLastName(lastName); setAge(age); setEmail(email); setPhone(phone); setAddress(address); } public Person(String firstName, String lastName, String email){ setFirstName(firstName); setLastName(lastName); setEmail(email); }    public String getFirstName(){ return firstName; }    public String getLastName(){ return lastName; }...
Can you please tell me why my code isn't working? It won't calculate the values I...
Can you please tell me why my code isn't working? It won't calculate the values I have using my input file. /******************************************************************************* AUTHOR SECTION ENGR 200.07 DATE: 10/23/2020 PROGRAM: ******************************************************************************** PROGRAM DESCRIPTION This program takes a pre-made .txt file’s input values, and calculates the kinetic energy wind farms produce from moving air into electrical energy. Using 3 different formulas this program calculates the available power in the wind, the maximum available power that can be produced, and the amount of...
I was wondering if you can tell me if the following code is correct and if...
I was wondering if you can tell me if the following code is correct and if its not can it be fixed so it does not have any syntax errors. Client one /** * Maintains information on an insurance client. * * @author Doyt Perry/<add your name here> * @version Fall 2019 */ public class Client { // instance variables private String lastName; private String firstName; private int age; private int height; private int weight; /** * First constructor for...
Can someone tell me how to fix warning msg in my code of C ++? I...
Can someone tell me how to fix warning msg in my code of C ++? I got run-time error for this question please help me asap! Errors are: In function 'void bfs(int, int)': warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int j = 0; j < adj[pppp].size(); j++){ ^ In function 'int main()': warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %d %d %d", &a, &q, &c, &N, &m); ^...
Hello, I was wondering if someone could show me the process as to how to answer...
Hello, I was wondering if someone could show me the process as to how to answer this question. The answers were posted by the teacher assistant however I do not actually know how to solve the question: The production function of a firm is given as ? =K 1/2, L1/2 , capital is 200. The rental rate for both labor and capital is 5 and 20. There are total 20 firms that produce the same good. A. Write down the...
Hello, I was wondering if you could tell me how to do a general Ledger? I...
Hello, I was wondering if you could tell me how to do a general Ledger? I just finish doing a Sales Journal, Purchase Journal, Cash Receipt Journal, Cash Disbursements Journal and a General Journal under one company Sound Bytes Electronics). What I wanted to know is do I use the General Journal to do the General Ledger? Or do I use the Special Journals and the General Journal to do the General Ledger? Can you put me in the right...
Could someone please tell me what corrections I should make to this code. (Python) Here are...
Could someone please tell me what corrections I should make to this code. (Python) Here are the instructions. Modify the program so it contains four columns: name, year, price and rating (G,PG,R…) Enhance the program so it provides a find by rating function that lists all of the movies that have a specified rating I can't get the find function to work and I have no idea how to even go about it. For example, when type in 'find' and...
I need to fix this code, and could you please tell me what was the problem...
I need to fix this code, and could you please tell me what was the problem options 1 and 9 don't work #include <stdio.h> #include <time.h> #include <stdlib.h> // generate a random integer between lower and upper values int GenerateRandomInt(int lower, int upper){     int num =(rand()% (upper - lower+1))+lower;     return num; } // use random numbers to set the values of the matrix void InitializeMatrix(int row, int column, int dimension, int mat[][dimension]){     for(int i =0; i<row; i++){...
Can someone look into my code and tell me what do you think: Thats Palindrome; //class...
Can someone look into my code and tell me what do you think: Thats Palindrome; //class name Palindrome public class Palindrome {    public static void palindromeChecker(String... str) {        // takes string one by one        for (String s : str) {            // creates a stringbuilder for s            StringBuilder sb = new StringBuilder(s);            // reverses the sb            sb.reverse();            // checks if both...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT