package books;
import java.awt.List;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class Book implements Comparable<Book>{
private String title;
private String author;
private int year;
public Book(String title, String author, int year){
this.title = title;
this.author = author;
this.year = year;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public int getYear() {
return year;
}
@Override
public String toString() {
return title + author + "("+ year + ")";
}
public static void getList(String file) throws IOException {
try {
ArrayList<Book> books= new ArrayList<Book>();
FileReader fr = new FileReader (file);
BufferedReader br = new BufferedReader(fr);
String line;
while((line=br.readLine())!=null) {
String [] entries =line.split(",");
//int [] entrie=line.split(",");
Book book = new Book( title[0], author [1], year[2]);
System.out.println(line);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main( String [] args ) throws IOException {
getList("books (2).csv");
}
I couldn't find the answer so maybe you guys could help me out but I am trying to separate the list of book titles, authors, and the year and then arrange them alphabetically. Im trying to get them to an array but I don't think that I am using the constructor correctly or something. Do you have any ideas?