我正在NetBeans中爲java類編寫此代碼,但我遇到了一些錯誤,非常感謝您的幫助。分配是:使用下列準則實施絃樂器類在java代碼中非法表達
設計:
您的儀器數據字段應包含字符串的數字,代表字符串名稱字符串名稱的陣列(例如E, A,D,G)和布爾字段來確定樂器是否已調諧,以及樂器是否正在播放。如果您願意,歡迎您添加其他數據字段。
一個構造函數方法,將已調整和當前正在播放的字段設置爲false。 其他方法
- 給樂器調音
- 開始樂器演奏,並
- 以停止播放儀器。 您認爲合適的其他方法(添加至少一種獨特方法)。
使用您選擇的圖表工具(例如PPT,Visio)創建UML類圖。準備圖表並將它們放在一個word文檔中,並附上每個類的簡要說明。
爲您的儀器創建Java類。確保你的代碼符合你的設計規範,並且包含一些最小的功能。例如,如果您調用了violin.play()方法,則至少應打印出小提琴正在播放。當您停止播放,調整或調用您的任何方法時,應該提供類似的功能。例如:
public void playviolin() {
System.out.println("The violin is now playing.");
}
寫從您的儀器類的方法,以使用戶在命令行參數(例如,Java Mynamep3tst myfilename.txt)進入了一個文本文件的輸出。這允許您的程序通過命令行參數接受來自用戶的文件名。
最後,創建一個模擬使用您的儀器類的Java測試類。在你的測試課上,你應該至少:a)構建你的樂器的10個實例,b)調整你的樂器,c)開始演奏樂器,d)調用你獨特的方法,e)停止演奏你的樂器。 (提示:數組和循環將使您的工作更輕鬆,並導致更有效的代碼!)
因此,這裏是目前我的代碼:
package andrewrubinfinalproject;
/**
*
* @author Andy
*/
public class AndrewRubinFinalProject {
public static void main(String[] args) {
//fields to determine if the instrument is isTuned,
private boolean isTuned;
//and if the instrument is currently isPlaying.
private boolean isPlaying;
private String name;
private int numberOfStrings = 4; // number of strings
private String nameofStringsInInstrument[] = {"E", "C", "D", "A"}; //an array of string names
//A constructor method that set the isTuned and currently isPlaying fields to false.
public AndrewRubinFinalProject() {
this.isTuned = false;
this.isPlaying = false;
}
public String getNameOfInstrument() {
return name;
}
public void setNameOfInstrument(String nameOfInstrument) {
this.name = nameOfInstrument;
}
// Other methods
public boolean isPlaying() {
return isPlaying;
}
public void setPlaying(boolean playing) {
this.isPlaying = playing;
}
public boolean isTuned() {
return isTuned;
}
public void setTuned(boolean isTuned) {
this.isTuned = isTuned;
}
public void startPlayInstrument() {
System.out.println("The Instrument is now Playing.");
isPlaying = true;
}
public void stopPlayInstrument() {
System.out.println("The Instrument is not Playing anymore.");
isPlaying = false;
}
public void startTuneInstrument() {
System.out.println("The Instrument is Tuned.");
isTuned = true;
}
public void stopTuneInstrument() {
System.out.println("The Instrument is not Tuned.");
isTuned = false;
}
public int getNumberOfStrings() {
return this.numberOfStrings ;
}
public String[] getStringNames() {
return nameofStringsInInstrument;
}
}
這就像你把你的整個任務放在這裏:)你的問題是怎麼回事? –
+1爲我讀過的最無意義的標題! – tilpner
*「一些錯誤」*總是複製/粘貼錯誤和異常輸出。 –