Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package resources;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.Scanner;
- import resources.Item;
- import resources.SystemData;
- public class SystemData {
- //This class for display pau menu list
- private Scanner input;
- private ArrayList<Item> itemList = new ArrayList<Item>();
- public SystemData(){ //default constructor
- getItems();
- }
- public void getItems(){
- try {
- //get file
- input = new Scanner(new BufferedReader(new FileReader("item.txt")));
- input.nextLine();
- //store all itemlist in arraylist
- while (input.hasNext()) {
- String temp[] = input.nextLine().split(","); //split this nextline of temp
- Item item = new Item(temp[0],temp[1],temp[2], temp[3], temp[4]); //get info
- itemList.add(item); //add in itemlist memory
- }
- } catch (FileNotFoundException error) {
- System.out.println("File not found!"); //print warning but still can running
- error.printStackTrace();
- }
- }
- public void viewItem(){ //method for view pau list
- //print menu
- System.out.println("================= PAU =================");
- //create arraylist loop
- for(Iterator<Item> i = itemList.iterator(); i.hasNext(); ) {
- Item item = i.next(); //create item object
- if(item.getType().equals("Pau")){ //if the item type is pau then print pau list only
- System.out.println(item.getItemID() + " "+ item.getName() + " RM" + item.getPrice() + " " + item.getDesc());
- System.out.println();
- }
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment