package assignment2; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class DataConvereter { 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()); 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]; 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()); 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]); 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()); 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]; 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()); 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]); new Refreshments(code,type, name, cost); } else if(type.equals("SP")){ String venueCode = parts[2]; double hourlyFee = Double.parseDouble(parts[3]); 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]); 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]); new SeasonPass(code, type, team, startDate,endDate,cost); } else if(type.equals("SL")){ String ticketCode = parts[2]; double licenseFee = Double.parseDouble(parts[3]); new PSL(code, type, ticketCode, licenseFee); } } s.close(); } }