Question: Fig. 3 . 9 / / Fig. 3 . 9 : AccountTest.java / / Inputting and outputting floating - point numbers with Account objects. 3
Fig.
Fig. : AccountTest.java
Inputting and outputting floatingpoint numbers with Account
objects.
import java.util.Scanner;
public class AccountTest
public static void mainString args
Account account new AccountJane Green", ;
Account account new AccountJohn Blue", ;
display initial balance of each object
System.out.printfs balance: $fn
accountgetName accountgetBalance;
System.out.printfs balance: $fnn
accountgetName accountgetBalance;
create a Scanner to obtain input from the command window
Scanner input new Scanner
System.in;
System.out.printEnter deposit amount for account: ;
prompt
double depositAmount input.nextDouble; obtain user input
System.out.printfnadding f to account balancenn
depositAmount;
accountdepositdepositAmount; add to accounts balance display balances
System.out.printfs balance: $fn
accountgetName accountgetBalance;
System.out.printfs balance: $fnn
accountgetName accountgetBalance;
System.out.printEnter deposit amount for account: ;
depositAmount input.nextDouble; obtain user input
System.out.printfnadding f to account balancenn
depositAmount;
accountdepositdepositAmount; add to account balance
display balances
System.out.printfs balance: $fn
accountgetName accountgetBalance;
System.out.printfs balance: $fnn
accountgetName accountgetBalance;
Java Removing Duplicated Code in Method main In the AccountTest class of Fig method main contains six statements lines and that each display an Account objects name and balance. Study these statements and youll notice that they differ only in the Account object being manipulatedaccount or account In this exercise, youll define a new displayAccount method that contains one copy of that output statement. The methods parameter will be an Account object and the method will output the objects name and balance. Youll then replace the six duplicated statements in main with calls to displayAccount, passing as an argument the specific Account object to output.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
