⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vehicles.java

📁 This file contains all the vehicles program in one file.
💻 JAVA
字号:
public class Vehicles {
  // Construct a polyline from an array of points
  public Vehicles(Vehicle[] vhcs) {
    vehiclelist = new LinkedList<Vehicle>(vhcs);    // Create list of Vehicle objects
  }
  
  // Add a Vehicle object to the list
  public void addVehicle(Vehicle vehicle) {
    vehiclelist.addItem(vehicle);                     // Add the Vehicle to the list
  }

/****************** String representation of a vehicle *****/
  public String toString() {
    StringBuffer str = new StringBuffer("Vehicles:");
    Vehicle vehicle = (Vehicle) vehiclelist.getFirst();  
                                                 // Set the 1st point as start
    while(vehicle != null) {
      str.append(" ("+ vehicle+ ")\n");              // Append the current vehicle
      vehicle = (Vehicle)vehiclelist.getNext();         // Make the next vehicle current
    }
    return str.toString();

  } // end of toString
/*********************************************************/

/************************* Using Iterator, ******************************/
/********For your problem you need to use this code instead of the above *************
  public String toString() {
    StringBuffer str = new StringBuffer("Vehicles:");
    for ( Vehicle v : vehiclelist)
      str.append(" ("+ v + ")\n");              // Append the current vehicle
    return str.toString();
  } // end of toString
***************************************************************/

  private LinkedList<Vehicle> vehiclelist;            // The linked list of vehicles
}

⌨️ 快捷键说明

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