0
好吧。這是我的第一頁與訪問器和mutators我如何將數據輸入到用戶的數組中?我正在使用訪問器和增變器
public class TimeCard {
private int employeeNum;
private String[] clockInTimes = new String[14];
private String[] clockOutTimes = new String[14];
private float[] decimalClockIn = new float[14];
private float[] decimalClockOut = new float[14];
private float[] timeElapsed = new float[14];
public String[] getClockInTimes()
{
return clockInTimes;
}
public void setClockInTimes(String[] value)
{
clockInTimes = value;
}
}
我的第二類acessessing set/get數組。 我如何要求每個數組下標0-13的用戶輸入?
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
TimeCard josue = new TimeCard();
System.out.println("Enter Monday Clock In Times:");
//not sure if this is right?
josue.setClockInTimes[0](reader.next());
}
}
順便說一句,我需要這樣做,因爲老師想這樣。我只是不確定如何獲得用戶輸入並將其放入使用對象類的數組中。
你可能想要做一些類似於你的setter獲取索引*和*值的東西。目前,setter將覆蓋整個數組。 – EvanM
那看起來會怎樣?我有點迷路。 –
嘗試將掃描儀放入for循環並將數組索引設置爲for循環變量。 –