Question
Assignment 1 Instructions: Submit an electronic copy of the assignment (.java) to the Dropbox (ex. ClassName.java, etc.) IMPORTANT: FOLLOW GOOD PROGRAMMING STYLE/CONVENTION FOR NAMING ALL
Assignment 1 Instructions: Submit an electronic copy of the assignment (.java) to the Dropbox (ex. ClassName.java, etc.) IMPORTANT: FOLLOW GOOD PROGRAMMING STYLE/CONVENTION FOR NAMING ALL YOUR OBJECTS/VARIABLES. ADD COMMENTS ON TOP OF EACH METHOD AND AT TOP OF THE FILE (SEE EXAMPLE AT THE LAST PAGE) Programming Exercise: (Savings Account Class) Create class SavingsAccount. Use a static variable annualInterestRate to store the annual interest rate for all account holders. Each object of the class contains a private instance variable savingsBalance indicating the amount the saver currently has on deposit. Provide method calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by annualInterestRate divided by 12this interest should be added to savings- Balance. Provide a static method modifyInterestRate that sets the annualInterestRate to a new value. Write a program to test class SavingsAccount. Instantiate two savingsAccount objects, saver1 and saver2, with balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate the monthly interest for each of 12 months and print the new balances for both savers. Next, set the annualInterestRate to 5%, calculate the next months interest and print the new balances for both savers. //filename: BankAccount.java public class BankAccount { private int acctNumber; private double balance; private String firstName; private String lastName; //constructor with given value public BankAccount(int acctNumber, String firstName, String lastName, double balance) { this.acctNumber = acctNumber; this.balance = balance; this.firstName = firstName; this.lastName = lastName; } //get the first name public String getFirstName() { return firstName; } //get the last name public String getLastName() { return lastName; } //get the account number public int getAcctNumber() { //return accountNumber; return acctNumber; } //deposit amount into account public void deposit(double amount) { //double newBalance = balance + amount; //balance = newBalance; balance += amount; } //withdraw money public void withdraw(double amount) { double newBalance = balance - amount; balance = newBalance; } //get balance public double getBalance() { return balance; } //display info public void displayAccount() { System.out.printf("Account# : %d%n", getAcctNumber()); System.out.printf("First Name: %s%n", getFirstName()); System.out.printf("Last Name : %s%n", getLastName()); System.out.printf("Balance : %.2f%n", getBalance()); } } //filename: AccountTest.java public class AccountTest { public static void main(String[] args) { BankAccount savings = new BankAccount(1001,"Robert", "Smith",1000, 0.8); BankAccount checking = new BankAccount(1002,"Antonio", "Stewart", 500); System.out.println("-----Saving's Account-----"); savings.displayAccount(); System.out.println(); System.out.println("-----Checking's Account-----"); checking.displayAccount(); savings.deposit(1000); savings.withdraw(100); System.out.println(); System.out.println("-----Saving's Account-----"); savings.displayAccount(); System.out.println(); System.out.println("-----Checking's Account-----"); checking.displayAccount(); //adding money into checking account checking.withdraw(100); checking.withdraw(100); checking.withdraw(100); checking.deposit(500); //adding interest into savings account and deducting fees System.out.println("-----Saving's Account-----"); savings.displayAccount(); System.out.println(); System.out.println("-----Checking's Account-----"); checking.displayAccount(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started