Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.lang.Math;
- import java.io.File;
- import java.util.ArrayList;
- import java.io.FileNotFoundException;
- //equalsIgnoreCase
- public class n00885749
- {
- public static void main(String[] args)throws FileNotFoundException {
- File data = new File(args[0]);
- ArrayList<Vehicle>vehicleList = new ArrayList<Vehicle>(0);
- ArrayList<String>vehicleDataList = new ArrayList<String>();
- try{
- Scanner input = new Scanner(data);
- input.useDelimiter("\n");
- while(input.hasNext()){
- String type = input.next();
- vehicleDataList.add(type);
- }
- }
- catch(FileNotFoundException ex){
- System.out.println(ex);
- }
- int listLength = vehicleDataList.size();
- int i;
- //System.out.println(listLength);
- for(i=0; i< vehicleDataList.size(); i++){
- //System.out.print(vehicleDataList.get(i));
- //System.out.println("-----------------------------------------------");
- if (vehicleDataList.get(i).equals("vehicle \n")){
- String ownerName = vehicleDataList.get(i+1);
- String ownerAddress = vehicleDataList.get(i+2);
- String ownerPhone = vehicleDataList.get(i+3);
- String ownerEmail = vehicleDataList.get(i+4);
- System.out.println(ownerName + ownerAddress + ownerPhone + ownerEmail);
- vehicleList.add(new Vehicle(ownerName, ownerAddress, ownerPhone, ownerEmail));
- }
- else if (vehicleDataList.get(i).equals("car\n")){
- System.out.println("working");
- String ownerName = vehicleDataList.get(i+1);
- String ownerAddress = vehicleDataList.get(i+2);
- String ownerPhone = vehicleDataList.get(i+3);
- String ownerEmail = vehicleDataList.get(i+4);
- boolean isConvertible;
- if (vehicleDataList.get(i+5).equals("true")){
- isConvertible = true;
- }
- else{
- isConvertible = false;
- }
- String carColor = vehicleDataList.get(i+6);
- vehicleList.add(new Car(isConvertible, carColor, ownerName, ownerAddress, ownerPhone, ownerEmail));
- }
- else if (vehicleDataList.get(i).equals("american car \n")){
- String ownerName = vehicleDataList.get(i+1);
- String ownerAddress = vehicleDataList.get(i+2);
- String ownerPhone = vehicleDataList.get(i+3);
- String ownerEmail = vehicleDataList.get(i+4);
- boolean isConvertible;
- if (vehicleDataList.get(i+5).equals("true")){
- isConvertible = true;
- }
- else{
- isConvertible = false;
- }
- String carColor = vehicleDataList.get(i+6);
- boolean madeDetroit;
- if(vehicleDataList.get(i+7).equals("true")){
- madeDetroit = true;
- }
- else{
- madeDetroit = false;
- }
- boolean madeUnion;
- if(vehicleDataList.get(i+8).equals("true")){
- madeUnion = true;
- }
- else{
- madeUnion = false;
- }
- vehicleList.add(new AmericanCar(madeDetroit, madeUnion, isConvertible, carColor,ownerName, ownerAddress, ownerPhone, ownerEmail));
- }
- else if (vehicleDataList.get(i).equals("foriegn car \n")){
- System.out.println("working");
- String ownerName = vehicleDataList.get(i+1);
- String ownerAddress = vehicleDataList.get(i+2);
- String ownerPhone = vehicleDataList.get(i+3);
- String ownerEmail = vehicleDataList.get(i+4);
- boolean isConvertible;
- if (vehicleDataList.get(i+5).equals("true")){
- isConvertible = true;
- }
- else{
- isConvertible = false;
- }
- String carColor = vehicleDataList.get(i+6);
- String originCountry = vehicleDataList.get(i+7);
- float payDuty = Float.parseFloat(vehicleDataList.get(i+8));
- vehicleList.add(new ForeignCar(originCountry, payDuty, isConvertible, carColor,ownerName, ownerAddress, ownerPhone, ownerEmail));
- }
- else if (vehicleDataList.get(i).equals("bicycle \n")){
- String ownerName = vehicleDataList.get(i+1);
- String ownerAddress = vehicleDataList.get(i+2);
- String ownerPhone = vehicleDataList.get(i+3);
- String ownerEmail = vehicleDataList.get(i+4);
- int numSpeeds = Integer.parseInt(vehicleDataList.get(i+5));
- vehicleList.add(new Bicycle(numSpeeds, ownerName, ownerAddress, ownerPhone, ownerEmail));
- }
- else if (vehicleDataList.get(i).equals("truck \n")){
- String ownerName = vehicleDataList.get(i+1);
- String ownerAddress = vehicleDataList.get(i+2);
- String ownerPhone = vehicleDataList.get(i+3);
- String ownerEmail = vehicleDataList.get(i+4);
- float tonsCapacity = Float.parseFloat(vehicleDataList.get(i+5));
- float truckCost = Float.parseFloat(vehicleDataList.get(i+6));
- String truckDate = vehicleDataList.get(i+6);
- vehicleList.add(new Truck(tonsCapacity, truckCost, truckDate, ownerName, ownerAddress, ownerPhone, ownerEmail));
- }
- }
- int vehicleLenght = vehicleList.size();
- System.out.println(vehicleLenght);
- }
- }
- class Vehicle
- {
- private String owner;
- private String address;
- private String phone;
- private String email;
- public Vehicle(){
- }
- public Vehicle(String owner, String address, String phone, String email){
- this.owner = owner;
- this.address = address;
- this.phone = phone;
- this.email = email;
- }
- public void setOwner(String owner){
- this.owner = owner;
- }
- public String getOwner(){
- return owner;
- }
- public void setAddress(String address){
- this.address = address;
- }
- public String getAddress(){
- return address;
- }
- public void setPhone(String phone){
- this.phone = phone;
- }
- public String getPhone(){
- return phone;
- }
- public void setEmail(String email){
- this.email = email;
- }
- public String getEmail(){
- return email;
- }
- public String toString(){
- return owner + "\n" + address + "\n" + phone + "\n" + email;
- }
- }
- class Car extends Vehicle
- {
- private boolean convertible;
- private String color;
- public Car(){
- }
- public Car(boolean convertible, String color, String owner, String address, String phone, String email){
- super(owner, address, phone, email);
- this.convertible = convertible;
- this.color = color;
- }
- public void setColor(String color){
- this.color = color;
- }
- public String getColor(){
- return color;
- }
- public void setConvertible(boolean convertible){
- this.convertible = convertible;
- }
- public boolean getConvertible(){
- return convertible;
- }
- public String toString(){
- return super.toString() + "\n" + convertible + "\n" + color;
- }
- }
- class AmericanCar extends Car
- {
- private boolean detroit;
- private boolean union;
- public AmericanCar(){
- }
- public AmericanCar(boolean detroit, boolean union, boolean convertible, String color, String owner, String address, String phone, String email){
- super(convertible, color, owner, address, phone, email);
- this.detroit = detroit;
- this.union = union;
- }
- public void setDetroit(boolean detroit){
- this.detroit = detroit;
- }
- public boolean getDetroit(){
- return detroit;
- }
- public void setUnion(boolean union){
- this.union = union;
- }
- public boolean getUnion(){
- return union;
- }
- public String toString(){
- return super.toString() + "\n" + detroit + union;
- }
- }
- class ForeignCar extends Car
- {
- private String country;
- private float duty;
- public ForeignCar(){
- }
- public ForeignCar(String country, float duty, boolean convertible, String color, String owner, String address, String phone, String email){
- super(convertible, color, owner, address, phone, email);
- this.country = country;
- this.duty = duty;
- }
- public void setCountry(String country){
- this.country = country;
- }
- public String getCountry(){
- return country;
- }
- public void setDuty(float duty){
- this.duty = duty;
- }
- public float getDuty(){
- return duty;
- }
- public String toString(){
- return super.toString() + "\n" + country + "\n" + duty;
- }
- }
- class Bicycle extends Vehicle
- {
- private int speeds;
- public Bicycle(){
- }
- public Bicycle(int speeds, String owner, String address, String phone, String email){
- super(owner, address, phone, email);
- this.speeds = speeds;
- }
- public void setSpeeds(int speeds){
- this.speeds = speeds;
- }
- public int getSpeeds(){
- return speeds;
- }
- public String toString(){
- return super.toString() + "\n" + speeds;
- }
- }
- class Truck extends Vehicle
- {
- private float tons;
- private float cost;
- private String date;
- public Truck(){
- }
- public Truck(float tons, float cost, String date, String owner, String address, String phone, String email){
- super(owner, address, phone, email);
- this.tons = tons;
- this.cost = cost;
- this.date = date;
- }
- public void setTons(float tons){
- this.tons = tons;
- }
- public float getTons(){
- return tons;
- }
- public void setCost(float cost){
- this.cost = cost;
- }
- public float getCost(){
- return cost;
- }
- public void setDate(String date){
- this.date = date;
- }
- public String getDate(){
- return date;
- }
- public String toString(){
- return super.toString() + "\n" + tons + "\n" + cost + "\n" + date;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement