我在嘗試將構造函數方法中指定的String
和String[]
保存到數組中然後將其打印出來時遇到問題。 該計劃背後的想法是添加一個人的塗鴉程序與他們的名字和他們的答案(在voegDeelnameToe
),然後打印出所有信息槽geefPollInfo()
。Java:從數組中的方法保存指定的字符串
我試圖加6人線槽voegDeelnameToe()方法,但我不能保存
String deelnemer
(=字符串 '參與者的名字')
和
String[] aanwezigheden
(=的String []「答案')
在另一個對象中,然後將其打印出來。
doodle.voegDeelnameToe("Bram",new String[]{"ja", "ja", "nee", "ja", "ja", "nee", "ja", "ja", "ja", "nee", "nee", "nee", "ja", "ja", "ja"});
doodle.voegDeelnameToe("Katja", new String[]{"nee", "nee", "ja", "nee", "nee", "nee", "ja", "nee", "ja", "ja", "nee", "ja", "ja", "nee", "ja"});
doodle.voegDeelnameToe("Kristien", new String[]{"ja", "ja", "ja", "ja", "nee", "nee", "nee", "nee", "nee", "ja", "nee", "ja", "ja", "nee", "ja"});
doodle.voegDeelnameToe("Peter", new String[]{"ja", "nee", "ja", "ja", "nee", "nee", "nee", "nee", "nee", "ja", "nee", "ja", "ja", "nee", "ja"});
doodle.voegDeelnameToe("Sven", new String[]{"nee", "nee", "ja", "ja", "nee", "nee", "nee", "nee", "nee", "ja", "nee", "ja", "ja", "ja", "ja"});
doodle.voegDeelnameToe("Matthias", new String[]{"ja", "ja", "ja", "ja", "nee", "ja", "nee", "nee", "nee", "ja", "nee", "ja", "ja", "nee", "ja"});
System.out.println(doodle.geefPollInfo());`
類:
public class Poll {
boolean type;
String titel;
String omschrijving;
String locatie;
String initiator;
final int MAX_DEELNEMERS = 10;
LocalDate[] data;
LocalTime[] tijdstippen;
String[] deelnemers = new String[] {"","","","","","",};
String[] antwoorden = new String[15];
String[][] poll = new String[6][15];
String einde = " ";
boolean afgesloten;
int teller = 1;
public Poll(String testBasispoll_1, String dit_is_de_eerste_basispoll, String location, String name, LocalDate[] data, LocalTime[] tijdstippen, boolean b) {
titel = testBasispoll_1;
omschrijving = dit_is_de_eerste_basispoll;
locatie = location;
initiator = name;
this.data = data;
this.tijdstippen = tijdstippen;
type = b;
}
public String geefPollInfo() {
System.out.println("Titel : " + titel);
System.out.println("Omschrijving : " + omschrijving);
System.out.println("Locatie : " + locatie);
System.out.println("Initiator : " + initiator);
System.out.println("Max aantal deelnemers : " + MAX_DEELNEMERS);
System.out.println("--------------------------------------------------------");
System.out.println("Dag \t \t" + data[0] + "\t \t" + data[1] + "\t \t" + data[2] + "\t \t" + data[3] + "\t \t" + data[4]);
System.out.println("Uur \t \t" + tijdstippen[0] + "\t" + tijdstippen[1] + "\t" + tijdstippen[2] + "\t" + tijdstippen[0] + "\t" + tijdstippen[1] + "\t" + tijdstippen[2] + "\t" + tijdstippen[0] + "\t" + tijdstippen[1] + "\t" + tijdstippen[2] + "\t" + tijdstippen[0] + "\t" + tijdstippen[1] + "\t" + tijdstippen[2] + "\t" + tijdstippen[0] + "\t" + tijdstippen[1] + "\t" + tijdstippen[2]);
for (int i = 0; i < 6; i++) {
System.out.println(deelnemers[i] + "\t");
}
for (int j = 0; j < 15; j++) {
System.out.print(antwoorden[j] + "\t");
}
return einde;
}
public boolean voegDeelnameToe(String deelnemer, String[] aanwezigheden) {
//for (int i = 0; i < 6; i++) {
for (int j = 0; j < 15; j++) {
antwoorden[j] = aanwezigheden[j];
}
// }
for (int i = 0; i < 6; i++) {
deelnemers[i] = deelnemer;
}
return type;
}
您正在從geefPollInfo()打印返回的字符串,它是變量einde。 einde只是一個「角色」,我不認爲它在任何地方都會重新初始化。我不確定你在這裏做什麼。 –