The variable accounttwo being set

Assignment Help Basic Computer Science
Reference no: EM13677006

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 }

Reference no: EM13677006

Questions Cloud

A cyber stalker and you are going to stalk : A cyber stalker and you are going to stalk yourself.
Is the following statement true or false for penn state : Is the following statement true or false for Penn State
How much extra transmission delay will the segments : a) How much extra transmission delay will the segments experience?
Transitive-closure : Transitive-Closure
The variable accounttwo being set : 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?
Global data distribution : Global Data Distribution
Evaluate student ability to research and evaluate security : Evaluate the student  ability to research and evaluate security testing software and present a proposal for review by executive team members
Java how to program 10th edition : Java How To Program 10th Edition
Network security & how do they work together : 1. In reference to firewalls, proxies, Intrusion Prevention Systems and Intrusion Detection Systems. Why are they important for network security & how do they work together?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd