Java 试图实现一个类
我试图得到帮助,以运行我的汽车编译器我改变了一些事情,我有一个错误Java 试图实现一个类,java,Java,我试图得到帮助,以运行我的汽车编译器我改变了一些事情,我有一个错误 public class AutomobileDescription { /** Constructor to display the make, model and price the new automobile I wish to purchase */ public AutomobileDescription(String carMake, String carModel, carPri
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 exec:javac-g AutomobileDescription.java
AutomobileDescription.java:7:错误:应为
公共汽车说明(字符串carMake、字符串carModel、carPrice)
^
1错误
----jGRASP楔形2:进程的退出代码为1。
----jGRASP:操作已完成。这不是有效的方法名称:
public String getMake + getModel + getPrice;
解决这个问题。如果您仍然有问题,请更详细一点。甚至可以发布错误消息
public AutomobileDescription(String carMake, String carModel, carPrice)
^^^^^^^^
您省略了参数的类型carPrice
。很可能是你想要的
public AutomobileDescription(String carMake, String carModel, BigDecimal carPrice)
另一个问题
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 ");
}
return
语句意味着永远无法访问以下两条语句,在纠正第一个问题后,这将导致编译错误。您在这里遇到多个问题:
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());
}
}
方法应该有名称,只能有字母、数字或下划线。此外,您必须提供
getMake
、getModel
和getPrice
的实现。是的,我有一个问题,我可以让它返回3个变种和实例老实说,它确实显示了一点。至于我的答案,方法名不能有这样的符号。你可以说public String getAllDetails{
,这应该行得通。但这并不意味着这里没有更多的错误。如果你看到Automobile(丰田,凯美瑞,22055)
也有问题。什么是汽车?什么是丰田,什么是凯美瑞?22055不是一个字符串。OP似乎完全不知道他在干什么。你和我同时在写我们的答案。检查时间戳。然后,吉姆,你和我应该得到+1Cool@shepcleveland-获得一本关于Java的好书:-)…然后慢慢来。