This activity will require you to apply your knowledge of interfaces – including the Comparable interface – in order to leverage the capabilities of the ArrayList data structure. --------- You may...

1 answer below »

This activity will require you to apply your knowledge of interfaces – including the Comparable interface – in order to leverage the capabilities of the ArrayList data structure.


---------


You may work individually or with a partner, but be sure that each student submits their own assignment in Canvas (and leave a comment with your partner's name if you worked with one).


---------



Description:


Interfaces are used to make a Class implement a behavior or set of behaviors. Recall the example from class in which the Gradable Interface was used to ensure that the calculateGrade() and getAbsences() methods were implemented by the Student class.


Your goal for this assignment is to create your own example of an Interface and a Class that implements it. You may not use Gradable / Student.



  • Decide on the Interface that you will be creating. It should include at least three methods and one attribute, and represent a type of behavior. Please use the convention of ending your Interface name in “able” (e.g. gradable). Create this interface in its own file as shown in class.

  • Decide on a Class that will implement this interface. In addition to implementing the Interface that you created, you should implement the Comparable interface for your class (as demonstrated in class). Override the compareTo() method in a manner that makes sense for your Class. Also, override the toString() method in a way that displays all relevant information for your Class.Note that your methods don't need to be exceedingly complex -- just make sure that they do something that makes sense in the context of your class and interface.

  • In your main method, create an ArrayList containing 5 instances of your Class. You may hard-code the values for your class attributes in your main method. Sort your ArrayList as demonstrated in class, and display the contents using the enhanced for-loop syntax and overridden toString() method that you created.



---------


You are welcome to use either VSCode or NetBeans to complete this assignment. If you use VSCode, upload your Java files. If you use NetBeans, export your project to a ZIP file and upload that. Please do not upload any compression formats other than ZIP files. Other formats (e.g. 7zip, tar.gz, etc.) will not be accepted and will result in a grade of zero.

Previous Module:

Week 7: Abstract classes and Polymorphism" style="float: left;">Previous
zyBooks: 14.1 – 14.3 " style="float: right;">Next
Answered Same DayOct 15, 2021

Answer To: This activity will require you to apply your knowledge of interfaces – including the Comparable...

Vaibhav answered on Oct 15 2021
126 Votes
Account.java
Account.java
import java.util.ArrayList;
import java.util.Collections;
/**
 * Account class denotes the account details of an individual.
 */
class Account implements Transactionable, Comparable 
{
    private int accountNumber;
    private String name;
    private float accountBalance;
    private boolean isActive;
    /**
     * Default Constructor to initialize data members.
     * 
     * @param acNum
     * @param name
     * @param bal
     * @param isActive
     */
    public Account(int acNum, String name, float bal, boolean isActive) {
        this.accountNumber = acNum;
        this.name = name;
        this.accountBalance = bal;
        this.isActive = isActive;
    }
    /**
     * Display the account details
     */
    @Override
    public String toString() {
        return "\nName : " + name + "\nAccount Number :" + accountNumber + " \nAccount Balance : $" + accountBalance
                + " \nStatus : " + (isActive ? "Active" : "Not Active");
    }
    /**
     * Used by sort to compare two accounts
     */
    @Override
    public int compareTo(Account o) {
        return (int) (accountBalance - o.accountBalance);
    }
    @Override
    public float calculateInterestAmount(float timePeriod) {
        if (this.accountBalance > 0 && isActive) {
            float interestAmt = (interestRate * accountBalance * timePeriod) / 100;
            return interestAmt;
        }
        return 0;
    }
    @Override
    public boolean isAmountWithdrawable(int amount) {
        if (accountBalance >= amount && isActive) {
            return true;
        }
        return false;
    }
    @Override
    public void withdrawAmount(int amount) {
        if (isAmountWithdrawable(amount)) {
            this.accountBalance -= amount;
        }
    }
    public static void main(String[] args) {
        // Populating the arraylist with 5 account details.
        ArrayList accounts = new ArrayList();
        accounts.add(new Account(10001, "Raj", 100.0f, true));
        accounts.add(new Account(10002, "Howard", 1500.0f, true));
        accounts.add(new Account(10003, "Sheldon", 96800.0f, false));
  ...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here