So I'm currently making a code right now that searches through arraylists and prints out the largest one. This code prompts the user for BankAccount names and how much money the account has. Currently I've run into the problem of not knowing how to search through arraylists for the biggest number. I also don't know how to compare each balance to the maxBalance. Any help is appreciated, Thanks.
import java.io.*;
import java.util.*;
import java.text.*;
public class Project43Tester
{
public static void main(String args[])
{
NumberFormat formatter = NumberFormat.getNumberInstance( );
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String name;
ArrayList <String> aryLst = new ArrayList<String>();
do
{
Scanner kbReader = new Scanner(System.in);
System.out.print("Please enter the name to whom the account belongs.(\"Exit\" to abort)");
name = kbReader.nextLine( );
if( !name.equalsIgnoreCase("EXIT") )
{
System.out.print("Please enter the amount of the deposit. ");
double amount = kbReader.nextDouble();
System.out.println(" ");
ArrayList <String> BankAccount = new <String> ArrayList();
AryLst.add(BankAccount);
}
}while(!name.equalsIgnoreCase("EXIT"));
Search aryList and print out the name and amount of the largest bank account
BankAccount ba = //get first account in the list
double maxBalance = ba.balance;
String maxName = ba.name;
for(int j = 1; j < aryLst.size( ); j++)
{
?
? Step through the remaining objects and decide which one has
largest balance (compare each balance to maxBalance)
?
}
System.out.println(" ");
System.out.println("The account with the largest balance belongs to " + maxName + ".");
System.out.println("The amount that the account contains is $" + formatter.format(maxBalance) + ".");
}
}