nextLineequalsexit done true Tries to login for the given credentials Updates

Nextlineequalsexit done true tries to login for the

This preview shows page 2 - 4 out of 7 pages.

if(stdin.nextLine().equals("exit")) done = true; } } /** * Tries to login for the given credentials. Updates the currentUser if * successful login * * @param username name of user * @param passwd password of user * @returns the currentUser */ public static User login(String username, String passwd){ if ((username == null) || (passwd == null)){ throw new IllegalArgumentException(); } for (int i = 0; i < users.size(); i++){ if (users.get(i).checkLogin(username, passwd)){ currentUser = users.get(i); return currentUser; } } return null; } /** * Reads the specified file to create and load products into the store. * Every line in the file has the format: <NAME>#<CATEGORY>#<PRICE>#<RATING> * Create new products based on the attributes specified in each line and * insert them into the products list * Order of products list should be the same as the products in the file * For any problem in reading the file print: 'Error: Cannot access file' * * @param fileName name of the file to read * @throws FileNotFoundException
Image of page 2
*/ public static void loadProducts(String fileName) throws FileNotFoundException { Scanner fileIn = null; try{ fileIn = new Scanner(new File(fileName)); String delims = "[#]"; Product tempProduct; while (fileIn.hasNext()){ String s = fileIn.nextLine(); String[] tokens = s.split(delims); String name = tokens[0]; String category = tokens[1]; int price = Integer.valueOf(tokens[2]); float rating = Float.parseFloat(tokens[3]); tempProduct = new Product(name, category, price, rating); products.add(tempProduct); } fileIn.close(); } catch (FileNotFoundException ex){ System.out.println("Error: Cannot access file"); } } /** * Reads the specified file to create and load a user into the store. * The first line in the file has the format:<NAME>#<PASSWORD>#<CREDIT> * Every other line after that is a name of a product in the user's wishlist, format:<NAME> * For any problem in reading the file print: 'Error: Cannot access file' * * @param fileName name of the file to read * @throws FileNotFoundException */ public static void loadUser(String fileName) throws FileNotFoundException{ Scanner fileIn = null; try{
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 7 pages?

  • Spring '08
  • MarvinSolomon
  • Data Structures, Login, Thomas Whitburn

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture