I'm having issues formatting an input String into an ArrayList. I commented out some of the things I've tried. Initially I tried to put the input into a string then add to arrayList.
The input is one long string:
(A,Name1,200), (A,Name1,200), (R,Name1,200), (A,Name2,900), (A,Name2,500), (A,Name3,800), (A,Name4,150), (A,Name5,850), (A,Name6,750), (A,Name7,950), (A,Name8,250), (R,Name6,750), (A,Name10,450), (A,Name11,1000)*emphasized text*
What I have so far:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
*
* @author Joshua
*/
public class HighScore {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
/**
Scanner sc = new Scanner(System.in);
String scores = sc.nextLine();
scores = scores.replace('(', '"');
scores = scores.replace('(', '"');
StringBuffer str = new StringBuffer(scores);
for (int i = 0; i < scores.length(); i++)
{
if (scores.charAt(i) == ',')
{
str.insert(i, 'H');
}
}
System.out.println(str);
*/
ArrayList<Score> list = new ArrayList<Score>();
ArrayList <Score> topscore = new ArrayList<Score>();
/**
list.add (new Score("A","1111",99999));
list.add (new Score("A","2222",88888));
list.add (new Score("A","3333",77777));
list.add (new Score("A","4444",66666));
list.add (new Score("A","5555",55555));
list.add (new Score("A","6666",44444));
list.add (new Score("R","4444",66666));
list.add (new Score("A","7777",22222));
list.add (new Score("A","8888",11111));
*/
Collections.sort(list);
//For loop to add all the high scores with 'A' as the command to the ArrayList topscore
for(Score addScore : list)
{
if (addScore.getCommand().equalsIgnoreCase("A"))
topscore.add(addScore);
}
//For loop to remove all the high scores with 'R' as the command from the ArrayList topscore
for(Score remScore : list)
{
if (remScore.getCommand().equalsIgnoreCase("R"))
for (int i = 0; i < topscore.size(); i++)
{
if (remScore.getName().equals(topscore.get(i).getName()))
if(remScore.getScoreValue() == topscore.get(i).getScoreValue())
topscore.remove(i);
}
}
//Prints the finished finalScore list
for(Score finalScore : topscore)
{
System.out.println(finalScore);
}
/**
String s[]=new String[100];
for(int i=0;i<s.length;i++)
{
s = scores.substring(1, scores.length()-1).split("\\), \\(");
}
*/
sc.close();
}
}