所以基本上我想做的是让用户通过car.setxxxx(scan.nextLine());
行输入变量,但是有一个错误:TestVehicle.java:21:错误:类Vehicle中的方法setModel无法应用给定类型;car.setModel(scan.nextLine());^必填:无参数找到:字符串原因:实际参数和正式参数列表的长度不同知道为什么会这样吗?
主要方法:
import java.util.Scanner;
public class TestVehicle{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
Vehicle car = new Vehicle();
System.out.print("Input name: ");
car.setName(scan.nextLine());
System.out.print("Input model: ");
car.setModel(scan.nextLine());
车辆类别:
public class Vehicle {
private String name;
private String model;
public Vehicle(){
}
public Vehicle(String name, String model){
this.name = name;
this.model = model;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getModel(){
return model;
}
public void setModel(){
this.model = model;
public void setModel(String modelName) {
this.model = model;
}