Advertisement
Guest User

Untitled

a guest
Jan 13th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. public class Magazine {
  6.  
  7.     private String MagazineName;
  8.     private String Publisher;
  9.     private String Frequency;
  10.     private String City;
  11.     private String objectName = "mg" + loopCount;
  12.     private int Distribution;
  13.     private static int loopCount = 0;
  14.  
  15.     static ArrayList<String> al = new ArrayList<String>(); // Consists of lines of the text file
  16.     static ArrayList<Magazine> bl = new ArrayList<Magazine>(); // Consists of Magazine objects
  17.  
  18.     private static void readData() throws FileNotFoundException {
  19.         java.io.File file = new java.io.File(
  20.                 "/Users/henrydang/Desktop/Zines.txt");
  21.         Scanner sc = new Scanner(file);
  22.         while (sc.hasNext()) {
  23.             sc.useDelimiter("\\n");
  24.             String line = sc.next();
  25.             System.out.println(line);
  26.             al.add(line);
  27.             Magazine objectName;
  28.  
  29.             for (int i = 0; i < al.size(); i++) {
  30.                 String result[] = al.get(i).split("#");
  31.                 for (int j = 0; j < result.length; j++) {
  32.                     System.out.println(result[0] + "1 " + result[1] + "2 " +  result[2] + "3 " +  result[3] + "4 "+  result[4]);
  33.                     int num = Integer.parseInt(result[4]);
  34.                    
  35.                     objectName = new Magazine();
  36.                     objectName.setMagazine(result[0]);
  37.                     objectName.setPublisher(result[1]);
  38.                     objectName.setFrequency(result[2]);
  39.                     objectName.setCity(result[3]);
  40.                     objectName.setDistribution(num);
  41.                     bl.add(objectName);            
  42.                 }
  43.                
  44.             }
  45.             loopCount++;
  46.             sc.close();
  47.  
  48.         }
  49.     }
  50.  
  51.     public Magazine() {
  52.  
  53.     }
  54.  
  55.     public void setMagazine(String name) {
  56.         this.MagazineName = name;
  57.     }
  58.  
  59.     public void setPublisher(String name) {
  60.         this.Publisher = name;
  61.     }
  62.  
  63.     public void setFrequency(String name) {
  64.         this.Frequency = name;
  65.     }
  66.  
  67.     public void setCity(String name) {
  68.         this.City = name;
  69.     }
  70.  
  71.     public void setDistribution(int num) {
  72.         this.Distribution = num;
  73.     }
  74.  
  75.     public String getMagazine() {
  76.         return MagazineName;
  77.     }
  78.  
  79.     public String getPublisher() {
  80.         return Publisher;
  81.     }
  82.  
  83.     public String getFrequency() {
  84.         return Frequency;
  85.     }
  86.  
  87.     public String getCity() {
  88.         return City;
  89.     }
  90.  
  91.     public int getDistribution() {
  92.         return Distribution;
  93.     }
  94.  
  95.     public static void main(String args[]) throws FileNotFoundException {
  96.         readData();
  97.     }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement