1. Declare the Account class
public class Account {
// code here
}
2. Add the balance instance variable
public double balance;
3.Add a constructor that sets the balance instance variable to the initial balance argument passed to the constructor
public Account (double initBalance) {
balance = initBalance;
}
1. Declare the
TestAccount2 class.
public class TestAccount2 {
// code here
}
2. Add the main method:
public static void main (String[] args){
// code here
}
a. Declare a variable withing the main method of type Account named acct. Also, in the same statement, initialize the variable acct to a new instance of Account by passing 100.00 to the constructor as the initial balance.
Account acct = new Account (100.0);
b. Use the addition operator to add 47 to the account object's balance
acct.balance = acct.balance + 47.0;
c. Use the substraction operator to substract 150 from the account object's balance
acct.balance = acct.balance -150.0
d. Use the System.out.println method to display the balance to the standard output stream.
System.out.println("Final account balance is "+acct.balance);