1 package com.db4o.f1.chapter4; 2 3 import java.util.*; 4 5 public class Car { 6 private String model; 7 private Pilot pilot; 8 private List history; 9 10 public Car(String model) { 11 this.model=model; 12 this.pilot=null; 13 this.history=new ArrayList(); 14 } 15 16 public Pilot getPilot() { 17 return pilot; 18 } 19 20 public void setPilot(Pilot pilot) { 21 this.pilot=pilot; 22 } 23 24 public String getModel() { 25 return model; 26 } 27 28 public SensorReadout[] getHistory() { 29 return (SensorReadout[])history.toArray(new SensorReadout[history.size()]); 30 } 31 32 public void snapshot() { 33 history.add(new TemperatureSensorReadout( 34 new Date(),this,"oil",pollOilTemperature())); 35 history.add(new TemperatureSensorReadout( 36 new Date(),this,"water",pollWaterTemperature())); 37 history.add(new PressureSensorReadout( 38 new Date(),this,"oil",pollOilPressure())); 39 } 40 41 protected double pollOilTemperature() { 42 return 0.1*history.size(); 43 } 44 45 protected double pollWaterTemperature() { 46 return 0.2*history.size(); 47 } 48 49 protected double pollOilPressure() { 50 return 0.3*history.size(); 51 } 52 53 public String toString() { 54 return model+"["+pilot+"]/"+history.size(); 55 } 56 } | Popular Tags |