Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Magazine {
- private String MagazineName;
- private String Publisher;
- private String Frequency;
- private String City;
- private String objectName = "mg" + loopCount;
- private int Distribution;
- private static int loopCount = 0;
- static ArrayList<String> al = new ArrayList<String>(); // Consists of lines of the text file
- static ArrayList<Magazine> bl = new ArrayList<Magazine>(); // Consists of Magazine objects
- private static void readData() throws FileNotFoundException {
- java.io.File file = new java.io.File(
- "/Users/henrydang/Desktop/Zines.txt");
- Scanner sc = new Scanner(file);
- while (sc.hasNext()) {
- sc.useDelimiter("\\n");
- String line = sc.next();
- System.out.println(line);
- al.add(line);
- Magazine objectName;
- for (int i = 0; i < al.size(); i++) {
- String result[] = al.get(i).split("#");
- for (int j = 0; j < result.length; j++) {
- System.out.println(result[0] + "1 " + result[1] + "2 " + result[2] + "3 " + result[3] + "4 "+ result[4]);
- int num = Integer.parseInt(result[4]);
- objectName = new Magazine();
- objectName.setMagazine(result[0]);
- objectName.setPublisher(result[1]);
- objectName.setFrequency(result[2]);
- objectName.setCity(result[3]);
- objectName.setDistribution(num);
- bl.add(objectName);
- }
- }
- loopCount++;
- sc.close();
- }
- }
- public Magazine() {
- }
- public void setMagazine(String name) {
- this.MagazineName = name;
- }
- public void setPublisher(String name) {
- this.Publisher = name;
- }
- public void setFrequency(String name) {
- this.Frequency = name;
- }
- public void setCity(String name) {
- this.City = name;
- }
- public void setDistribution(int num) {
- this.Distribution = num;
- }
- public String getMagazine() {
- return MagazineName;
- }
- public String getPublisher() {
- return Publisher;
- }
- public String getFrequency() {
- return Frequency;
- }
- public String getCity() {
- return City;
- }
- public int getDistribution() {
- return Distribution;
- }
- public static void main(String args[]) throws FileNotFoundException {
- readData();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement