In: Computer Science
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
Java Code :
import java.util.*;
//creating Account, Date, ClockWithAudio, BMI, Day and
FigurePane classes
class Account { }
class Date { }
class ClockWithAudio { }
class BMI { }
class Day { }
class FigurePane { }
public class Main
{
public static void main(String[] args) {
//Creating Account object, a Date
object, a ClockWithAudio object, a BMI object, a Day object, and a
FigurePane object
Account account = new
Account();
Date date = new Date();
ClockWithAudio clockWithAudio = new
ClockWithAudio();
BMI bmi = new BMI();
Day day = new Day();
FigurePane figurePane = new
FigurePane();
//creating an arrayList
ArrayList arrayList = new
ArrayList();
//Adding all objects to
arrayList
arrayList.add(account);
arrayList.add(date);
arrayList.add(clockWithAudio);
arrayList.add(bmi);
arrayList.add(day);
arrayList.add(figurePane);
//displaying the elements of
arrayList
for (int
i=0;i<arrayList.size();i++)
{
System.out.println(arrayList.get(i));
}
}
}
Output :