Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package date_array;
- /**
- * Creates and holds an array of MyDate objects
- *
- */
- public class DateArray {
- /**
- * Array of my date class
- */
- private MyDate[] dateArr;
- /**
- * Constructor.
- */
- public DateArray() {
- //initialize
- dateArr = new MyDate[] {
- new MyDate("May", 16, 1984),
- new MyDate("November", 14, 1978),
- new MyDate("September", 21, 1980),
- new MyDate("July", 3, 1987)
- };
- }
- /**
- * Prints the array
- */
- public void print() {
- //NOTE: this prints the array backwards
- for(int i = dateArr.length -1; i >=0; --i) {
- System.out.println(dateArr[i]); //to string implicitly called
- }
- }
- /**
- * Entry point -- initializes a "DateArray" then prints it.
- * @param args
- */
- public static void main(String[] args) {
- DateArray dateArray = new DateArray();
- dateArray.print();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement