/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package lab2stuff; import java.util.Scanner; import java.io.*; /** * Testing class * @author jcmt */ public class Lab2stuff { /** * @param args the command line arguments */ public static void main(String[] args) { Library mylib = new Library(); Person me = new Person(); Employee you = new Employee("Ali","Smith","TX",76010, 4); Scanner inF = new Scanner(System.in); System.out.println("Trying to assign file"); File inFile = new File("src/lab2stuff/info.txt"); //File inFile = new File("info.txt"); if (inFile.exists()) { System.out.println(inFile); try { inF = new Scanner(inFile); } catch (FileNotFoundException f) { System.out.println("Please enter all data from the keyboard"); } } else { System.out.println("File doesn't exist"); System.out.println("Please enter all data from the keyboard"); } int zip = inF.nextInt(); String first = inF.next(); String last = inF.next(); System.out.println(zip + " " + first + " " + last); while (inF.hasNext()) { String line = inF.nextLine(); if (line.startsWith("Item:")) { Book bnew = readItemFromFile(inF); } else if (line.startsWith("Patron:")) { Patron pnew = readPatronFromFile(inF); } else if (line.startsWith("Employee:")) { Employee enew = readEmployeeFromFile(inF); } else if (line.startsWith("//")) { System.out.println("File comment - "+ line); } } you.setAge(40); // Get user's choice of action //int userin = menuChoices(); /* System.out.println("Default Age you:"+ you.getAge()); you.setAge(15); System.out.println("After setAge(15) you:"+ you.getAge()); me.setAge(-42); System.out.println("After setAge(-42):"+ me.getAge()); //me.age = -42; System.out.println("After age(-42):"+ me.getAge()); */ /** * Implement user's choice */ } public static int menuChoices() { System.out.println("Please choose a library function by the number:"); System.out.println("1. Add a new book to the library"); System.out.println("3. Check out a book from the library"); Scanner in = new Scanner(System.in); int n = in.nextInt(); return n; } public static Book readItemFromFile(Scanner inF) { Book bnew = new Book(); bnew.setiSBN(inF.next()); System.out.println(" Read ISBN of "+bnew.getiSBN()); return bnew; } public static Patron readPatronFromFile(Scanner inF) { Patron pnew = new Patron(); pnew.setFirst(inF.next()); System.out.println(" Read first name of "+pnew.getFirst()); return pnew; } public static Employee readEmployeeFromFile(Scanner inF) { Employee enew = new Employee(); enew.setLast(inF.next()); System.out.println(" Read last name of "+enew.getLast()); return enew; } }