예제 #1
0
  public Model buildAuto(String fileName, String fileType) {
    FileIO builder = new FileIO();
    _autoModel = new Model();
    if (fileType.indexOf("prop") > -1) {
      try {
        _autoModel = builder.buildAutoModelFromProperties(fileName, _autoModel);
      } catch (AutoException ae) {
        System.out.print(ae.getErrMessage());
      }
    } else {
      try {

        _autoModel = builder.buildAutoModelObject(fileName, _autoModel);
      } catch (AutoException ae) {
        System.out.print(ae.getErrMessage());
        try {
          _autoModel = builder.buildAutoModelObject(fileName, _autoModel);
        } catch (AutoException e) {
          System.out.print("Could not resolve error " + ae.getErrMessage());
        }
      }
    }
    if (_autoModel != null) {
      _autoModel.setDefaultOptionChoices();
      addAuto(_autoModel);
    }
    return _autoModel;
  }
예제 #2
0
  public boolean buildAuto(Properties autoProp) {
    FileIO builder = new FileIO();
    _autoModel = new Model();
    try {
      builder.parseProperties(autoProp, _autoModel);
    } catch (AutoException e) {
      System.err.println(e.getMessage());
      if (e.getErrCode() == 102065) // missing properties, don't continue with this file.
      _autoModel = null;
    }

    if (_autoModel != null) {
      _autoModel.setDefaultOptionChoices();
      addAuto(_autoModel);
      return this.isAutoHere(_autoModel.getModelName());
    } else return false;
  }
예제 #3
0
  public static void main(String[] args) {
    DBConnection db = new DBConnection();
    // set up jdbc connection
    if (db.createConnection()) {
      // read file to build auto
      BuildAuto cars = new BuildAuto();
      cars.buildAuto("Focus.txt");
      cars.buildAuto("Prius.txt");

      // create table from text file
      ArrayList<String> sql = FileIO.readFile("sql.txt");
      CreateTable table = new CreateTable(db, sql.get(0), sql.get(1), sql.get(2));
      table.createTable();

      // add new automobile to db
      System.out.println("------------- add new automobile to database ---------------");
      Automobile focus = cars.getAutoByModelname("Focus");
      Automobile prius = cars.getAutoByModelname("Prius");
      AddAuto add = new AddAuto(db);
      add.addAuto(focus);
      add.addAuto(prius);
      String[] arr1 = {"model", "make", "base_price"};
      String[] arr2 = {"model", "setname"};
      String[] arr3 = {"model", "setname", "option_name", "price"};

      int two = db.showAll("automobile", arr1);
      if (two == 2) {
        System.out.println("add automobile to database successfully");
      } else {
        System.out.println("test failed, add automobile error");
      }

      // update automobile
      System.out.println(
          "------------- update option price & optionSet name to database---------------");
      UpdateDBAuto update = new UpdateDBAuto(db);
      // update option price
      update.updateOptionPrice("Focus", "Transmission", "Automatic", 20.0f);
      update.updateOptionsetName("Prius", "PowerMoonroof", "Power");
      db.showAll("optionset", arr2);
      db.showAll("options", arr3);

      // delete automobile
      System.out.println("------------- delete automobile from database ---------------");
      DeleteAuto delete = new DeleteAuto(db);
      delete.deleteAuto(focus);
      cars.delAutoByName("Focus");
      int one = db.showAll("automobile", arr1);
      if (one == 1) System.out.println("delete automobile from database successfully");
      else System.out.println("test failed, delete automobile error");
      System.out.println("");
      db.closeConnection();
    }
  }
예제 #4
0
  public static void main(String[] args) {

    FileIO file = new FileIO();
    // Create Automobile Object from a file.
    Automotive auto = file.buildAutomotiveObject("C:/Users/Shreyanshi/Desktop/FordZTW.txt");
    // Attributes before serialization
    System.out.println("Before serialization!\n");
    auto.print();

    FileIO fio = new FileIO();
    // Serialize
    Automotive FordZTW = fio.serializeAutomotive(auto);
    System.out.println("After Serialization !\n");
    // Print new attributes
    FordZTW.print();

    /** Finding */
    System.out.println("Find Power Moonroof & present\n");
    FordZTW.findOptionSet("Power Moonroof");
    FordZTW.findOption("present ");
    FordZTW.print();
    System.out.println("Finished Finding \n");
    /** Updating */
    System.out.println("Now update standard, $0.0 of automatic and Transmission!\n");
    FordZTW.updateOption("standard ", "classic");
    FordZTW.updateOption("automatic ", 400);
    FordZTW.updateOptionSet("Transmission", "Transmission Control");
    FordZTW.print();
    System.out.println("Finished Updating!\n");
    /** Deleting */
    System.out.println("\nNow delete ABS with Advance Trac and Side Impact Air Bags!\n");
    FordZTW.deleteOption("ABS with Advance Trac ");
    FordZTW.deleteOptionSet("Side Impact Air Bags");
    FordZTW.print();
    System.out.println("Finished Deleting!\n");
  }