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; }...
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)     {        ...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my...
Can someone please tell me if these calculations are correct! I'm reviewing my notes, and my professor said to always multiply the lipids by 3 and then divide by 7 to get the total amount of cals of lipids per day... I'm not completely sure why you do that? Can someone explain. Why don't you just stop at 700 cals for lipids? 1. Calculate the number of calories and grams protein for the following TPN solution: D50W in 500cc 10%...
why isn't my question completely answered? every time I post it someone only answers the first...
why isn't my question completely answered? every time I post it someone only answers the first part? I provide all the information that's needed
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT