Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8973459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:27:07+00:00 2026-06-15T18:27:07+00:00

I’ve been working at this for a couple hours now and I feel (I

  • 0

I’ve been working at this for a couple hours now and I feel (I hope) I’m right on the verge of figuring it out. This program reads in a bunch of values from an external file and places them in an array of objects which seems to be working just fine.

The Objects properties are:
Bank Account #
Customer Name
Bank Account Balance

1. I can output them in order of Account # (That’s how their read in from the file, no sorting is necessary)

2. I’ve setup a method from implementing Comparable to sort by Bank Account Balance and it’s working fine.

3. I need a second sort method, to sort by Customer Name.
– The problem I’m having with this is based on the research I’ve done and what I’ve tried I’ve come to the conclusion that the only way to make this work will be to build my own Comparable Objects (sorry if my terminology is skewed.) I’ve attempted this as well multiple times with both Java Doc and some similar questions on SE.

When all is said and done I’m going to throw some Listeners into my checkbox group to allow the user to toggle the different sort methods.

Here’s the chunks i’m working on:

 public class bankAccounts implements Comparable<bankAccounts> {
/* PRIVATE FIELDS HERE, FOLLOWED BY TYPICAL GET AND SET METHODS */

 /*SORTS BY ACCOUNT BALANCE WORKING GREAT*/
 public int compareTo(bankAccounts b)   {
    if (accountBalance < b.accountBalance)
    {
        return -1;
    }
    if (accountBalance > b.accountBalance)  {
        return 1;
    }
    return 0;
}


       /* BEGIN SNIPPET OF MAIN CLASS */


      /*METHOD I CALL FROM MAIN CLASS, SORTS BY BALANCE ^^ AS SEEN ABOVE */
Arrays.sort(retrievedAccounts);
for (int i=0; i<retrievedAccounts.length; i++)  {
    String resultFull = Integer.toString(retrievedAccounts[i].getAccountNumber()) + retrievedAccounts[i].getAccountLastName() + Double.toString(retrievedAccounts[i].getAccountBalance());
        box.append(resultFull + "\n");
}

/* NORMAL METHOD WHICH OUTPUTS IN ORDER OF ACCOUNT NUMBER, NO SORTING HAPPENING HERE */
        for(int x = 0; x < retrievedAccounts.length; ++x)
{
    String resultFull=Integer.toString(retrievedAccounts[x].getAccountNumber()) + retrievedAccounts[x].getAccountLastName() + Double.toString(retrievedAccounts[x].getAccountBalance());
    box.append("\n\n\n" + resultFull + "\n\n");
} 

I’m hoping someone will have some insight towards a next step which might allow me to finish this up. If you have suggestions to take this a completely different direction I’m open to that as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:27:08+00:00Added an answer on June 15, 2026 at 6:27 pm

    This is an idea haven’t tested.

    Create a another private method to store compareType

    public class bankAccounts implements Comparable<bankAccounts> {
    
    private int compareType = 0; // 0 - compare by balance 1-compare by name
    

    In your compare method

    public int compareTo(bankAccounts b)   {
    if(this.compareType == 0){
    if (accountBalance < b.accountBalance)
    {
        return -1;
    }
    if (accountBalance > b.accountBalance)  {
        return 1;
    }
    return 0;
    }else{
     return customerName.compareTo(b.customerName)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.