Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

create PassengerVehicle

  • Loading branch information...
commit da8cfce0214827f3a0f4b9838336749837a3f9b3 1 parent 6b5aebb
Sho Shimauchi authored December 23, 2011
87  src/org/progjava/ch3/PassengerVehicle.java
... ...
@@ -0,0 +1,87 @@
  1
+package org.progjava.ch3;
  2
+
  3
+import org.progjava.ch2.Vehicle;
  4
+
  5
+public class PassengerVehicle extends Vehicle {
  6
+	private int maxSeats;
  7
+	private int currentSeats;
  8
+
  9
+	public PassengerVehicle() {
  10
+		this(0.0, 0.0, "none", 0);
  11
+	}
  12
+
  13
+	public PassengerVehicle(double currentVelocity, double currentDirection,
  14
+			String ownerName, int id) {
  15
+		this(currentVelocity, currentDirection, ownerName, id, 4, 0);
  16
+		// TODO Auto-generated constructor stub
  17
+	}
  18
+
  19
+	public PassengerVehicle(double currentVelocity, double currentDirection,
  20
+			String ownerName, int id, int maxSeats, int currentSeats) {
  21
+		super(currentVelocity, currentDirection, ownerName, id);
  22
+		this.maxSeats = maxSeats;
  23
+		this.currentSeats = currentSeats;
  24
+	}
  25
+
  26
+	public void setMaxSeats(int maxSeats) {
  27
+		this.maxSeats = maxSeats;
  28
+	}
  29
+
  30
+	public int getMaxSeats() {
  31
+		return maxSeats;
  32
+	}
  33
+
  34
+	public void setCurrentSeats(int currentSeats) {
  35
+		this.currentSeats = currentSeats;
  36
+	}
  37
+
  38
+	public int getCurrentSeats() {
  39
+		return currentSeats;
  40
+	}
  41
+
  42
+	public String toString() {
  43
+		String str = Double.toString(this.getCurrentVelocity()) + " "
  44
+				+ Double.toString(this.getCurrentDirection()) + " "
  45
+				+ this.getOwnerName() + " " + Integer.toString(this.getId())
  46
+				+ " " + Integer.toString(this.getMaxSeats()) + " "
  47
+				+ Integer.toString(this.getCurrentSeats());
  48
+		return str;
  49
+	}
  50
+
  51
+	/**
  52
+	 * @param args
  53
+	 */
  54
+	public static void main(String[] args) {
  55
+		if (args.length == 1) {
  56
+			PassengerVehicle your_car = new PassengerVehicle(100.0, 100.0, args[0], 100);
  57
+			System.out.printf("%s\n", your_car);
  58
+		}
  59
+
  60
+		PassengerVehicle car = new PassengerVehicle(10.0, 20.0, "tom", 1, 6, 1);
  61
+		PassengerVehicle car2 = new PassengerVehicle(11.0, 3.0, "jon", 2, 2, 2);
  62
+		PassengerVehicle car3 = new PassengerVehicle(15.0, 4.0, "jon", 10, 100, 10);
  63
+
  64
+		System.out.printf("car: %s\n", car);
  65
+		System.out.printf("car2: %s\n", car2);
  66
+		System.out.printf("car3: %s\n", car3);
  67
+		System.out.printf("max id: %d\n", PassengerVehicle.getMaxId());
  68
+
  69
+		System.out.printf("stop\n");
  70
+		car.stop();
  71
+		System.out.printf("car: %s\n", car);
  72
+
  73
+		System.out.printf("turn 20 degrees\n");
  74
+		car.turn(20.0);
  75
+		System.out.printf("car: %s\n", car);
  76
+
  77
+		System.out.printf("turn 400 degrees\n");
  78
+		car.turn(400.0);
  79
+		System.out.printf("car: %s\n", car);
  80
+
  81
+		System.out.printf("turn right\n");
  82
+		car.turn(PassengerVehicle.TURN_RIGHT);
  83
+		System.out.printf("car: %s\n", car);
  84
+
  85
+	}
  86
+
  87
+}

0 notes on commit da8cfce

Please sign in to comment.
Something went wrong with that request. Please try again.