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: エラー: 予想される public AutomobileDescription(String carMake, String carModel, carPrice) ^ 1 エラー

----jGRASP wedge2: プロセスの終了コードは 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ステートメントは、次の 2 つのステートメントに到達できないことを意味し、最初の問題を修正するとコンパイル エラーが発生します。

于 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 に答える