0
날짜 배열 (myDates)의 각 날짜 개체를 화면에 인쇄하려고합니다. 날짜 클래스의 값은 월, 일 및 연도입니다.화면에 객체 배열을 인쇄하는 방법은 무엇입니까?
private static void printDates(Date[] myDates) throws IOException {
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
if(myDates.length == 0) {
System.out.println("There are no dates to print.\n");
}
else {
System.out.println("Print the dates to the screen or to a file?");
System.out.println(" 1. Print to screen.");
System.out.println(" 2. Print to a new file.");
System.out.print("Choice: ");
int option = input.nextInt();
System.out.println("");
if(option == 1) {
for(int i = 0; i < myDates.length; i++) { //Is this necessary?
//Don't know how to print array of objects with toString method in date class.
}
날짜 클래스의 가져 오기 및 설정 방법과 관련이 있지만 올바르게 수행하는 방법을 잘 모르겠습니다.
public String getDate() {
return "" + month.getMonth() + " " + day.getDay() + " " + year.getYear();
}
public void setDate(Date date) {
//maybe make a date string then this.date = date; ???
}
아니면 날짜 클래스의 'toString 메서드를 사용 하시겠습니까? 이것은 정확하지 않을 수 있습니다.
public String toString(e) {
return getMonthWord(day.toString()) + " " + month.toString() + " " + year.getYear();
}