0

我试图获得帮助以使用我的汽车编译器运行我改变了一些东西并且我有 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 exec: javac -g AutomobileDescription.java

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

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

4

3 回答 3

1
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语句意味着永远无法达到以下两个语句,这将导致您更正第一个问题后编译错误。

于 2013-02-03T05:20:59.310 回答
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, /*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()); 
 }
}
于 2013-02-03T05:21:21.560 回答
0

这不是有效的方法名称:

public String getMake + getModel + getPrice;

修复它。如果您仍然有问题,请更详细一点。甚至可能发布错误消息!

于 2013-02-03T04:35:47.437 回答