tryvehiclehashmapregistry-template.java

来自「This file contains all the vehicles prog」· Java 代码 · 共 38 行

JAVA
38
字号
import java.util.HashMap;
import java.io.*;

public class TryVehicleHashMapRegistry {
  public static void main(String[] args) 
    throws IOException
  {

   /***
    HashMap define 
   ***/

    Vehicle[] vhcs = {
      new Vehicle("Windom Toyota","Toyota","Corolla","1234A"),
      new Vehicle("Sunsuke Honda","Honda","Stream","14321B"),
      new Vehicle("Yusuke Toyota","Toyota","Avalon","1212A"),
      new Vehicle("Yuu Toyota","Toyota","Camry","3210B"),
      new Vehicle("Daisuke Honda","Honda","Accord","1111A"),
    };

    for (Vehicle v : vhcs) //*** Register the vehicles to HashMap registry

    BufferedReader charStream = new BufferedReader (new InputStreamReader(System.in)); 
    Vehicle v;

    while(true) {
      System.out.print("Enter the name you want: ");
      String data = charStream.readLine();   
      if(data.equals("")) break;
      v = registry.get(data);  //get the vehicle from the registry
      if(v != null) System.out.println("Answer:\n" + v);
      else System.out.println("No found");
    }

  }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?