0% found this document useful (0 votes)
19 views3 pages

Lab4.2 - Wednesday

This lab exercise involves practicing creating arrays and array lists of objects in Java. Students will create classes for BankAccount, CheckingAccount, and SavingAccount with the appropriate relationships. They will then create an array of CheckingAccount objects and an ArrayList of SavingAccount objects, populate them with sample data, and demonstrate various array and array list methods.

Uploaded by

Nini Lili
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Lab4.2 - Wednesday

This lab exercise involves practicing creating arrays and array lists of objects in Java. Students will create classes for BankAccount, CheckingAccount, and SavingAccount with the appropriate relationships. They will then create an array of CheckingAccount objects and an ArrayList of SavingAccount objects, populate them with sample data, and demonstrate various array and array list methods.

Uploaded by

Nini Lili
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 111T - Lab

Programming Language 2
Computer Science Department
2023

Lab Objectives:
In this lab, a student will practice

• Creating an Array of objects.


• Adding objects to the array.
• Creating an ArrayList and using different methods of the ArrayList.
• Test the classes with ArrayList and Array in the Main Class.
Lab Exercise:
Given the following UML implement all the classes, with all needed instance variables,
constructors and setter/getter methods; then write a test application to demonstrate the class
capabilities.

Consider the following points:


Link the classes CheckingAccount and SavingAccount with class BankAccount by is_a relationship.

In your main Class:


A. Array:

1. Create an Array of type CheckingAccount of size 2, and use this information in the following table:

Owner balance annoualFee


Amal 20000 1000
Sara 5000 500

2. Change the annoualFee of Sara to become 400.


3. Print out the elements of the array.

B. ArrayList:

1. Create an ArrayList of type SavingAccount.


2. Create two objects of SavingAccount class with the following values:
Owner balance InterrestRate
Omar 3000 10
Ahmad 40000 7

3. Add the objects created to the ArrayList by using the appropriate ArrayList method.
4. Print all the list elements by using one line code.
5. Use the appropriate ArrayList method to print the Interest Rate of Owner Ahmad.

Assignment:
Write a Java program that demonstrate Array and ArrayList. DO NOT use the examples from
the lecture.

In your program, design and implement 3 classes ( one superclass and two subclasses ) in the
same package with all needed instance variables, accessor and mutators methods and
constructors; then write a test application to demonstrate the classes capabilities.

Consider the following points:

• Declare 2 instance variables in each class


• Create full Argument constructor in each classes.
• Create a getter and setter methods in each classes.
• In the main class:
o Create an Array of the first subclass of size 4, then add the information to the
array.
o Create an ArrayList of the Second subclass then in the main class add two
Objects with the appropriate values to the ArrayList by using the appropriate
ArrayList method .

You might also like