Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q. 36 Suppose you have a pre-existing class BankAccount that represents users' accounts and money deposited at a given bank. The class has the following

image text in transcribed

Q. 36 Suppose you have a pre-existing class BankAccount that represents users' accounts and money deposited at a given bank. The class has the following data and behavior: Field/Constructor/Method Description private String name name of the person using the account private int id ID number of this account private double balance amount of money currently in the account public BankAccount (String name, int id) makes account with given name/ID and $0.00 public void deposit (double amount) adds given amount to account's balance public int getID) returns the account's ID number public String getName() returns the account's name public double get Balance () returns the account's balance public String toString() returns String such as "Ed Smith: $12.56" public void withdraw (double amount) | subtracts given amount from account's balance Make RankAccount objects comparable to each other using the Comparable interface. Add any necessary code below, and/or make any changes to the existing code headings shown. The bank wants to sort by who has the most money, so accounts are compared by balance. One with a lower balance is considered to be "less than one with a higher balance. If two accounts have the same balance, they are compared by ID. The one with the lower ID is considered to be "less than the one with the higher ID. If two accounts have the same balance and ID, they are considered to be "equal." Your method should not modify any account's state. You may assume the parameter passed is not null. public class BankAccount { ... // write any added code here Now create a class called Bank comparater that implements the Comparator interface in order to sort a list of customers in ascending order. Your BankComparator class must be able to provide the order to sort the list in ascending order based on the balance in customer's account

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions