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

  How many nibbles are in a byte

What is the hex value of the least significant nibble of the binary number 1001 0101?

  Describes how a honey pot was used

Describes how a honey pot was used

  Wat do you mean by query optimization why is it required

question 1 what is a query execution plan?question 2 what is query optimization? why is it needed?question 3 with a

  Systems analyst modifying the sales order process

Suppose that you are a systems analyst on a project that involves modifying the sales order process. How many do you need to sample if you want 95 percent certainty that you have covered all variations?

  In order to create a unique field in a table in a database

1. in order to create a unique field in a table in a database you need to define a .viewprimary keyhost keyjoin2.a in

  Evaluate the natural settings of the test environment

Assess the reliability of data gathered via paid Internet users. Describe and assess the evaluation method being used by the testing company, i.e., nonvisual and verbal recording of browser activities and tester's vocal comments.

  Write the main program to generate random numbers

To compare the performance, you need to write the main program to generate random numbers to populate a large integer array, and then call the subroutine to sort this array. Remember to get the time before and after the bubble sort to measure the ..

  Determine number in cs register

If code segments for the 8086 program start at address 70400H, what number will be in CS Register? Suppose the same code segment base.

  Describe how upper is adjusted to allow simpler code to work

Describe how A_upper is adjusted to allow this simpler code to work. (Hint: A_upper requires to be adjusted because A_lower will be sign-extended.)

  Use the raptor to complete the problem

Use the Raptor to complete the problem, Input names of students from the user, terminated by "ZZZ", 0, 0, 0, and create a data file grades with records of the following form: student (string), test (integer), test 2 (integer), test 3 (integer)

  Compare clock cycle times and execution times

Instead of a single cycle orgization we use multicycle organization where each instruction takes multiple cucles but only one instruction finishes before another is fetched. in this organization.

  The context of a database system

1. Discuss what a user view represents in the context of a database system.

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