Commit 3740ff4fdb42f25621cd1162511ddf7e51f424ff

Authored by Thomas Røiri Aaslund
1 parent 7bc0946a

add missing prod date to car +bicycle

Showing 3 changed files with 33 additions and 2 deletions   Show diff stats
Bicycle.java
... ... @@ -2,21 +2,30 @@
2 2 package vehicle;
3 3  
4 4 import java.lang.*;
  5 +import java.util.*;
5 6  
6 7 public class Bicycle extends Vehicle
7 8 {
8 9 int gears;
  10 + Calendar productionDate;
9 11  
10 12 public int getGears() { return this.gears; }
11 13 public void setGears(int value) { this.gears = value; }
12 14  
  15 + public Calendar getProductionDate() { return this.productionDate; }
  16 + public void setProductionDate(Calendar value) { this.productionDate = value; }
  17 +
  18 +
13 19 public Bicycle()
14 20 {
  21 + this.productionDate = new GregorianCalendar();
  22 + this.gears = 0;
15 23 }
16 24  
17 25 public Bicycle(String name, String color, int price, int model, String serialNumber, int direction, int gears)
18 26 {
19 27 super(name, color, serialNumber, model, price, direction);
  28 + this.productionDate = new GregorianCalendar();
20 29 this.gears = gears;
21 30 }
22 31  
... ... @@ -44,6 +53,11 @@ public class Bicycle extends Vehicle
44 53 @Override
45 54 public String toString()
46 55 {
47   - return String.format("%s, gears: %s", super.toString(), gears);
  56 + return String.format(
  57 + "%s, gears: %s, productionDate: %s",
  58 + super.toString(),
  59 + gears,
  60 + DATE_FORMAT.format(productionDate.getTime())
  61 + );
48 62 }
49 63 }
50 64 \ No newline at end of file
... ...
Car.java
... ... @@ -2,21 +2,30 @@
2 2 package vehicle;
3 3  
4 4 import java.lang.*;
  5 +import java.util.*;
  6 +
5 7  
6 8 public class Car extends Vehicle
7 9 {
  10 + Calendar productionDate;
8 11 int power;
9 12  
10 13 public int getPower() { return this.power; }
11 14 public void setPower(int value) { this.power = value; }
12 15  
  16 + public Calendar getProductionDate() { return this.productionDate; }
  17 + public void setProductionDate(Calendar value) { this.productionDate = value; }
  18 +
13 19 public Car()
14 20 {
  21 + this.productionDate = new GregorianCalendar();
  22 + this.power = 0;
15 23 }
16 24  
17 25 public Car(String name, String color, int price, int model, String serialNumber, int direction, int power)
18 26 {
19 27 super(name, color, serialNumber, model, price, direction);
  28 + this.productionDate = new GregorianCalendar();
20 29 this.power = power;
21 30 }
22 31  
... ... @@ -44,6 +53,11 @@ public class Car extends Vehicle
44 53 @Override
45 54 public String toString()
46 55 {
47   - return String.format("%s, power: %s", super.toString(), power);
  56 + return String.format(
  57 + "%s, power: %s, productionDate: %s",
  58 + super.toString(),
  59 + power,
  60 + DATE_FORMAT.format(productionDate.getTime())
  61 + );
48 62 }
49 63 }
50 64 \ No newline at end of file
... ...
Vehicle.java
... ... @@ -3,9 +3,12 @@ package vehicle;
3 3  
4 4 import java.lang.*;
5 5 import java.util.*;
  6 +import java.text.*;
6 7  
7 8 public abstract class Vehicle
8 9 {
  10 + protected static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
  11 +
9 12 String color;
10 13 String name;
11 14 String serialNumber;
... ...