Commit f4384a0b94c2d7d1cb5df9f6e87fe2f810b112ab

Authored by Thomas Røiri Aaslund
1 parent 197c3c51

main changes for part 3

Showing 2 changed files with 23 additions and 4 deletions   Show diff stats
@@ -54,7 +54,8 @@ public class TestVehicle @@ -54,7 +54,8 @@ public class TestVehicle
54 System.out.println("4..............Show data about all vehicles"); 54 System.out.println("4..............Show data about all vehicles");
55 System.out.println("5.......Change direction of a given vehicle"); 55 System.out.println("5.......Change direction of a given vehicle");
56 System.out.println("6.......................Test clone() method"); 56 System.out.println("6.......................Test clone() method");
57 - System.out.println("7..............................Exit program"); 57 + System.out.println("7..................Test driveable interface");
  58 + System.out.println("0..............................Exit program");
58 System.out.println("...............................Your choice?"); 59 System.out.println("...............................Your choice?");
59 System.out.print(":"); 60 System.out.print(":");
60 int choice = scan.nextInt(); 61 int choice = scan.nextInt();
@@ -133,8 +134,26 @@ public class TestVehicle @@ -133,8 +134,26 @@ public class TestVehicle
133 System.out.println(theClone); 134 System.out.println(theClone);
134 } 135 }
135 } 136 }
136 - break;  
137 case 7: 137 case 7:
  138 + {
  139 + System.out.println("Make 2 vehicles: ");
  140 + Vehicle nv1 = new Bicycle("BMX","color",4000,1993,"BC133",10,0);
  141 + Vehicle nv2 = new Car("Lada","red",1200000,1996,"A122",350,0);
  142 + System.out.println(nv1);
  143 + System.out.println(nv2);
  144 + nv1.accelerate(50);
  145 + nv2.accelerate(50);
  146 + nv1.accelerate(100);
  147 + nv2.accelerate(100);
  148 +
  149 + nv1.brakes(10);
  150 + nv2.brakes(10);
  151 +
  152 + nv1.stop();
  153 + nv2.stop();
  154 + }
  155 + break;
  156 + case 0:
138 scan.close(); 157 scan.close();
139 System.exit(0); 158 System.exit(0);
140 default: 159 default:
@@ -46,9 +46,9 @@ public abstract class Vehicle implements Comparable<Vehicle>, Cloneable, Driveab @@ -46,9 +46,9 @@ public abstract class Vehicle implements Comparable<Vehicle>, Cloneable, Driveab
46 46
47 protected void printSpeedChangeMessage(String desc) 47 protected void printSpeedChangeMessage(String desc)
48 { 48 {
49 - System.out.println(String.format(String.format("%s %s: %s to %s", 49 + System.out.println(String.format("%s %s: %s to %.2f kmph",
50 this.getClass().getSimpleName(), 50 this.getClass().getSimpleName(),
51 - this.getName()), 51 + this.getName(),
52 desc, 52 desc,
53 getSpeed() 53 getSpeed()
54 )); 54 ));