Question

In: Computer Science

JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...

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.

Solutions

Expert Solution

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 :


Related Solutions

java please Write a program that creates an ArrayList and adds 5 circle objects to the...
java please Write a program that creates an ArrayList and adds 5 circle objects to the list , and display all elements in the list by invoking the object’s toString() method.
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
Write a Java program that takes an ArrayList<Integer>,  adds k copies of it at the end, and...
Write a Java program that takes an ArrayList<Integer>,  adds k copies of it at the end, and returns the expanded ArrayList.  The total size will be (k+1) * n.   public ArrayList<Integer> makeCopies(ArrayList<Integer>, int k) { } Example: ArrayList<Integer> has (3,7,4) and k = 2, then the returned, expanded ArrayList will have (3,7,4,3,7,4,3,7,4).  The total size is (k+1)*n = (2+1)*3= 9.
3.1 Write code that creates an ArrayList object named list and fills list with these numbers...
3.1 Write code that creates an ArrayList object named list and fills list with these numbers (using one or a pair of for or while loops): 0 1 2 3 4 0 1 2 3 4 3.2 Consider the ArrayList object named list containing these Integers: list = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 } What are the contents of list after this loop completes? for (int i = 1; i < 10; ++i) {...
Write a program that adds and subtracts two polynomials. It creates an array of nodes and...
Write a program that adds and subtracts two polynomials. It creates an array of nodes and connects them into the freeStore. This implementation uses one array to store multiple array to store multiple polynomial instances and the free store. I need help to finish the LinkedListInArrayPolynomial class. Output should look like below: Forth test is linked list of terms in an array. linkInArray1 = 3x^11+4x^10+4x^4 linkInArray2 = 4x^19+5x^14-3x^12-78 sum of linkInArray1 and linkInArray2 = 4x^19+5x^14-3x^12+3x^11+4x^10+4x^4-78 linkInArray1 minus linkInArray2 = -4x^19-5x^14+3x^12+3x^11+4x^10+4x^4+78...
Write a java program that adds up the squares and adds up the cubes of integers...
Write a java program that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered by the user: Upper Limit: 5 The sum of Squares is 55 The sum of Cubes is 225 Do this by using just one loop that generates the integers. DO NOT USE ANY FORMULAS.
Write a java program: Write a program that creates a text file. Write to the file...
Write a java program: Write a program that creates a text file. Write to the file three lines each line having a person's name. In the same program Append to the file one line of  'Kean University'.  In the same program then Read the file and print the four lines without lines between.
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
IN JAVA write a program that creates an array of strings with 8 people in it....
IN JAVA write a program that creates an array of strings with 8 people in it. Second,  Assign a random rank between 1 to 8 to each of the players. The rankings do not change throughout the tournament. Finally, Sort the players based on the rankings and print the data (show rankings of players, in square brackets, at every step after they are ranked). USING JAVA COLLECTIONS IS NOT ALLOWED
Consider the following program that creates an ArrayList of objects of a type A, and sorst...
Consider the following program that creates an ArrayList of objects of a type A, and sorst them. Supply the missing code. Sample output when you run the program is shown below. import java.util.*; class A { int i, j, k; public A(int i, int j, int k){ this.i=i; this.j=j; this.k=k; } public String toString(){ return "A("+i+","+j+","+k+")"; } } class SortA { public static void main(String[] args){ ArrayList aL=new ArrayList(); Random rand= new Random(1000); //1000 is a seed value for (int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT