Dietel10004 How to Program In Java R IN Dietal & Dietal Prentice Hall 06-09-08
Flanag0204 Java In a Nutshell C OUT David Flanagan O'Reilly 03-06-20
END
99100452 John Smith #5 Hillview Drive, Tunapuna UnderGrad 5
02154632 Chris Chami #16 Insame Lane, St. Anns Lecturer 0
END
Data are separated by tabs
Expand|Select|Wrap|Line Numbers
- public class Book{
- private String ISBN;
- private String title;
- private String type;
- private String status;
- private String author;
- private String publisher;
- private String dateborrowed;
- public Book( String isb, String tit, String typ, String sta, String aut, String pub, String dateb )
- {
- ISBN = isb;
- title = tit;
- type = typ;
- status = sta;
- author = aut;
- publisher = pub;
- dateborrowed = dateb;
- }
- public String toString(){
- String str;
- str = "ISBN" + ISBN+"\n"+
- "title " + title+"\n"+
- "type " + type+"\n"+
- "status " + status+"\n"+
- "author " + author+"\n"+
- "publisher " + publisher+"\n"+
- "dateborrowed " + dateborrowed+"\n";
- return str;
- }
- }//End Book class
Expand|Select|Wrap|Line Numbers
- import java.io.*;
- import java.util.*;
- public class Test1{
- static Book[] book = new Book [ 100 ];
- public static void main(String [] args)throws IOException{
- Scanner input = new Scanner(new FileReader("db.txt"));
- input.useDelimiter("\t"); //Set scanner to break on tabs
- int a = 0;
- String x = input.next();
- while(!(x.equals("END"))){
- book[a] = new Book(x, input.next(),input.next(),input.next(),input.next(),input.next(),input.next()); //noSuchElementException
- a++;
- x = input.next();
- }
- for(int i = 0; i < a; i++){
- System.out.println(book[i].toString());
- }
- }//end class main
- }//end class test