/**
  * Find Find OptionSet with name
  *
  * @throws AutoException
  */
 public OptionSet findOpset(String name) throws AutoException {
   for (OptionSet opset : this.OptionSet) {
     if (opset.getName().equals(name)) {
       return opset;
     }
   }
   throw new AutoException(EnumerationAutoException.WrongOptionSetName);
 }
Ejemplo n.º 2
0
  /*set the optionset for a given optionset*/
  protected void setOptionSet(OptionSet optset) {
    int i = 0;

    for (i = 0; i < optset.getOption().size(); i++) {
      this.option.get(i).setOptionName1(optset.getOption(i).getOptionName());
      this.option.get(i).setPrice(optset.getOption(i).getPrice());
    }
  }
Ejemplo n.º 3
0
 public synchronized void deleteOpt(String opsetName, String optName) {
   OptionSet OptList = opsetList.get(opsetName);
   for (int j = 0; j < OptList.getOpt().size(); j++) {
     if (OptList.getOpt().get(j).getName().equals(optName)) {
       OptList.getOpt().remove(j);
       break;
     }
   }
 }
 public void printOneOption(String name) throws AutoException {
   OptionSet opset_find = this.findOpset(name);
   if (opset_find != null) {
     System.out.println(opset_find.getName() + ":");
     opset_find.printAllOptions();
   } else {
     System.out.println("Have no item named:" + name);
   }
 }
 public void printOptions() {
   System.out.println("*************************************************************");
   System.out.println("*                       Car's Options                       *");
   System.out.println("*************************************************************");
   int i = 1;
   for (OptionSet opt : this.OptionSet) {
     System.out.println("" + i + ". " + opt.getName() + ":");
     opt.printAllOptions();
     i++;
   }
 }
Ejemplo n.º 6
0
 public synchronized Option findOptWithName(String optName) {
   Iterator<String> iter = opsetList.keySet().iterator();
   while (iter.hasNext()) {
     String key = iter.next();
     OptionSet optList = opsetList.get(key);
     for (int j = 0; j < optList.getOpt().size(); j++) {
       if (optList.getOpt().get(j).getName().equals(optName)) {
         return optList.getOpt().get(j);
       }
     }
   }
   return null;
 }
Ejemplo n.º 7
0
  // print automobile model, base price and options
  public synchronized String print() {
    StringBuffer sB = new StringBuffer();
    sB.append("Make: ");
    sB.append(make);
    sB.append("\nModel: ");
    sB.append(model);
    sB.append("\nBase Price: $");
    sB.append(baseprice);

    Iterator<String> iter = opsetList.keySet().iterator();
    while (iter.hasNext()) {
      String key = iter.next();
      OptionSet optList = opsetList.get(key);
      sB.append("\n\n");
      sB.append(key);
      sB.append(optList.print());
    }
    return sB.toString();
  }
Ejemplo n.º 8
0
 public synchronized void updateOpt(String opsetName, String optName, float price) {
   try {
     if (!opsetList.containsKey(opsetName))
       throw new AutoOptionException(
           "The option set name entered is not found. Please check!" + "\nNo update is made.");
     else {
       OptionSet OptList = opsetList.get(opsetName);
       boolean optNameExists = false;
       for (int j = 0; j < OptList.getOpt().size(); j++) {
         if (OptList.getOpt().get(j).getName().equals(optName)) {
           OptList.getOpt().get(j).setPrice(price);
           optNameExists = true;
           break;
         }
       }
       if (optNameExists == false)
         throw new AutoOptionException(
             "The option name entered is not found. Please check!" + "\nNo update is made.");
     }
   } catch (AutoOptionException e) {
     System.out.println(e.getMsg());
   }
 }
 public void setOptionChoice(String setName, String optionName) throws AutoException {
   OptionSet opset = this.findOpset(setName);
   this.choice.add(opset.getOption(optionName));
   opset.setOptionChoice(optionName);
 }
 public void updateOptionPrice(String opset_name, String option_name, float price)
     throws AutoException {
   OptionSet temp = this.findOpset(opset_name);
   temp.updateOptPrice(option_name, price);
 }
 /**
  * Option Part
  *
  * @throws AutoException
  */
 public void updateOptionName(String opset_name, String old_name, String name)
     throws AutoException {
   OptionSet temp = this.findOpset(opset_name);
   temp.updateOptName(old_name, name);
 }
 public void updateOpsetName(String old_name, String name) throws AutoException {
   OptionSet temp = this.findOpset(old_name);
   if (temp != null) {
     temp.setName(name);
   }
 }
 /**
  * Option Part
  *
  * @throws AutoException
  */
 public void setOption(String opset_name, String name, float price) throws AutoException {
   OptionSet temp = this.findOpset(opset_name);
   if (temp != null) {
     temp.setOpt(name, price);
   }
 }