Write a class (with a main method) called AppleTest Declare 2 double variables n
ID: 3581314 • Letter: W
Question
Write a class (with a main method) called AppleTest Declare 2 double variables named: interest Amount and new Balance Declare an object of the above class AppieAccount called "account" and initialize t with the following data: Larry, 50000, 0. 10 Call the appropriate method to calculate the interest amount of the "account1" object and assign it to the variable "interestAmount". Add the interestAmount variable (above) to the current balance of the "account1" object and assign the result to the variable 'newBalance'. Use the 'newBalance' variable (above) ti set the new account balance of the 'account1' object. Declare a new object of the AppleAccount class called "account2" and initialize it with following data George, 100000, 0.06. Compare the balances of the 'account1" and 'account2' and print the smallest balance.Explanation / Answer
Java Code:
/* Class definition */
class AppleTest
{
//Main method
public static void main(String args[])
{
double interestAmount, newBalance;
//Creating an object of AppleAccount class
AppleAccount account1 = new AppleAccount("Larry", 50000, 0.10);
//Calculating interest amount
interestAmount = account1.calculateInterest();
//Updating new balance
newBalance = interestAmount + account1.getCurrentBalance();
//Updating new balance
account1.setCurrentBalance(newBalance);
//Creating another object of class AppleAccount
AppleAccount account2 = new AppleAccount("George", 100000, 0.06);
//Comparing balance of both accounts
if(account1.getCurrentBalance() < account2.getCurrentBalance())
{
//Printing account with lowest balance
System.out.println(account1.getName() + " has lowest balance ");
}
else
{
System.out.println(account2.getName() + " has lowest balance ");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.