gpt4 book ai didi

java - 尝试实现一个类

转载 作者:行者123 更新时间:2023-12-02 07:18:04 25 4
gpt4 key购买 nike

我试图获得有关运行我的汽车编译器的帮助,我改变了一些东西,但有 1 个错误

public class AutomobileDescription
{
/**
Constructor to display the make, model and price the new automobile I wish to purchase
*/

public AutomobileDescription(String carMake, String carModel, carPrice)
{
make = m;
model = mo;
price = p;
}
public String m =("Toyota");
public String mo =("Camry");
public String p =("22055");

public String getAutomobileinfo()
{
return m + mo + p;
Automobile myAutomobile = new Automobile(Toyota, Camry, 22055);
System.out.println("The Make, Model and Price of the car is: m + mo + p ");

}
}

----jGRASP 执行:javac -g AutomobileDescription.java

AutomobileDescription.java:7:错误:预期 公共(public)汽车描述(字符串 carMake,字符串 carModel,carPrice) ^1 个错误

----jGRASP wedge2:进程的退出代码为 1。 ----jGRASP:操作完成。

最佳答案

您在这里遇到多个问题:

public class AutomobileDescription
{
/**
Constructor to display the make, model and price the new automobile I wish to purchase
*/

public AutomobileDescription(String carMake, String carModel, /*no return type*/ carPrice)
{
make = m;
model = mo;
price = p;
}
public String m =("Toyota");
public String mo =("Camry");
public String p =("22055");

public String getAutomobileinfo()
{
return m + mo + p; /*return? then why statements after this?*/
Automobile myAutomobile = new Automobile(Toyota, Camry, 22055);
System.out.println("The Make, Model and Price of the car is: m + mo + p ");

}
}

解决方案:

public class AutomobileDescription{ 
/**
Constructor to display the make, model and price the new automobile I wish to purchase
*/

public AutomobileDescription(String carMake, String carModel, String carPrice)
{
m = make;
mo = model;
p = carPrice;
}
private String m;
private String mo;
private String p;

public String getAutomobileinfo()
{
return m + mo + p;
}
public static void main(String[] args){
AutomobileDescription myAutomobile = new AutomobileDescription("Toyota", "Camry", "22055");
System.out.println("The Make, Model and Price of the car is: " + myAutomobile.getAutomobileinfo());
}
}

关于java - 尝试实现一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14669513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com