Question

In: Computer Science

Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...

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.

Solutions

Expert Solution

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


Related Solutions

Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
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. Problem : The Fraction class (Filename: TestFraction.java) Design...
Objectives: use Scite 1. Use recursion to solve a problem 2. Create classes to model objects...
Objectives: use Scite 1. Use recursion to solve a problem 2. Create classes to model objects Problem 1: Compute greatest common divisor using recursion (filename: TestRecusiveGCD.java) The gcd(m, n) can be defined recursively as follows: If m % n is 0, gcd (m, n) is n. Otherwise, gcd(m, n) is gcd(n, m % n). Write a recursive method to find the GCD of two given integers. Write a test program that prompts the user to enter two integers, calls the...
11.1 Simple Arithmetic Program Using the instructions from Week 1 Lab, create a new folder named...
11.1 Simple Arithmetic Program Using the instructions from Week 1 Lab, create a new folder named Project01. In this folder create a new class named Project01. This class must be in the default package. Make sure that in the comments at the top of the Java program you put your name and today's date using the format for Java comments given in the Week 1 Lab. For this lab, you will write a Java program to prompt the user to...
Objectives: use Scite Use recursion to solve a problem Create classes to model objects Problem :...
Objectives: use Scite Use recursion to solve a problem Create classes to model objects Problem : The Rectangle class (Filename: TestRectangle.java) Design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height....
I. At the beginning, create a folder named "test" and add the folder into the version...
I. At the beginning, create a folder named "test" and add the folder into the version control tool tracking system. Then create one file named "001" under this folder. Commit any change if necessary. II. Next, add another file named "002" in the same folder and commit the change ("adding") in the version control tool. III. Followed by adding that file, create a branch (namely, "branch-A") in the version control tool and make some changes to the contents in file...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play....
Using Python to play Checkers: 1) Create classes to represent the necessary objects for game play. This will include, at least, the game board, the two types of pieces and the two sides. You will need to determine the best way to represent the relationship between them. 2) Set up one side of the board. Print the status of the board.
Instructions Create an application to accept data for an array of five CertOfDeposit objects, and then...
Instructions Create an application to accept data for an array of five CertOfDeposit objects, and then display the data. import java.time.*; public class CertOfDeposit { private String certNum; private String lastName; private double balance; private LocalDate issueDate; private LocalDate maturityDate; public CertOfDeposit(String num, String name, double bal, LocalDate issue) { } public void setCertNum(String n) { } public void setName(String name) { } public void setBalance(double bal) { } public void issueDate(LocalDate date) { } public String getCertNum() { }...
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program...
Inside “Lab1” folder, create a project named “Lab1Ex3”. Use this project to develop a C++ program that performs the following:  Define a function called “Find_Min” that takes an array, and array size and return the minimum value on the array.  Define a function called “Find_Max” that takes an array, and array size and return the maximum value on the array.  Define a function called “Count_Mark” that takes an array, array size, and an integer value (mark) and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT