CPT121 Task 5.1.3 Practice Exercises – Managing Arrays of Objects Solved

30.00 $

Category:

Description

5/5 - (1 vote)

Task 5.1.3 Practice Exercises – Managing Arrays of Objects

  1. Assume that the application class below makes use of the Account class discussed previously import java.util.*; public class TestAccounts2

{ public static void main(String args[])

{

String accountID, name; double balance; Scanner sc = new Scanner(System.in));

/*** Array used to store up to 10 accounts ***/

Account[] accounts = new Account[1];

/*** CODE for part a) goes here ***/

/*** CODE for part c) goes here *** …

// print details for all accounts

System.out.println(“Account Details”);

/*** Code for part b) goes here ***/ …

}

}

  1. Write code to populate the array with the Accounts containing the following details:
ID Name Balance
S5234 David $1000
S1239 Cliff $2000
S4236 Martin $3000
  1. Write code which iterates through the objects that are currently stored in the array and prints their details to the screen. Your iteration loop should cease executing once it has gone past the last object in the array.
  2. What will be the output printed by the program if we replace the indicated comment for part C in the code above with each of the following blocks?

Tip: You may find drawing diagrams of the array and the objects each element is pointing to useful when considering the effect of each code segment.

  1. a[1] = a[0]; a[2] = a[1]; a[0] = a[2];
  2. a[0] = a[1];

a[0].withdraw(100); a[1].withdraw(100);

  • a[0].transfer(a[1],500); a[1].transfer(a[2],500);
  • task_5_1_3-c2igc9.zip