background image

Java 程序:Spring 笔记(一)

  这是从构建一个过山车订购系统的书籍中摘录的代码部分,全书在,体育商店可以
用来对它们的过山车进行管理和订购。第一节作者先硬编码了两个有依赖关系的类
CommandLineView.java 和 RentABike.java。我们先看看源代码:
  Example 1-1. Bike.java
  

public

 

class

 Bike {

  

private

 String manufacturer;

  

private

 String model;

  

private

 int frame;

  

private

 String serialNo;

  

private

 double weight;

  

private

 String status;

  

public

 Bike(String manufacturer, String model, int frame,

  String serialNo, double weight, String status) {
  this.manufacturer = manufacturer;
  this.model = model;
  this.frame = frame;
  this.serialNo = serialNo;
  this.weight = weight;
  this.status = status;
  }
  

public

 String toString( ) {

  

return

 "Bike : " +

  "manufacturer -- " + manufacturer +
  "\n: model -- " + model +
  "\n: frame -- " + frame +
  "\n: serialNo -- " + serialNo +
  "\n: weight -- " + weight +
  "\n: status -- " + status +
  ".\n";
  }
  

public

 String getManufacturer( ) { 

return

 manufacturer; }

  

public

 void setManufacturer(String manufacturer) {

  this.manufacturer = manufacturer;
  }
  

public

 String getModel( ) { 

return

 model; }

  

public

 void setModel(String model) { this.model = model; }

  

public

 int getFrame( ) { 

return

 frame; }