Example
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
{
this
this
this
this
this
this
}
public String toString( )
{
return
}
public String getManufacturer( ) { return manufacturer; }
public void setManufacturer(String manufacturer) { this
public String getModel( ) { return model; }
public void setModel(String model) { this
public int getFrame( ) { return frame; }
public void setFrame(int frame) { this
public String getSerialNo( ) { return serialNo; }
public void setSerialNo(String serialNo) { this
public double getWeight( ) { return weight; }
public void setWeight(double weight) { this
public String getStatus( ) { return status; }
public void setStatus(String status) { this
}
可以看出
Example
import java
public class RentABike
{
private String storeName;
final List bikes = new ArrayList( );
public RentABike(String storeName)
{
this
bikes
bikes
bikes
public String toString( ) { return
public List getBikes( ) { return bikes; } //得到某一個序列號的過山車
public Bike getBike(String serialNo)
{
Iterator iter = bikes
while(iter
{
Bike bike = (Bike)iter
if(serialNo
}
return null;
}
}
這個類描敘了租用一台過山車的操作
我們再看看用戶接口是如何調用的
Example
import java
public class CommandLineView
{
private RentABike rentaBike;
public CommandLineView( ) {rentaBike = new RentABike(
public void printAllBikes( )
{
System
Iterator iter = rentaBike
while(iter
{
Bike bike = (Bike)iter
System
}
}
public static final void main(String[] args)
{
CommandLineView clv = new CommandLineView( );
clv
}
}
運行結果
C:\RentABikeApp\out> java CommandLineView
RentABike: Bruce
Bike : manufacturer
: model
: frame
: serialNo
: weight
: status
Bike : manufacturer
: model
: frame
: serialNo
: weight
: status
Bike : manufacturer
: model
: frame
: serialNo
: weight
: status
大家看出問題了嗎?
private RentABike rentaBike;
public CommandLineView( ) {rentaBike = new RentABike(
所以
Spring筆記和小結(二)
Spring筆記和小結(三)
Spring筆記和小結(四)
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29032.html