plven the following code ublic class Account { private double balance; / instance variable that stores the balance // constructor public Account( double initialBalance ) H validate that initialBalance is greater than 0.0; // if it is not, balance is initialized to the default value 0.0 if ( initialBalance > 0.0) balance = initialBalance; } // end Account constructor // credit (add) an amount to the account public void credit( double amount ) balance = balance + amount; // add amount to balance } // end method credit // return the account balance public double getBalance() return balance; // gives the value of balance to the calling method } // end, method getBalance } // end class Account Vhat is output by the following main method? public static void main( String args[] ) Account account1 = new Account( 15.33 ); System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); System.out.println( "adding $2.53 to account1 balance" ); account1.credit( 2.53 ); System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); } // end main O account1 balance: 15.33 adding 2.53 to account1 balance account1 balance: 17.86 O account1 balance: $15.33 adding $2.53 to account1 balance account1 balance: $17.86 Oaccount1 balance: $17.86 adding $15.33 to account1 balance account1 balance: $2.53 O account1 balance: $15.33 adding $17.86 to account1 balance account1 balance: $2.53 Save and Submit to save and submit. Click Save All Answers to save all answers.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter11: Introduction To Classes
Section11.2: Basic Class Functions
Problem 5E
icon
Related questions
Question
o Jullulo
* Question Completion Status:
QUESTION 14
Given the following code:
public class Account
{
private double balance; // instance variable that stores the balance
/ constructor
public Account( double initialBalance )
/ validate that initialBalance is greater than 0.0;
/ if it is not, balance is initialized to the default value 0.0
if ( initialBalance > e.0)
balance = initialBalance;
} // end Account constructor
// credit (add) an amount to the account
public void credit( double amount )
{
balance = balance + amount; / add amount to balance
} // end method credit
// return the account balance
public double getBalance()
return balance; // gives the value of balance to the calling method
} // end, method getBalance
} // end class Account
What is output by the following main method?
public static void main( String args[] )
{
Account account1 = new Account( 15.33 );
System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() );
System.out.println( "adding $2.53 to account1 balance" );
account1.credit( 2.53 );
System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() );
} // end main
O account1 balance: 15.33
adding 2.53 to account1 balance
account1 balance: 17.86
O account1 balance: $15.33
adding $2.53 to account1 balance
account1 balance: $17.86
O account1 balance: $17.86
adding $15.33 to account1 balance
account1 balance: $2.53
O account1 balance: $15.33
adding $17.86 to account1 balance
account1 balance: $2.53
Click Save and Submit to save and submit, Click Save All Answers to save all answers.
Transcribed Image Text:o Jullulo * Question Completion Status: QUESTION 14 Given the following code: public class Account { private double balance; // instance variable that stores the balance / constructor public Account( double initialBalance ) / validate that initialBalance is greater than 0.0; / if it is not, balance is initialized to the default value 0.0 if ( initialBalance > e.0) balance = initialBalance; } // end Account constructor // credit (add) an amount to the account public void credit( double amount ) { balance = balance + amount; / add amount to balance } // end method credit // return the account balance public double getBalance() return balance; // gives the value of balance to the calling method } // end, method getBalance } // end class Account What is output by the following main method? public static void main( String args[] ) { Account account1 = new Account( 15.33 ); System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); System.out.println( "adding $2.53 to account1 balance" ); account1.credit( 2.53 ); System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() ); } // end main O account1 balance: 15.33 adding 2.53 to account1 balance account1 balance: 17.86 O account1 balance: $15.33 adding $2.53 to account1 balance account1 balance: $17.86 O account1 balance: $17.86 adding $15.33 to account1 balance account1 balance: $2.53 O account1 balance: $15.33 adding $17.86 to account1 balance account1 balance: $2.53 Click Save and Submit to save and submit, Click Save All Answers to save all answers.
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning