Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA HW) In the submarine class, over-load the turnOn and turnOff methods, so that the method can receive a time integer. This is my code

(JAVA HW) In the submarine class, over-load the turnOn and turnOff methods, so that the method can receive a time integer.

This is my code so far:

public class Vehicle {

//attributes

String color;

String model;

//constructor

public Vehicle(String color, String model) {

super();

this.color = color;

this.model = model;

}

//methods

public void turnOn(){

System.out.println("The vehicle has been turned on");

}

public void turnOff(){

System.out.println("The vehicle has been turned off");

}

}

public class Submarine extends Vehicle {

//attributes

int maxLoad;

int maxDepth;

//constructor

public Submarine(String color, String model, int maxLoad, int maxDepth){

super(color,model);

this.maxLoad = maxLoad;

this.maxDepth = maxDepth;

}

//methods

public void turnOn(int time){

System.out.println(model + " will be turned on in "+time+" minutes");

}

public void turnOff(int time){

System.out.println(model + " will be turned off in"+time+" minutes");

}

public void descend(){

System.out.println(model+" has descended");

}

public void useRadar(){

System.out.println(model+" has used the radar");

}

}

but i get this error when i test it out:

public class Main{

public static void main(String[] args){

Vehicle c1 = new Submarine("red","toyota",2,4);

c1.turnOn(5);

}

}

Main.java:5: error: method turnOn in class Vehicle cannot be applied to given types; c1.turnOn(5); ^ required: no arguments found: int reason: actual and formal argument lists differ in length 1 error

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

Step: 3

blur-text-image

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

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions

Question

Question How are IRAs treated for state tax law purposes?

Answered: 1 week ago