I am given the (books.txt AND cards.txt)
exp of book.txt: the law of power, Tolstoy, 456, false, 0
exp of cards.txt: Jeff johnson, 524-852-0000, 234, 0
I am trying to read the information and display it in the menu; however, I got stuck at line 40 trying to tokenize the info...
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class newinfo {
public static void main(String[] args, int i) {
// declaring array of 20 cards
Card[] cards = new Card[20];
// declare an array of 20 books
Book[] books = new Book[20];
// declare a file pointer and open the cards file
Scanner fileinput;
try {
fileinput = new Scanner(new File("cards.txt"));
} catch (FileNotFoundException x) {
System.out.println("Error, cards can not be found...");
return;
}
// read the next line from the file
String line = fileinput.nextLine();
try {
// declare a file pointer and open the books file
fileinput = new Scanner(new File("books.txt"));
} catch (FileNotFoundException x) {
System.out.println("Error, books.txt can not be found...");
return;
}
// tokenize the line to get the data for class variables
while(fileinput.hasNext())
{
String title = fileinput.next();
String author = fileinput.next();
int bookid = fileinput.nextInt();
books[i] = new Book(tokens[0], tokens[1], parseInt(tokens[2]), false, 0);
i++;
}
// read the next line from the file
String line = fileinput.nextLine();
// display main menu
ShowMenu();
while(command != 0)
{
ShowMenu();
}
}
}
public static void ShowMenu()
{
System.out.println();
System.out.println(" ****** Menu ******** ");
System.out.println(" 1 - Show all library Books ");
System.out.println(" 2 - Check out a book ");
System.out.println(" 3 - Check in a book ");
System.out.println(" 4 - display this menu ");
System.out.println();
System.out.println();
}
public static Card CreateCard(String name, String phone, int CardID, int BookID)
{
}
public class Card {
}
public class Book {
}

New Topic/Question
Reply




MultiQuote




|