Associate
Still got no public properties? Check my earlier post.
I think the setAuthor type mismatch, while incorrect, is a red herring. It will never be called.
that is a very good point, DOH!
Still got no public properties? Check my earlier post.
I think the setAuthor type mismatch, while incorrect, is a red herring. It will never be called.
/* -------------------- Saving and Loading Text -------------------- */
public void saveTextBook(String fn) throws IOException {
PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(fn)));
outfile.println(books.size());
for (Book b : books) {
outfile.println(b.getTitle());
outfile.println(b.getPrice());
outfile.println(b.getAuthor().getName());
}
outfile.close();
}
public void saveTextAuthor(String fn) throws IOException {
PrintWriter outfile = new PrintWriter(new OutputStreamWriter(
new FileOutputStream(fn)));
outfile.println(authors.size());
for (Author a : authors) {
outfile.println(a.getName());
outfile.println(a.getNationality());
}
outfile.close();
}
public void loadTextBook(String fn) throws IOException {
Scanner infile = new Scanner(new InputStreamReader(new FileInputStream(
fn)));
int num = infile.nextInt();
infile.nextLine();
for (int i = 0; i < num; i++) {
String t = infile.nextLine();
double p = infile.nextDouble();
}
infile.close();
}
public void loadTextAuthor(String fn) throws IOException {
Scanner infile = new Scanner(new InputStreamReader(new FileInputStream(
fn)));
int num = infile.nextInt();
infile.nextLine();
for (int i = 0; i < num; i++) {
String n = infile.nextLine();
String nat = infile.nextLine();
}
infile.close();
}
Have you tried stepping through it with the debugger?
On first glance, assuming the file reading works, it's reading both into local string variables and then doing nothing with them before looping round again.
Presumable you need to instantiate / clear the lists and add new Author and Book objects to them which are created from these locals.
public void loadTextAuthor(String fn) throws IOException {
Scanner infile = new Scanner(new InputStreamReader(new FileInputStream(
fn)));
int num = infile.nextInt();
infile.nextLine();
for (int i = 0; i < num; i++) {
String n = infile.nextLine();
String nat = infile.nextLine();
}
infile.close();
}