What is being called by line 20 of listing 2 how is the


What is being called by line 20 of Listing 2? How is the balance value of the object referenced by the variable accountTwo being set?

Here is the code:

2
3 import java.util.Scanner;
4 import java.util.Random;
5
6 public class AccountTester
7 {
8 Random randomNumbers = new Random();
9 Scanner userInput = new Scanner(System.in);
10
11 public void testAccountClass()
12 {
13 System.out.println("nn*** Testing the Account Class ***");
14
15 System.out.printf("nCurrent Interest Rate: %.2f%%", Account.CURRENT_RATE *
16 100.0);
17
18 System.out.println("nnCreating Account Objects");
19 Account accountOne = new Account(5000.0);
20 Account accountTwo = new Account(accountOne);
21 accountOne.displayValues("nInitial Values for Account One:");
22 accountTwo.displayValues("nInitial Values for Account Two:");
23
24 System.out.println("nnExercising Account Transactions");
25 accountOne.credit(0.0);
26 accountOne.debit(-6);
27 accountTwo.credit(-1.50);
28 accountTwo.debit(100.0);
29 accountTwo.debit(5000);
30 exerciseTransactions(accountOne, 100, 500.0);
31 exerciseTransactions(accountTwo, 250.0);
32 accountOne.displayValues("nnUpdated Values for Account One:");
33 accountTwo.displayValues("nUpdated Values for Account Two:");
34
35 System.out.println("nnExercising Future Value Calculators");
36 System.out.printf(" Calculation 1: $%.2fn", accountOne.futureValue(6.5,
37 0.05));
38 System.out.printf(" Calculation 2: $%.2fn", accountOne.futureValue(15,
39 0.05));
40 System.out.printf(" Calculation 3: $%.2fn", accountTwo.futureValue(6.5));
41 System.out.printf(" Calculation 4: $%.2fn", accountTwo.futureValue(15));
42 System.out.println("nn*** Testing Complete ***n");
43 }
44
45 private void exerciseTransactions(Account thisAccount, int testCount,
46 double limit)
47 {
48 int count = 0;
49 while( count < testCount )
50 {
51 if( (count % 3) != 0 )
52 thisAccount.credit(getDataValue(limit));
53 else
54 thisAccount.debit(getDataValue(limit));
55 count++;CSC-240 Java Programming - Exam One Listings Page 4 of 6
56 }
57 }
58
59 private void exerciseTransactions(Account thisAccount, double limit)
60 {
61 char answer;
62 displayMenu();
63 do
64 {
65 answer = getUserCommand();
66 switch( answer )
67 {
68 case 'D':
69 thisAccount.debit(getUserValue(limit));
70 break;
71 case 'C':
72 thisAccount.credit(getUserValue(limit));
73 break;
74 case 'V':
75 thisAccount.displayValues();
76 break;
77 case 'M':
78 displayMenu();
79 break;
80 }
81 }
82 while( answer != 'Q' );
83 }
84
85 private double getDataValue(double maxValue)
86 {
87 return 1.0 + randomNumbers.nextDouble() * maxValue;
88 }
89
90 private double getUserValue(double limit)
91 {
92 double thisValue;
93 do
94 {
95 System.out.printf("Please enter a value (0.0 - %.2f): ", limit);
96 thisValue = userInput.nextDouble();
97 if( !(thisValue >= 0.0 && thisValue <= limit) )
98 System.out.printf("? Invalid input: %.2fn", thisValue);
99 }
100 while( thisValue < 0.0 || thisValue > limit );
101 return thisValue;
102 }
103
104 private void displayMenu()
105 {
106 System.out.println("nnPlease enter one of the following:");
107 System.out.println(" D - to test the debit method");
108 System.out.println(" C - to test the credit method");
109 System.out.println(" V - to display the values of the Account");
110 System.out.println(" M - to re-display this menu");
111 System.out.println(" Q - to exit this testn");
112 }CSC-240 Java Programming - Exam One Listings Page 5 of 6
113
114 private char getUserCommand()
115 {
116 char thisChar;
117 boolean goodChar;
118 do
119 {
120 System.out.print("Enter a command letter: ");
121 thisChar = userInput.next().toUpperCase().charAt(0);
122 goodChar = (thisChar == 'D' || thisChar == 'C' || thisChar == 'M' ||
123 thisChar == 'Q' || thisChar == 'V');
124 if( !goodChar )
125 System.out.println("That is not a valid command letter");
126 }
127 while( goodChar == false );
128 return thisChar;
129 }
130 }

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: What is being called by line 20 of listing 2 how is the
Reference No:- TGS0930585

Expected delivery within 24 Hours