Commit edf2280822c7f4437374d8cbda6d0cf9d551b672

Authored by Thomas Røiri Aaslund
1 parent 053f6dd1

vehicle

Showing 4 changed files with 121 additions and 14 deletions   Show diff stats
Bicycle.java
1 1  
  2 +package vehicle;
2 3  
3 4 import java.lang.*;
4   -import java.gui.*;
5 5  
... ...
Car.java
1 1  
  2 +package vehicle;
2 3  
3 4 import java.lang.*;
4   -import java.gui.*;
5 5  
... ...
TestVehicle.java
1 1  
2 2  
3   -import java.lang.*;
4   -import java.gui.*;
5 3  
6   -public class TestVehicle
  4 +package vehicle;
  5 +
  6 +import java.util.*;
  7 +import java.io.*;
  8 +
  9 +public class TestVehicle
7 10 {
8   - public static void main(String[] args)
  11 + public static void main(String[] args)
9 12 {
10   - System.out.println("test123");
11   - System.out.println("test456");
12   - System.out.println("test789");
13   - System.out.println("testABC");
  13 + TestVehicle vtest = new TestVehicle();
  14 + try
  15 + {
  16 + vtest.menuLoop();
  17 + }
  18 + catch(IOException e) {
  19 + System.out.println("IO Exception!");
  20 + System.exit(1);
  21 + }
  22 + catch(CloneNotSupportedException e)
  23 + {
  24 + System.out.println("CloneNotSupportedException");
  25 + System.exit(1);
  26 + }
14 27 }
15   -}
16 28 \ No newline at end of file
  29 +
  30 + private void menuLoop() throws IOException, CloneNotSupportedException
  31 + {
  32 + Scanner scan = new Scanner(System.in);
  33 + ArrayList<Vehicle> arr = new ArrayList<Vehicle>();
  34 + Vehicle vehicle;
  35 +
  36 + //arr.add(new Car("Volvo","Black",85000,2010,"1010-11",163,0));
  37 + //arr.add(new Bicycle("Diamant","yellow",4000,1993,"BC100",10,0));
  38 + //arr.add(new Car("Ferrari Testarossa","red",1200000,1996,"A112",350,0));
  39 + //arr.add(new Bicycle("DBS","pink",5000,1994,"42",10,0));
  40 +
  41 + while(true)
  42 + {
  43 + System.out.println("1...................................New car");
  44 + System.out.println("2...............................New bicycle");
  45 + System.out.println("3......................Find vehicle by name");
  46 + System.out.println("4..............Show data about all vehicles");
  47 + System.out.println("5.......Change direction of a given vehicle");
  48 + System.out.println("6..............................Exit program");
  49 + System.out.println(".............................Your choice?");
  50 + int choice = scan.nextInt();
  51 +
  52 + switch (choice)
  53 + {
  54 + case 1:
  55 + //legg til en ny bil
  56 + break;
  57 + case 2:
  58 + //legg til en ny sykkel
  59 + break;
  60 + case 3:
  61 + //vis info om gitt kjøretøy
  62 + break;
  63 + case 4:
  64 + //vis info om alle kjøretøy
  65 + break;
  66 + case 5:
  67 + // Finn kjøretøy med gitt navn, sett ny retning
  68 + break;
  69 + case 6:
  70 + scan.close();
  71 + System.exit(0);
  72 + default:
  73 + System.out.println("Wrong input!");
  74 + }
  75 + }
  76 + }
  77 +}
  78 +
... ...
Vehicle.java
1 1  
  2 +package vehicle;
2 3  
3 4 import java.lang.*;
4   -import java.gui.*;
5 5  
6   -public class TestVehicle
  6 +public abstract class Vehicle
7 7 {
8   - public stat
  8 + String color;
  9 + String name;
  10 + String serialNumber;
  11 + int model;
  12 + int price;
  13 + int direction;
  14 + double speed = 0;
  15 +
  16 + public Vehicle()
  17 + {
  18 + }
  19 +
  20 + public String getColor() { return this.color; }
  21 + public void setColor(String value) { this.color = value; }
  22 +
  23 + public String getName() { return this.name; }
  24 + public void setName(String value) { this.name = value; }
  25 +
  26 + public String getSerialNumber() { return this.serialNumber; }
  27 + public void setSerialNumber(String value) { this.serialNumber = value; }
  28 +
  29 + public int getModel() { return this.model; }
  30 + public void setModel(int value) { this.model = value; }
  31 +
  32 + public int getPrice() { return this.price; }
  33 + public void setPrice(int value) { this.price = value; }
  34 +
  35 + public int getDirection() { return this.direction; }
  36 + public void setDirection(int value) { this.direction = value; }
  37 +
  38 + public double getSpeed() { return this.speed; }
  39 + public void setSpeed(double value) { this.speed = value; }
  40 +
  41 + public Vehicle(String name, String color, String serialNumber, int model, int price, int direction)
  42 + {
  43 + this.color = color;
  44 + this.name = name;
  45 + this.serialNumber = serialNumber;
  46 + this.model = model;
  47 + this.price = price;
  48 + this.direction = direction;
  49 + }
  50 +
  51 + public abstract void turnLeft(int degrees);
  52 + public abstract void turnRight(int degrees);
  53 +
9 54 }
... ...