Advertisement
Guest User

Untitled

a guest
Oct 17th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.00 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.Math;
  3. import java.io.File;
  4. import java.util.ArrayList;
  5. import java.io.FileNotFoundException;
  6. //equalsIgnoreCase
  7.  
  8. public class n00885749
  9. {
  10.    public static void main(String[] args)throws FileNotFoundException {
  11.       File data = new File(args[0]);
  12.       ArrayList<Vehicle>vehicleList = new ArrayList<Vehicle>(0);
  13.       ArrayList<String>vehicleDataList = new ArrayList<String>();
  14.       try{
  15.          Scanner input = new Scanner(data);
  16.          input.useDelimiter("\n");        
  17.          while(input.hasNext()){
  18.             String type = input.next();
  19.             vehicleDataList.add(type);          
  20.          }
  21.       }
  22.       catch(FileNotFoundException ex){
  23.          System.out.println(ex);
  24.       }
  25.       int listLength = vehicleDataList.size();
  26.       int i;
  27.       //System.out.println(listLength);
  28.       for(i=0; i< vehicleDataList.size(); i++){
  29.          //System.out.print(vehicleDataList.get(i));
  30.          //System.out.println("-----------------------------------------------");
  31.          if (vehicleDataList.get(i).equals("vehicle \n")){
  32.             String ownerName = vehicleDataList.get(i+1);
  33.             String ownerAddress = vehicleDataList.get(i+2);
  34.             String ownerPhone = vehicleDataList.get(i+3);
  35.             String ownerEmail = vehicleDataList.get(i+4);
  36.             System.out.println(ownerName + ownerAddress + ownerPhone + ownerEmail);
  37.             vehicleList.add(new Vehicle(ownerName, ownerAddress, ownerPhone, ownerEmail));
  38.          }
  39.          else if (vehicleDataList.get(i).equals("car\n")){
  40.             System.out.println("working");
  41.             String ownerName = vehicleDataList.get(i+1);
  42.             String ownerAddress = vehicleDataList.get(i+2);
  43.             String ownerPhone = vehicleDataList.get(i+3);
  44.             String ownerEmail = vehicleDataList.get(i+4);
  45.             boolean isConvertible;
  46.             if (vehicleDataList.get(i+5).equals("true")){
  47.                isConvertible = true;
  48.             }
  49.             else{
  50.                isConvertible = false;
  51.             }
  52.             String carColor = vehicleDataList.get(i+6);
  53.             vehicleList.add(new Car(isConvertible, carColor, ownerName, ownerAddress, ownerPhone, ownerEmail));
  54.          }
  55.          else if (vehicleDataList.get(i).equals("american car \n")){
  56.             String ownerName = vehicleDataList.get(i+1);
  57.             String ownerAddress = vehicleDataList.get(i+2);
  58.             String ownerPhone = vehicleDataList.get(i+3);
  59.             String ownerEmail = vehicleDataList.get(i+4);
  60.             boolean isConvertible;
  61.             if (vehicleDataList.get(i+5).equals("true")){
  62.                isConvertible = true;
  63.             }
  64.             else{
  65.                isConvertible = false;
  66.             }
  67.             String carColor = vehicleDataList.get(i+6);
  68.             boolean madeDetroit;
  69.             if(vehicleDataList.get(i+7).equals("true")){
  70.                madeDetroit = true;
  71.             }
  72.             else{
  73.                madeDetroit = false;
  74.             }
  75.             boolean madeUnion;
  76.             if(vehicleDataList.get(i+8).equals("true")){
  77.                madeUnion = true;
  78.             }
  79.             else{
  80.                madeUnion = false;
  81.             }
  82.             vehicleList.add(new AmericanCar(madeDetroit, madeUnion, isConvertible, carColor,ownerName, ownerAddress, ownerPhone, ownerEmail));
  83.          }
  84.          else if (vehicleDataList.get(i).equals("foriegn car \n")){
  85.             System.out.println("working");
  86.             String ownerName = vehicleDataList.get(i+1);
  87.             String ownerAddress = vehicleDataList.get(i+2);
  88.             String ownerPhone = vehicleDataList.get(i+3);
  89.             String ownerEmail = vehicleDataList.get(i+4);
  90.             boolean isConvertible;
  91.             if (vehicleDataList.get(i+5).equals("true")){
  92.                isConvertible = true;
  93.             }
  94.             else{
  95.                isConvertible = false;
  96.             }
  97.             String carColor = vehicleDataList.get(i+6);
  98.             String originCountry = vehicleDataList.get(i+7);
  99.             float payDuty = Float.parseFloat(vehicleDataList.get(i+8));
  100.             vehicleList.add(new ForeignCar(originCountry, payDuty, isConvertible, carColor,ownerName, ownerAddress, ownerPhone, ownerEmail));
  101.          }
  102.          else if (vehicleDataList.get(i).equals("bicycle \n")){
  103.             String ownerName = vehicleDataList.get(i+1);
  104.             String ownerAddress = vehicleDataList.get(i+2);
  105.             String ownerPhone = vehicleDataList.get(i+3);
  106.             String ownerEmail = vehicleDataList.get(i+4);
  107.             int numSpeeds = Integer.parseInt(vehicleDataList.get(i+5));
  108.             vehicleList.add(new Bicycle(numSpeeds, ownerName, ownerAddress, ownerPhone, ownerEmail));
  109.          }
  110.          else if (vehicleDataList.get(i).equals("truck \n")){
  111.             String ownerName = vehicleDataList.get(i+1);
  112.             String ownerAddress = vehicleDataList.get(i+2);
  113.             String ownerPhone = vehicleDataList.get(i+3);
  114.             String ownerEmail = vehicleDataList.get(i+4);                  
  115.             float tonsCapacity = Float.parseFloat(vehicleDataList.get(i+5));
  116.             float truckCost = Float.parseFloat(vehicleDataList.get(i+6));
  117.             String truckDate = vehicleDataList.get(i+6);
  118.             vehicleList.add(new Truck(tonsCapacity, truckCost, truckDate, ownerName, ownerAddress, ownerPhone, ownerEmail));
  119.          }
  120.          
  121.       }
  122.       int vehicleLenght = vehicleList.size();
  123.       System.out.println(vehicleLenght);
  124.    }
  125. }
  126.  
  127. class Vehicle
  128. {
  129.    private String owner;
  130.    private String address;
  131.    private String phone;
  132.    private String email;
  133.    
  134.    public Vehicle(){
  135.    }
  136.    public Vehicle(String owner, String address, String phone, String email){
  137.       this.owner = owner;
  138.       this.address = address;
  139.       this.phone = phone;
  140.       this.email = email;
  141.    }
  142.    
  143.    public void setOwner(String owner){
  144.       this.owner = owner;
  145.    }
  146.    public String getOwner(){
  147.       return owner;
  148.    }
  149.    public void setAddress(String address){
  150.       this.address = address;
  151.    }
  152.    public String getAddress(){
  153.       return address;
  154.    }
  155.    public void setPhone(String phone){
  156.       this.phone = phone;
  157.    }
  158.    public String getPhone(){
  159.       return phone;
  160.    }
  161.    public void setEmail(String email){
  162.       this.email = email;
  163.    }
  164.    public String getEmail(){
  165.       return email;
  166.    }
  167.    public String toString(){
  168.       return owner + "\n" + address + "\n" + phone + "\n" + email;
  169.    }
  170.    
  171. }
  172.  
  173. class Car extends Vehicle
  174. {
  175.    private boolean convertible;
  176.    private String color;
  177.    public Car(){
  178.    }
  179.    public Car(boolean convertible, String color, String owner, String address, String phone, String email){
  180.       super(owner, address, phone, email);
  181.       this.convertible = convertible;
  182.       this.color = color;
  183.    }
  184.    public void setColor(String color){
  185.       this.color = color;
  186.    }
  187.    public String getColor(){
  188.       return color;
  189.    }
  190.    public void setConvertible(boolean convertible){
  191.       this.convertible = convertible;
  192.    }
  193.    public boolean getConvertible(){
  194.       return convertible;
  195.    }
  196.    public String toString(){
  197.       return super.toString() + "\n" + convertible + "\n" + color;
  198.    }
  199. }
  200.  
  201. class AmericanCar extends Car
  202. {
  203.    private boolean detroit;
  204.    private boolean union;
  205.    public AmericanCar(){
  206.    }
  207.    public AmericanCar(boolean detroit, boolean union, boolean convertible, String color, String owner, String address, String phone, String email){
  208.       super(convertible, color, owner, address, phone, email);
  209.       this.detroit = detroit;
  210.       this.union = union;
  211.    }
  212.    public void setDetroit(boolean detroit){
  213.       this.detroit = detroit;
  214.    }
  215.    public boolean getDetroit(){
  216.       return detroit;
  217.    }
  218.    public void setUnion(boolean union){
  219.       this.union = union;
  220.    }
  221.    public boolean getUnion(){
  222.       return union;
  223.    }
  224.    public String toString(){
  225.       return super.toString() + "\n" + detroit + union;
  226.    }
  227. }
  228.  
  229. class ForeignCar extends Car
  230. {
  231.    private String country;
  232.    private float duty;
  233.    public ForeignCar(){
  234.    }
  235.    public ForeignCar(String country, float duty, boolean convertible, String color, String owner, String address, String phone, String email){
  236.       super(convertible, color, owner, address, phone, email);
  237.       this.country = country;
  238.       this.duty = duty;
  239.    }
  240.    public void setCountry(String country){
  241.       this.country = country;
  242.    }
  243.    public String getCountry(){
  244.       return country;
  245.    }
  246.    public void setDuty(float duty){
  247.       this.duty = duty;
  248.    }
  249.    public float getDuty(){
  250.       return duty;
  251.    }
  252.    public String toString(){
  253.       return super.toString() + "\n" + country + "\n" + duty;
  254.    }
  255. }
  256.  
  257. class Bicycle extends Vehicle
  258. {
  259.    private int speeds;
  260.    public Bicycle(){
  261.    }
  262.    public Bicycle(int speeds, String owner, String address, String phone, String email){
  263.       super(owner, address, phone, email);
  264.       this.speeds = speeds;
  265.    }
  266.    public void setSpeeds(int speeds){
  267.       this.speeds = speeds;
  268.    }
  269.    public int getSpeeds(){
  270.       return speeds;
  271.    }
  272.    public String toString(){
  273.       return super.toString() + "\n" + speeds;
  274.    }
  275. }
  276.  
  277. class Truck extends Vehicle
  278. {
  279.    private float tons;
  280.    private float cost;
  281.    private String date;
  282.    public Truck(){
  283.    }
  284.    public Truck(float tons, float cost, String date, String owner, String address, String phone, String email){
  285.       super(owner, address, phone, email);
  286.       this.tons = tons;
  287.       this.cost = cost;
  288.       this.date = date;
  289.    }
  290.    public void setTons(float tons){
  291.       this.tons = tons;
  292.    }
  293.    public float getTons(){
  294.       return tons;
  295.    }
  296.    public void setCost(float cost){
  297.       this.cost = cost;
  298.    }
  299.    public float getCost(){
  300.       return cost;
  301.    }
  302.    public void setDate(String date){
  303.       this.date = date;
  304.    }
  305.    public String getDate(){
  306.       return date;
  307.    }
  308.    public String toString(){
  309.       return super.toString() + "\n" + tons + "\n" + cost + "\n" + date;
  310.    }
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement