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 - 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...
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.
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are...
Write a java program that will ask for a Star Date and then convert it into...
Write a java program that will ask for a Star Date and then convert it into the corresponding Calendar date. without using array and methods.
CODE IN JAVA: Write a ProductTester class that creates one Product object named "Juicer" with a...
CODE IN JAVA: Write a ProductTester class that creates one Product object named "Juicer" with a price of $50.99, prints the name and price of the product, reduces its price by 4.0, and then prints its price again. public class Product { private String name; private double price; public Product(String productName, double productPrice) { name = productName; price = productPrice; } public String getName() { return name; } public double getPrice() { return price; } public void reducePrice(double amount) {...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a...
Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used to hold the rectangle’s width....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT