I'm trying to create an object of the "Borrower" class. I tried all combinations of parameters but it's giving me an error for everything. Not sure what is happening. The way its setup is String,int,int but when I give it in this format, it gives me error.
Here is an image of the parameter screen:
The code for the borrower class is:
import java.util.ArrayList;
public class Borrower {
private String name;
private int id;
private int age;
private ArrayList<Book> booklist;
public Borrower(String[] info) {
this.setName(info[0]);
this.setId(Integer.parseInt(info[1]));
this.setAge(Integer.parseInt(info[2]));
this.booklist = new ArrayList<Book>();
if(info.length == 5) {
this.booklist.add(new Book(info[3], info[4], ""));
} else if(info.length == 6) {
this.booklist.add(new Book(info[3], info[4], info[5]));
} else if(info.length == 7) {
this.booklist.add(new Book(info[3], info[4], ""));
this.booklist.add(new Book(info[5], info[6], ""));
} else if(info.length == 8) {
this.booklist.add(new Book(info[3], info[4], info[5]));
this.booklist.add(new Book(info[6], info[7], info[8]));
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public ArrayList<Book> getBooklist() {
return booklist;
}
public boolean addBook(Book book) {
if(this.booklist.size() < 2) {
this.booklist.add(book);
return true;
}
return false;
}
public boolean returnBook() {
if(this.booklist.size() > 0) {
this.booklist.remove(0);
return true;
}
return false;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.getName());
sb.append("," + this.getId());
sb.append("," + this.getAge());
for(Book book : booklist) {
sb.append("," + book);
}
return sb.toString();
}
}
Any help here is appreciated.
Write it this way
{"Arvind" , "1" , "2"}
Enter the above in the dialog box.
Basically {}
was the missing identifier.