java liest aus der csv-Datei und speichert die Informationen in ArrayList <class>
Ich bin ein Java-Neuling und ich brauche Hilfe
so hier ist meine Hauptmethode:
RegistrationMethods dmv = new RegistrationMethods();
ArrayList<CarOwner> ItState = new ArrayList<CarOwner>();
dmv.processTextToArrayList(ItState);
und ich habe eine Klasse namensCarOwner
und es hat Getter und Setter fürfirstName, lastName, license, month, year
Instanzvariablen.
Und das ist mein Methodenheader fürprocessTextToArrayList
Methode
public void processTextToArrayList(ArrayList<CarOwner> inList) throws IOException
diese Methode soll neues @ hinzufügCarOwner
Objekte zuminList CarOwner
collection übergeben. Für jede Zeile der csv-Datei wird einCarOwner
Objekt wird zu @ hinzugefüinList
.
Ich muss von der CSV-Datei in die Array-Liste lesen. Meine CSV-Datei enthält so etwas wie:
Bunny Bugs ACB-123 5 2013
Bunny Honey DEF-456 9 2013
Bunny Lola GHI-789 3 2014
wie codiere ich das mit while-Schleife?
bearbeiten
eine CarOwner-Klasse ist:
public class CarOwner extends Citizen implements CarOwnerInterface, Serializable
{
private String license;
private int month, year;
public CarOwner()
{
super();
license = "Not Assigned";
month = 0;
year = 0;
}
public CarOwner(String inFirst, String inLast, String inLicense, int inMonth, int inYear)
{
super(inFirst, inLast);
license = inLicense;
month = inMonth;
year = inYear;
}
public void setLicense(String inLicense)
{
license = inLicense;
}
public String getLicense()
{
return license;
}
public void setMonth(int inMonth)
{
month = inMonth;
}
public int getMonth()
{
return month;
}
public void setYear(int inYear)
{
year = inYear;
}
public int getYear()
{
return year;
}
public int compareTo(Object o)
{
if ((o != null ) && (o instanceof CarOwner))
{
CarOwner otherOwner = (CarOwner) o;
if (otherOwner.compareTo(getYear()) > 0)
return -1;
else if (otherOwner.compareTo(getYear()) < 0)
return 1;
else if (otherOwner.equals(getYear()))
if (otherOwner.compareTo(getMonth()) > 0)
return -1;
else if (otherOwner.compareTo(getMonth()) < 0)
return 1;
else if (otherOwner.equals(getMonth()))
return 0;
}
return -1;
}
}
und meine Bürgerklasse ist auch:
public class Citizen implements CitizenInterface, Serializable
{
private String firstName, lastName;
public Citizen()
{
firstName = "No Name";
lastName = "No Name";
}
public Citizen(String inFirstName, String inLastName)
{
firstName = inFirstName;
lastName = inLastName;
}
public void setFirstName(String inFirst)
{
firstName = inFirst;
}
public String getFirstName()
{
return firstName;
}
public void setLastName(String inLast)
{
lastName = inLast;
}
public String getLastName()
{
return lastName;
}
public String toString()
{
String str;
str = firstName + " " + lastName;
return str;
}