对于这个简单的程序,我们有2个类可以使用MyDate
和DueDates
(当然是main
类)。在初始化MyDate
类的对象数组之后private MyDate [] dueDates = new MyDate[10]
,一个特定的函数要求我们“从传入的扫描器中读取数组中日期的值”。
我很困惑,因为我 - 一个弱的程序员 - 只用于Scanner
类似的东西System.in
。这不是我不理解的; 我怎么能读到这些价值观?因为我无法使用input.next()
或不能使用类型Class的数组。
public class DueDates { private MyDate[] dueDates ; public DueDates() { //***** write the code for this method here dueDates = new MyDate [10]; } //set array to have size of parameter passed in public DueDates(int max) { //***** write the code for this method here dueDates = new MyDate[max]; } /*reads in values for the dates in the array from the Scanner passed in ------having issues here*/ public boolean inputDueDates(Scanner in) { //***** write the code for this method here in = new Scanner(System.in); dueDates = in. // I'm lost at this point return true; }}
public class MyDate { private int day = 1; private int month = 1; private int year = 2018; public MyDate() { } public String toString() { return new String ("" + year + "/" + month + "/" + day); } public boolean inputDate(Scanner in) { month = 0; day = 0; year = 0; do { System.out.print ("Enter month - between 1 and 12: "); if (in.hasNextInt()) this.month = in.nextInt(); else { System.out.println ("Invalid month input"); in.next(); } } while (this.month <= 0 || this.month > 12); do { System.out.print ("Enter day - between 1 and 31: "); if (in.hasNextInt()) this.day = in.nextInt(); else { System.out.println ("Invalid day input"); in.next(); } }
喵喔喔
相关分类