package class4_1_Observer; import java.util.Random; /** * Author: Josiah Yoder et al. * Class: SExxxx-xx * Date: 1/7/14 7:45 AM * Lesson: Week x, Day x */ public class Example { public static void main(String[] ignored) { Car car = new Car(); car.addObserver(new SimplePositionObserver()); car.addObserver(new VelocityObserver()); car.addObserver(new AverageObserver()); car.run(); } // public void run() { // Random gen = new Random(); // double positionMeters = 0; // double oldPosition = 0; // double smoothedPosition = 0; // // for(int i= 0; i<10; i++) { // positionMeters += gen.nextDouble(); // // // Compute velocity // double velocity = positionMeters - oldPosition; // oldPosition = positionMeters; // System.out.println("Velocity: "+velocity+" m/s"); // // // Compute average position // smoothedPosition = 0.9 * smoothedPosition + 0.1 * positionMeters; // System.out.println("Smoothed position: "+smoothedPosition); // // // Compute "named" location // String namedLocation; // if(Math.abs(positionMeters) < 1) { // namedLocation = "Home"; // } else if(Math.abs(positionMeters-10)<1) { // namedLocation = "Work"; // } else { // namedLocation = ""; // } // if(namedLocation.length() > 0) { // System.out.println("We are at "+namedLocation); // } // // // Separater between steps... // System.out.println(); // } // } }