Skip to content
Snippets Groups Projects
Select Git revision
  • 9d4991fe876c6f060186788cb0865b27de117b71
  • class default protected
2 results

ProgrammingAssignment1.ipynb

Blame
  • Forked from Zeynep Hakguder / csce478
    Source project has a limited visibility.
    DataConverter.java 4.10 KiB
    package assignment2;
    
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    import com.thoughtworks.xstream.*;
    
    public class DataConverter {
    	
    	private Customer[] customerArray;
    	private Venues[] venuesArray;
    	private Product[] productArray;
    
    	public void readPerson() {
    		String fileName = "data/Person.dat";
    		Scanner s = null;
    		try {
    			s = new Scanner(new File(fileName));
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		}
    		
    		int size = Integer.parseInt(s.nextLine());
    		Person[] personArray;
    		personArray = new Person[size];
    		
    		for(int i=0;i<size;i++){
    			String personTemp = s.nextLine();
    			String[] parts = personTemp.split(";");
    			String personCode = parts[0];
    			String name = parts[1];
    			String address = parts[2];
    			String eMail = parts[3];
    			personArray[i] = new Person(personCode,name,address,eMail);
    		}
    		s.close();
    	}
    
    	public void readVenues() {
    		String fileName = "data/Venues.dat";
    		Scanner s = null;
    		try {
    			s = new Scanner(new File(fileName));
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		}
    		
    		int size = Integer.parseInt(s.nextLine());
    		
    		venuesArray = new Venues[size];
    		
    		for(int i=0;i<size;i++){
    			String venueTemp = s.nextLine();
    			String[] parts = venueTemp.split(";");
    			String venueCode = parts[0];
    			String name = parts[1];
    			String address = parts[2];
    			int capacity = Integer.parseInt(parts[3]);
    			venuesArray[i] = new Venues(venueCode,name,address,capacity);
    		}
    		s.close();
    	}
    
    	public void readCustomer() {
    		String fileName = "data/Customers.dat";
    		Scanner s = null;
    		try {
    			s = new Scanner(new File(fileName));
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		}
    		
    		int size = Integer.parseInt(s.nextLine());
    		//instantiation up top for testing implementation
    		customerArray = new Customer[size];
    		for(int i=0;i<size;i++){
    			String customerTemp = s.nextLine();
    			String[] parts = customerTemp.split(";");
    			String customerCode = parts[0];
    			String type = parts[1];
    			String primaryContact = parts[2];
    			String name = parts[3];
    			String address = parts[4];
    			customerArray[i] = new Customer(customerCode,type, primaryContact, name, address);
    		}
    		s.close();
    	}
    	public void readProduct(){
    		String fileName = "data/Products.dat";
    		Scanner s = null;
    		try {
    			s = new Scanner(new File(fileName));
    		} catch (FileNotFoundException e) {
    			e.printStackTrace();
    		}
    		
    		int size = Integer.parseInt(s.nextLine());
    		productArray = new Product[size];
    		
    		for(int i=0;i<size;i++) {
    			String productTemp = s.nextLine();
    			String[] parts = productTemp.split(";");
    			String code = parts[0];
    			String type = parts[1];
    
    			if(type.equals("SR")) {
    				String name = parts[2];
    				double cost = Double.parseDouble(parts[3]);
    				productArray[i] = new Refreshments(code,type, name, cost);
    			}
    			else if(type.equals("SP")) {
    				String venueCode = parts[2];
    				double hourlyFee = Double.parseDouble(parts[3]);
    				productArray[i] = new ParkingPass(code,type,venueCode,hourlyFee);
    			}
    			else if(type.equals("TG")) {
    				String venueCode = parts[2];
    				String dateTime = parts[3];
    				String team1 = parts[4];
    				String team2 = parts[5];
    				double pricePerUnit = Double.parseDouble(parts[6]);
    				productArray[i] = new GameTicket(code,type,venueCode, dateTime, team1, team2, pricePerUnit);
    			}
    			else if(type.equals("TS")) {
    				String team = parts[2];
    				String startDate = parts[3];
    				String endDate = parts[4];
    				double cost = Double.parseDouble(parts[5]);
    				productArray[i] = new SeasonPass(code, type, team, startDate,endDate,cost);
    			}
    			else if(type.equals("SL")) {
    				String ticketCode = parts[2];
    				double licenseFee = Double.parseDouble(parts[3]);
    				productArray[i] = new PSL(code, type, ticketCode, licenseFee);
    			}
    			
    
    		}
    		s.close();
    	}
    
    	private String serializeObjects(Object obj) {
    		XStream xstream = new XStream();
    		String xml = null;
    		return xml;
    	}
    	
    	private String serializeObjects() {
    		//trying to serialize and output files related to products
    		for(int i=0;i<customerArray.length;i++) {
    			
    		}
    			
    		return File;
    	}
    	
    	public static void main(String args[]) {
    		serializeObjects();
    	}
    
    }