Hello Everyone.
Iam in need of an algorithm were i can fetch data of one particlar student from a .csv file and write it in another .txt file that is empty. Note that the .csv file is the one that has all the data and i need to move just once full student deatils from the .csv file to the .txt file that has no data in it. Let me explain furthure. below is a .csv file
101, Helen Scott, 2003, Beginner, 1, 1, 2, 2, 3,
102, James Jackson, 2004, Amature, 2, 2, 3, 3, 4,
103, Tim Moore, 2005, Novice, 3, 4, 3, 3, 4,
104, Tom Smith, 2004, Expert, 4, 5, 3, 5, 4,
105, Jo Black, 2004, Amature, 4, 3, 2, 2, 1,
106, Mary Brown, 2001, Novice, 4, 4, 3, 3, 4,
107, John Black, 2006, Beginner, 1, 1, 1, 1, 2,
108, Mary Blue, 2005, Amature, 2, 2, 4, 3, 3,
109, Jonney Depp, 2007, Amature, 3, 3, 4, 2, 2,
110, Mary Black, 2005, Novice, 4, 2, 3, 3, 4,
Now i just need to get full details of one particular student with everything(Name, id, year etc...). There is no input command needed here...
Below are 3 files,
1) the main file(The main file that contains both the .csv and .txt)
2) the XboxCompetetion file(That stores all the attributes of the student)
3) and the CompetitorList file(This is where i have the read and write file code and this is where i want to put that algorithm). I will just put the relevant codes so as not to make it confusing
The Main File
public class Main {
public static void main(String[] args) {
Manager sm = new Manager();
sm.run();
CompetitorList sl = new CompetitorList();
sl.readFile("XboxList.csv");
String report = sl.getTableOfXboxCompetetions();
sl.writeToFile("XboxResults.txt", report);
}
}
The XboxCompetetion file
public class XboxCompetetion {
private int competitorNumber;
private Name competitorName;
private int year;
private String competetionLevel;
private int [] score;
public XboxCompetetion(int cNumber, Name cName, int year, String cLevel, int[] score)
{
competitorNumber = cNumber;
competitorName = cName;
this.year = year;
competetionLevel = cLevel;
this.score = score;
}
The CompetitorList file
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class CompetitorList {
private ArrayList<XboxCompetetion> CompetitorList;
public XboxCompetetion Comp;
public CompetitorList() {
CompetitorList = new ArrayList<XboxCompetetion> ();
}
public void add(XboxCompetetion s) {
CompetitorList.add(s);
}
public void writeToFile(String filename, String report) {
FileWriter fw;
try {
fw = new FileWriter(filename);
fw.write("The report\n")
}
}
public void readFile(String filename) {
try {
File f = new File(filename);
Scanner scanner = new Scanner(f);
while (scanner.hasNextLine()) {
String inputLine = scanner.nextLine();
if (inputLine.length() != 0) {
processLine(inputLine);
}
}
}
catch (FileNotFoundException fnf){
System.out.println( filename + " not found ");
System.exit(0);
}
}
private void processLine(String line) {
try {
String parts [] = line.split(",");
String id = parts[0];
int number = Integer.parseInt(id);
Name name = new Name(parts[1]);
String yearNum = parts[2];
yearNum = yearNum.trim();
int year = Integer.parseInt(yearNum);
String level = parts[3];
int scoreLength = parts.length - 4;
int scores[] = new int[scoreLength];
System.arraycopy(parts, 4, scores, 0, scoreLength);
XboxCompetetion s = new XboxCompetetion(number, name, year, level, scores);
this.add(s);
}
}
Thank you for whatever help i can get.