我有一個針對我的java編程課程的項目。實施演示/測試程序
指令是我們必須創建一個簡單的類和測試器類,並且該類必須包含一個Default構造函數;具有三個參數(品牌,型號和價格)的參數化構造函數;稱爲getMake()的Accessor方法返回make;稱爲getModel()的訪問器方法返回模型;訪問器方法getPrice()返回價格; Mutator方法setMake(String newMake)設置make; Mutator方法setModel(String newModel)設置模型;和一個Mutator方法setPrice(double newPrice)來設置價格。
我創建了我的課程和測試程序,並且我的課程完美編譯。 當我嘗試運行它時,雖然得到的錯誤是沒有主要方法。現在,我遵循我的教授的示例程序示例,並且發現了一些錯誤。如果有人能給我一個正確的方向指針,我將不勝感激。
我的問題是:我如何實現我的測試程序?我是否需要創建一個zip文件?我已經試過這樣做,似乎不幫助多...
以下是我的類代碼:
public class Automobile
{
private String make;
private String model;
private double price;
public Automobile()
{
make = "Lexus2017";
model = "RX";
}
public Automobile(String initMake, String initModel, double initPrice)
{
make = initMake;
model = initModel;
price = initPrice;
}
public String getMake()
{
return make;
}
public String getModel()
{
return model;
}
public double getPrice()
{
return price;
}
public void setMake(String newMake)
{
make = newMake;
}
public void setModel(String newModel)
{
model = newModel;
}
此外,以下是我的測試類(具有一個很多錯誤的):
public class AutomobileTester
{
public static void main(String[] args)
{
Automobile make = new Automobile("Lexus 2017");
System.out.println("The car is " + make.getMake());
Automobile model = new Automobile("RX");
System.out.println("The car is " + Automobile.getModel());
Automobile price = new Automobile("43020");
System.out.println("The car is " + Automobile.getPrice());
// Use the mutator to change the make variable
Automobile.setMake("Lexus 2017");
System.out.println("The car is " + backDoor.getState());
// Use the mutator to change the model variable
Automobile.setModel("RX");
System.out.println("The car is called " + backDoor.getName());
Automobile.setPrice("43020");
System.out.println("The car is " + price.getPrice());
}
}
這與建設者的工作我的第一次,我很新到Java,所以我現在沒有任何明顯的錯誤抱歉。提前感謝您的時間和幫助。
'參數化的構造函數與t hree參數(品牌,型號和價格);'不匹配'新汽車(「雷克薩斯2017」);' –
不要使用類名來訪問方法...這裏有很多錯誤。你是否期待我們解決所有問題併爲你完成任務? –
@ cricket_007不,那太荒謬了,我不會學到任何東西。我只想了解如何實施一堂課,因爲我已經三次閱讀了我的章節,聽了課堂筆記,還有一些沒有點擊我。我只是想把我的代碼放在上下文中。 –