The following Comparator class is attempting to arrange BankAccount objects by account name, breaking ties by account
Question:
The following Comparator class is attempting to arrange BankAccount objects by account name, breaking ties by account balance. But the code has some syntax errors and some logic errors. What is wrong with the code? How would you correct it?
Transcribed Image Text:
1 import java.util.*; 2 public class AccountComparator extends Comparator { 3. public int compareTo (BankAccount account2) { if (!this.getName ().equals (account2.getName () )) { 4 return this.getName ().compareTo (account2.getName ()); } else { return this.getBalance () account2.getBalance (); 8. 9. 10 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (8 reviews)
The AccountComparator shown has a few errors line 2 It should implement Comparator rathe...View the full answer
Answered By
Nazrin Ziad
I am a post graduate in Zoology with specialization in Entomology.I also have a Bachelor degree in Education.I posess more than 10 years of teaching as well as tutoring experience.I have done a project on histopathological analysis on alcohol treated liver of Albino Mice.
I can deal with every field under Biology from basic to advanced level.I can also guide you for your project works related to biological subjects other than tutoring.You can also seek my help for cracking competitive exams with biology as one of the subjects.
3.30+
2+ Reviews
10+ Question Solved
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Question Posted:
Students also viewed these Computer science questions
-
How would you go about attempting to come up with the probability of a super- event or the probability of a unique- event? What factors would you consider?
-
Problem 2 [20pt] Consider the following Java code: public class BankAccount { public double balance; public BankAccount () ( balance = 0.0; } public void withdraw (double amount) { balance -= amount;...
-
How would you arrange two flat circular coils so that their mutual inductance was? (a) Greatest, (b) Least (without separating them by a great distance)?
-
Identify and summarize the most important models and concepts of employee motivation.
-
A country has two regions, the North and the South, which are identical in all respects except the hourly wage and the number of workers. The demand for labor in each region is: (a) What is the wage...
-
Determine whether the statement is true or false. If it is true, explain why. If it is false, explain why or give an example that disproves the statement. For any vectors u and v in V 3 , u v = v u.
-
The anchor bolt was pulled out of the concrete wall and the failure surface formed part of a frustum and cylinder. This indicates a shear failure occurred along the cylinder BC and tension failure...
-
Karen Most has a federal tax levy of $2,100.50 against her. If Most is single with two personal exemptions and had a take-home pay of $499.00 this week, how much would her employer take from her pay...
-
Door Dash Economic Growth and Stability Identify the general economic conditions of the country, region, state, or local area where the firm's target customers are located. How are these economic...
-
You are hired as a data analyst to prepare a short report (1500 words) that examines the annual dividend returns for Coca-Cola shares between 2001 and 2013 using the data contained in the spreadsheet...
-
To which complexity class does the following algorithm belong? public static void mystery3 (List list) { for (int i = 0; i < list.size () 1; i += 2) { String first = list.remove (i); list.add (i + 1,...
-
To which complexity class does the following algorithm belong? public static void mystery4 (List list) { for (int i = 0; i < list.size () 1; i += 2) { %3D String first list.get (i); !! list.set (i,...
-
Spend some time looking at the Web site for 3 Day Startup. How do Startup Weekend and 3 Day Startup compare? Are both equally suited for college student entrepreneurs?
-
Interest expense on bonds payable should be recorded in a debt service fund a. At the end of the fiscal period if the interest due date does not coincide with the end of the fiscal period. b. When...
-
Which of the following funds of a governmental unit uses the same basis of accounting as an enterprise fund? a. Special revenue b. Internal service c. Permanent fund d. Capital projects
-
Why might companies and investment funds engage in greenwashing?
-
What are the main differences between a linear economy and a circular economy?
-
What do we mean by the term carbon footprint and what are its two components?
-
Tarass Inc. is an accrual-method calendar-year corporation. Tarass, Inc. did not qualify for the domestic production activities deduction. The following information has been provided about the...
-
Use translations to graph f. f(x) = x-/2 +1
-
What type of relationship cant be stored in a relational database? Why?
-
Identify at least three reasons an organization might analyze historical sales data stored in its database.
-
Which of the following characters can be used in a table name? a. b. ( c. % d. !
-
A friend owes you $500 in 1 year from now, and then $1000 2 years from now. Both loans are at 5%. If you want to replace both of these loans with ONE PAYMENT NOW, how much would your friend give you ?
-
If the amount of retained earnings at the beginning of the year was $ 3 0 , 0 0 0 , and $ 1 2 , 0 0 0 in dividends is paid during the year, calculate net income for the year.
-
On January 2, 20Y4, Whitworth Company acquired 33% of the outstanding stock of Aloof Company for $330,000. For the year ended December 31, 20Y4, Aloof Company earned income of $86,000 and paid...
Study smarter with the SolutionInn App