Advertisement
tuldok89

Tokenizer

Sep 18th, 2011
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.34 KB | None | 0 0
  1. // Coded By Alvin Tabontabon
  2. // BSIT
  3.  
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class cashieringInJava {
  8.  
  9.     public static BufferedReader br = new BufferedReader(new InputStreamReader(
  10.             System.in));
  11.  
  12.     public static void main(String[] args) throws IOException {
  13.  
  14.         try {
  15.             File myFile = new File("employee.txt");
  16.             if (myFile.exists()) {
  17.                 getData();
  18.                 dtr();
  19.             } else
  20.                 System.out.println("Not Found!");
  21.         } catch (NullPointerException npe) {
  22.             System.out.print("");
  23.         }
  24.     }
  25.  
  26.     public static void dtr() throws IOException {
  27.         File myDTR = new File("dtr.txt");
  28.         System.out.println();
  29.  
  30.         if (myDTR.exists()) {
  31.             String[] day = { "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY",
  32.                     "FRIDAY" };
  33.             BufferedWriter bw = new BufferedWriter(new FileWriter(myDTR));
  34.  
  35.             for (int i = 0; i < day.length; i++) {
  36.                 System.out.print("Enter time-in for " + day[i] + ": ");
  37.                 bw.write(day[i] + " " + br.readLine());
  38.  
  39.                 System.out.print("Enter time-out for " + day[i] + ": ");
  40.                 bw.write(" TO " + br.readLine());
  41.                 bw.newLine();
  42.                 System.out.println();
  43.             }
  44.             bw.close();
  45.         } else
  46.             System.out.println("File Not Found!");
  47.     }
  48.  
  49.     public static void getData() throws IOException {
  50.  
  51.         System.out.print("Enter employee code: ");
  52.         String empCod = br.readLine();
  53.         Vector<String> v = new Vector<String>();
  54.  
  55.         int x = 0, a = 0;
  56.         String[] temp = new String[3];
  57.  
  58.         FileInputStream fis = new FileInputStream("employee.txt");
  59.         InputStreamReader isr = new InputStreamReader(fis);
  60.         BufferedReader br = new BufferedReader(isr);
  61.  
  62.         String str = "";
  63.         String strData;
  64.  
  65.         try {
  66.             while (str != null) {
  67.                 str = br.readLine();
  68.                 StringTokenizer st = new StringTokenizer(str, ",");
  69.  
  70.                 while (st.hasMoreTokens()) {
  71.                     strData = st.nextToken();
  72.                     v.add(x, strData);
  73.  
  74.                     if (v.elementAt(x).equals(empCod)) {
  75.                         while (strData != null) {
  76.                             temp[a] = strData;
  77.                             a++;
  78.                             strData = st.nextToken();
  79.  
  80.                             if (a == 2) {
  81.                                 System.out.println("Employee Code: " + temp[0]);
  82.                                 System.out.println("Employee Name: " + temp[1]);
  83.                                 System.out.println("Salary Level: " + strData);
  84.                             }
  85.                         }
  86.                     }
  87.                 }
  88.                 x += 1;
  89.                 if (x == 4) {
  90.                     System.out.println("Record Not Found!");
  91.                 }
  92.             }
  93.         } catch (NoSuchElementException nsee) {
  94.             System.out.print("");
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement