Skip to main content

mapping, quick sort, quick lookup help needed

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
BLoweCLE
Offline
Joined: 2013-04-16

Greetings all,
I could use some help on a program I need to write. The link to the program's instructions is pasted below:

http://grail.cba.csuohio.edu/~matos/notes/cis-265/2013-spring/Homework/c...

Data required:
http://grail.cba.csuohio.edu/~matos/notes/cis-265/2013-spring/Homework/i...

Here is my thought.. Either created an arraylist or a treemap of Player objects and use this to created the data in the memory. A map would probably be better for sorting, but I'm not very good with them and I don't totally understand how they work. If anyone could give me a push in the right direction I would greatly appreciate it. Some of my code is pasted below:

public class IndiansLookup {

public static void main(String[] args) throws FileNotFoundException {

File file = new File("testdata.txt");
Scanner scanner = new Scanner(file);
ArrayList list = new ArrayList ();
scanner.nextLine();
while(scanner.hasNext()){
String line = scanner.nextLine();
String[] tokens = line.split(",");
list.add(makeNewPlayer(tokens));
}

System.out.println("Enter Player's Last Name: ");
Scanner scan = new Scanner(System.in);
String input=scan.next();
for(int i=0; i if(list.get(i).getLastName().compareTo(input)==0){
System.out.println("match at " + i);
}
}

}

private static Player makeNewPlayer(String[] tokens){
return new Player(Integer.parseInt(tokens[0]), tokens[1], tokens[2],
tokens[3], tokens[4], Integer.parseInt(tokens[5]), Integer.parseInt(tokens[6]),
Integer.parseInt(tokens[7]),Integer.parseInt(tokens[8]),
Integer.parseInt(tokens[9]), Integer.parseInt(tokens[10]),
Integer.parseInt(tokens[11]), Integer.parseInt(tokens[12]),
Integer.parseInt(tokens[13]), Integer.parseInt(tokens[14]),
Integer.parseInt(tokens[15]), Integer.parseInt(tokens[16]),
Double.parseDouble(tokens[17]), Double.parseDouble(tokens[18]),
Double.parseDouble(tokens[19]), Double.parseDouble(tokens[20]));
}
}

Player class:
public class Player {

private int rank = 0;
private String lastName = "";
private String firstName = "";
private String team = "";
private String position = "";
private int gamesPlayed = 0;
private int atBats = 0;
private int runs = 0;
private int hits = 0;
private int doubles = 0;
private int triples = 0;
private int homeruns = 0;
private int runsBattedIn = 0;
private int walks = 0;
private int strikeouts = 0;
private int stolenBases = 0;
private int caughtStealing = 0;
private double battingAverage = .000;
private double onBasePercentage = .000;
private double sluggingPercentage = .000;
private double onBasePlusSlugging = .000;

public Player() {

}

public Player(int rank, String lastName, String firstName,
String team, String position, int gamesPlayed,
int atBats, int runs, int hits, int doubles,
int triples, int homeruns, int runsBattedIn,
int walks, int strikeouts, int stolenBases,
int caughtStealing, double battingAverage,
double onBasePercentage, double sluggingPercentage,
double onBasePlusSlugging) {
this.rank = rank;
this.lastName = lastName;
this.firstName = firstName;
this.team = team;
this.position = position;
this.gamesPlayed = gamesPlayed;
this.atBats = atBats;
this.runs = runs;
this.hits = hits;
this.doubles = doubles;
this.triples = triples;
this.homeruns = homeruns;
this.runsBattedIn = runsBattedIn;
this.walks = walks;
this.strikeouts = strikeouts;
this.stolenBases = stolenBases;
this.caughtStealing = caughtStealing;
this.battingAverage = battingAverage;
this.onBasePercentage = onBasePercentage;
this.sluggingPercentage = sluggingPercentage;
this.onBasePlusSlugging = onBasePlusSlugging;
}

public String showData(){
return "Rank: " + this.rank + "\nLast Name: " + this.lastName + "\nFirst Name: " + this.firstName
+ "\nTeam: " + this.team + "\nPosition: " + this.position + "\nGames Played: " +
this.gamesPlayed + "\nAt Bats: " + this.atBats + "\nRuns: " + this.runs +"\nHits: "
+this.hits + "\nDoubles: " + this.doubles + "\nTriples: " + this.triples + "\nHomeruns: "
+ this.homeruns + "\nRBIs: " + this.runsBattedIn + "\nWalks: " + this.walks + "\nStrikeouts: "
+this.strikeouts + "\nStolen Bases: " + this.stolenBases + "\nCaught Stealing: "
+this.caughtStealing + "\nBatting Average: " + this.battingAverage + "\nOn Base Percentage: "
+this.onBasePercentage + "\nSlugging Percentage: " + this.sluggingPercentage + "\nOBPS: "
+this.onBasePlusSlugging;
}
//getters and setters