NaoDesu

SystemData

Feb 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package resources;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileReader;
  6. import java.util.ArrayList;
  7. import java.util.Iterator;
  8. import java.util.Scanner;
  9.  
  10. import resources.Item;
  11. import resources.SystemData;
  12.  
  13. public class SystemData {
  14.     //This class for display pau menu list
  15.     private Scanner input;
  16.     private ArrayList<Item> itemList = new ArrayList<Item>();
  17.    
  18.     public SystemData(){ //default constructor
  19.         getItems();
  20.     }
  21.    
  22.     public void getItems(){
  23.         try {
  24.             //get file
  25.             input = new Scanner(new BufferedReader(new FileReader("item.txt")));
  26.             input.nextLine();
  27.             //store all itemlist in arraylist
  28.             while (input.hasNext()) {
  29.                 String temp[] = input.nextLine().split(","); //split this nextline of temp
  30.                 Item item = new Item(temp[0],temp[1],temp[2], temp[3], temp[4]); //get info
  31.                 itemList.add(item); //add in itemlist memory
  32.             }
  33.         } catch (FileNotFoundException error) {
  34.             System.out.println("File not found!"); //print warning but still can running
  35.             error.printStackTrace();
  36.         }
  37.     }
  38.    
  39.     public void viewItem(){ //method for view pau list
  40.    
  41.     //print menu
  42.     System.out.println("================= PAU =================");
  43.     //create arraylist loop
  44.     for(Iterator<Item> i = itemList.iterator(); i.hasNext(); ) {
  45.         Item item = i.next(); //create item object
  46.         if(item.getType().equals("Pau")){ //if the item type is pau then print pau list only
  47.             System.out.println(item.getItemID() + "   "+ item.getName() + "   RM" + item.getPrice() + "    " + item.getDesc());
  48.             System.out.println();
  49.             }
  50.     }
  51.     System.out.println();
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment