<repo_name>SporkyMcForkinspoon/CSCE156<file_sep>/src/com/datacontainers/Value.java
package com.datacontainers;

import java.util.ArrayList;

public class Value {
	//Variable names are not ordered arbitrarily.  Changes will cause the JSON file to output in the wrong order.
	private String customerIdNumber;
	private String productIdNumber;
	private String productType;	
	private String customerType;
	private String personIdNumber;
	private String lastName;
	private String firstName;
	private String movieDate;
	private String name;
	private Address address;
	private ArrayList<String> emails;
	private String startDate;
	private String endDate;
	private String screenNumber;
	private String price;
	
	//Constructors
	
	//Customer Constructor
	public Value(String customerIdNumber, String customerType, String personIdNumber, String name, Address address) {
		super();
		this.customerIdNumber = customerIdNumber;
		this.customerType = customerType;
		this.personIdNumber = personIdNumber;
		this.name = name;
		this.address = address;
			}
	
	//Movie constructor
	public Value(String productIdNumber, String productType, String movieDate, String name, Address address, String screenNumber, String price) {
		super();
		this.productIdNumber = productIdNumber;
		this.productType = productType;
		this.movieDate = movieDate;
		this.name = name;
		this.address = address;
		this.screenNumber = screenNumber; 
		this.price = price;
	}
	
	//Parking constructor
	public Value(String productIdNumber, String productType, String price) {
		this.productIdNumber = productIdNumber;
		this.productType = productType;
		this.price = price;
	}
	
	//Person Constructor (W/ Email)
	public Value(String personIdNumber, String firstName, String lastName, Address address, ArrayList<String> emails) {
		super();
		this.personIdNumber = personIdNumber;
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
		this.emails = emails;
	}
	
	//Person Constructor (No Email)
	public Value(String personIdNumber, String firstName, String lastName, Address address) {
		super();
		this.personIdNumber = personIdNumber;
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
	}
	
	//Refreshment constructor
	public Value(String productIdNumber, String productType, String name, String price) {
		super();
		this.productIdNumber = productIdNumber;
		this.productType = productType;
		this.name = name;
		this.price = price;
	}
	
	//Season Pass constructor
	public Value(String productIdNumber, String productType, String name, String startDate, String endDate, String price) {
		super();
		this.productIdNumber = productIdNumber;
		this.productType = productType;
		this.name = name;
		this.startDate = startDate;
		this.endDate = endDate;
		this.price = price;
	}
	
	//Getter and Setter methods
	public Address getAddress() {
		return this.address;
	}
	
	public String getCustomerIdNumber () {
		return this.customerIdNumber;
	}
	public void setCustomerIdNumber (String customerIdNumber) {
		this.customerIdNumber = customerIdNumber;
	}
	
	public String getCustomerType() {
		return this.customerType;
	}
	public void setCustomerType(String customerType) {
		this.customerType = customerType;
	}
	
	public String getEndDate() {
		return this.endDate;
	}
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	
	public ArrayList<String> getEmails () {
		return this.emails;
	}
	public void setEmails (ArrayList<String> emails) {
		this.emails = emails;
	}
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public String getMovieDate() {
		return this.movieDate;
	}
	public void setMovieDate(String movieDate) {
		this.movieDate = movieDate;
	}
	
	public String getName () {
		return this.name;
	}
	public void setName (String name){
		this.name = name;
	}
	
	public String getPersonIdNumber () {
		return this.personIdNumber;
	}
	public void setPersonIdNumber (String personIdNumber) {
		this.personIdNumber = personIdNumber;
	}
	
	public String getPrice() {
		return this.price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
	
	public String getProductIdNumber () {
		return this.productIdNumber;
	}
	public void setProductIdNumber (String productIdNumber) {
		this.productIdNumber = productIdNumber;
	}
	
	public String getProductType() {
		return this.productType;
	}
	public void setProductType(String productType) {
		this.productType = productType;
	}
	

	public String getScreenNumber() {
		return this.screenNumber;
	}
	public void setScreenNumber(String screenNumber) {
		this.screenNumber = screenNumber;
	}
	
	public String getStartDate() {
		return this.startDate;
	}
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}
}<file_sep>/src/com/datacontainers/Person.java
package com.datacontainers;

import java.util.ArrayList;

public class Person {
	
	private String idNumber;
	private String firstName;
	private String lastName;
	private Address address; // Person class owns Address class as a field
	private ArrayList<String> emails;
	
	// Constructor
	public Person(String idNumber, String firstName, String lastName, Address address, ArrayList<String> emails) {
		super();
		this.idNumber = idNumber;
		this.firstName = firstName;
		this.lastName = lastName;
		this.address = address;
		this.emails = emails;
	}
	
	// Getter and Setter methods
	public String getIdNumber () {
		return this.idNumber;
	}
	
	public void setIdNumber (String idNumber) {
		this.idNumber = idNumber;
	}
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public Address getAddress() {
		return this.address;
	}
	
	public ArrayList<String> getEmails () {
		return this.emails;
	}
	
	public void setEmails (ArrayList<String> emails) {
		this.emails = emails;
	}

}
<file_sep>/src/com/fileReader/FlatFileReader.java
package com.fileReader;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import com.datacontainers.*;

public class FlatFileReader {
	
	public ArrayList<Value> readValues(String fileName) {
		Scanner sc = null;
		
		try {
			sc = new Scanner(new File(fileName));
			sc.nextLine(); // reads the number of records from the first line
			
			// This Value ArrayList stores the Value objects 
			ArrayList<Value> valueList = new ArrayList<Value>();
			
			while(sc.hasNext()) {
				String line = sc.nextLine(); // reads each line starting from 2nd line
				String data[] = line.split(",|;"); // tokenizes the line and stores in a string array 
				
				Value value = null;
				
				if (data[1].equals("M")) { //If the data[1] is "M", prepares a movie ticket product Value.
					String productIdNumber = data[0].replaceAll("^\\s+", "").trim(); //Removes all starting and ending white space from the token before passing to the variable.
					String productType = data[1].replaceAll("^\\s+", "").trim();
					String movieDate = data[2].replaceAll("^\\s+", "").trim();
					String name = data[3].replaceAll("^\\s+", "").trim();
					String street = data[4].replaceAll("^\\s+", "").trim();
					String city = data[5].replaceAll("^\\s+", "").trim();
					String state = data[6].replaceAll("^\\s+", "").trim();
					String postalCode = data[7].replaceAll("^\\s+", "").trim();
					String country = data[8].replaceAll("^\\s+", "").trim();
					String screenNumber = data[9].replaceAll("^\\s+", "").trim();
					String price = data[10].replaceAll("^\\s+", "").trim();
					
					// Creates an Address object
					Address address = new Address(street, city, state, postalCode, country);
					// Creates a movie product type Value object
					value = new Value(productIdNumber, productType, movieDate, name, address, screenNumber, price);
				}
				
				else if (data[1].equals("P")) { // "P" is for parking pass
					String productIdNumber = data[0].replaceAll("^\\s+", "").trim();
					String productType = data[1].replaceAll("^\\s+", "").trim();
					String price = data[2].replaceAll("^\\s+", "").trim();
					
					//Creates a parking product Value object
					value = new Value(productIdNumber, productType, price);
				}
				
				else if (data[1].equals("R")) { //"R" is for refreshment
					String productIdNumber = data[0].replaceAll("^\\s+", "").trim();
					String productType = data[1].replaceAll("^\\s+", "").trim();
					String name = data[2].replaceAll("^\\s+", "").trim();
					String price = data[3].replaceAll("^\\s+", "").trim();
					
					//Creates a refreshment product Value object
					value = new Value(productIdNumber, productType, name, price);
				}
				
				else if (data[1].equals("S") && data.length == 6){ //There are two "S" product types.  This deals with season passes, which always have an array length of 6.
					String productIdNumber = data[0].replaceAll("^\\s+", "").trim();
					String productType = data[1].replaceAll("^\\s+", "").trim();
					String name = data[2].replaceAll("^\\s+", "").trim();
					String startDate = data[3].replaceAll("^\\s+", "").trim();
					String endDate = data[4].replaceAll("^\\s+", "").trim();
					String price = data[5].replaceAll("^\\s+", "").trim();
					
					//Creates a season pass product Value object
					value = new Value(productIdNumber, productType, name, startDate, endDate, price);
				}
				
				// "G" and "S" are both customer types, but "S" can also be season pass.  Students always have an array length of 9.
				else if (data[1].equals("G") || (data[1].equals("S") & data.length == 9)) {
					String customerIdNumber = data[0].replaceAll("^\\s+", "").trim();
					String customerType = data[1].replaceAll("^\\s+", "").trim();
					String personIdNumber = data[2].replaceAll("^\\s+", "").trim();
					String name = data[3].replaceAll("^\\s+", "").trim();
					String street = data[4].replaceAll("^\\s+", "").trim();
					String city = data[5].replaceAll("^\\s+", "").trim();
					String state = data[6].replaceAll("^\\s+", "").trim();
					String postalCode = data[7].replaceAll("^\\s+", "").trim();
					String country = data[8].replaceAll("^\\s+", "").trim();
					
					// Creates an Address object
					Address address = new Address(street, city, state, postalCode, country);
					
					// Creates a customer type Value object
					value = new Value(customerIdNumber, customerType, personIdNumber, name, address);
				}
				
				else {
					//Any other value for data[1] will always be a person.
					//Persons can have an arbitrary number of email addresses, including none.
					String personIdNumber = data[0].replaceAll("^\\s+", "").trim();
					String lastName = data[1].replaceAll("^\\s+", "").trim();
					String firstName = data[2].replaceAll("^\\s+", "").trim();
					String street = data[3].replaceAll("^\\s+", "").trim();
					String city = data[4].replaceAll("^\\s+", "").trim();
					String state = data[5].replaceAll("^\\s+", "").trim();
					String postalCode = data[6].replaceAll("^\\s+", "").trim();
					String country = data[7].replaceAll("^\\s+", "").trim();
					if (data.length >= 9) {
						ArrayList<String> emails = new ArrayList<String>();
						for (int i = 8; i < data.length; i++) {
							emails.add(data[i].replaceAll("^\\s+", ""));
						}
						
						// Creates an Address object
						Address address = new Address(street, city, state, postalCode, country);
						
						// Creates a person type Value object (w/ email)
						value = new Value(personIdNumber, lastName, firstName, address, emails);
					}
					else {
						// Creates an Address object
						Address address = new Address(street, city, state, postalCode, country);
						//Creates a person type Value object (w/o email)
						value = new Value (personIdNumber, lastName, firstName, address);
					}
				}
				valueList.add(value); //Used at the end of the while loop, rather than at the end of each if statement.
			}
			sc.close();
			return valueList;
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}	
	}
}