Question: (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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!