コード例 #1
0
ファイル: Client.java プロジェクト: ramya201/CarConfigApp
 public void configureCar(Automotive car) {
   System.out.println("Configure the Car-\nPlease enter option choice.");
   Scanner read = new Scanner(System.in);
   ListIterator<String> it = car.getOptionSetNamesIterator();
   while (it.hasNext()) {
     String optionSetName = it.next().toString();
     System.out.println(optionSetName + ":");
     try {
       car.setOptionChoice(optionSetName, read.nextLine());
     } catch (InvalidOptionException e) {
       e.fixException();
     }
   }
   car.calculateFinalPrice();
   System.out.println("\nFinal Configuration-");
   car.printFinalConfig();
 }
コード例 #2
0
ファイル: Client.java プロジェクト: ramya201/CarConfigApp
  public void run() {

    Automotive car = null;

    try {
      clientSock = new Socket(address, portNo);
      oos = new ObjectOutputStream(clientSock.getOutputStream());
      iis = new ObjectInputStream(clientSock.getInputStream());

      while (!end) {
        int selection =
            Integer.parseInt(
                readFromConsole(
                    "Select-\n1. Upload a car configuration\n2. Configure a car\nPlease enter 1 or 2"));
        if (selection == 1) {

          // Take File Name as input
          String fileName = readFromConsole("Enter file name");

          // Read File and create Automotive object
          car = FileIO.readFile(fileName);

          // Send serialized Automotive object to Server
          sendOutput(car);

          // Read acknowledgment from Server
          System.out.println("\nServer:" + iis.readObject());

          // Continue or exit?
          exitPoll();
        } else if (selection == 2) {

          // Request model options from Server
          sendOutput("Get Options");

          // Read available model options sent by Server
          System.out.println("\nServer:Available Models" + iis.readObject());

          // Take selected model name as input
          String model = readFromConsole("Enter selected Model Name");

          // Send selected model name to server
          sendOutput("Model-" + model);

          // Read configuration options for Model selected from Server
          System.out.println("\nServer:");
          Object input = iis.readObject();

          if (input instanceof Automotive) {
            car = (Automotive) input;
            System.out.println("Configurable Options");
            car.printOptionsAvailable();
          }
          configureCar(car);
          exitPoll();
        } else {
          System.out.println("Invalid Selection");
          exitPoll();
        }
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    } finally {
      try {
        clientSock.close();
      } catch (IOException e) {
        System.out.println(e.getMessage());
      }
    }
  }