In: Computer Science
Objectives:
1. Create classes to model objects
Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problems [30 marks]
Problem 1: The Account class (Filename: TestAccount.java) Design a class named Account that contains:
1. A private int data field named id for the account.
2. A private double data field named balance for the account.
3. A private double data field named annualInterestRate that stores the current interest rate.
4. A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0.
5. The accessor and mutator methods for id, balance, and annualInterestRate.
6. A method named getMonthlyInterestRate() that returns the monthly interest rate.
7. A method named withdraw(amount) that withdraws a specified amount from the account.
8. A method named deposit(amount) that deposits a specified amount to the account.
Write a test program that creates an Account object with an account ID of 1122, a balance of $20000, and an annual interest rate of 4.5%. Use the withdraw function to withdraw $2500, use the deposit function to deposit $3000, and print the balance, and the monthly interest.
class Account{
private int id;
private double balance;
private double annualInterestRate;
public Account() {
id=0;
balance=0;
annualInterestRate=0;
}
public int getId() {
return id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int aId) {
id = aId;
}
public void setBalance(double aBalance) {
balance = aBalance;
}
public void setAnnualInterestRate(double aAnnualInterestRate) {
annualInterestRate = aAnnualInterestRate;
}
public double getMonthlyInterestRate() {
return balance * (annualInterestRate/12/100);
}
public void withdraw(double amount) {
balance-=amount;
}
public void deposit(double amount) {
balance+=amount;
}
}
public class TestAccount {
public static void main(String[] args) {
Account a = new Account();
a.setId(1122);
a.setBalance(20000);
a.setAnnualInterestRate(4.5);
a.withdraw(2500);
a.deposit(3000);
System.out.println("Balance: $"+a.getBalance());
System.out.println("Monthly Interest: "+a.getMonthlyInterestRate());
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME