Last min uni work very quick thing UML

Soldato
Joined
11 Apr 2003
Posts
4,261
Location
Notts
Hi all, just wanted to check if I had gotten this UML Class diagram correct:

It needs to display objects, vectors etc?

Also, I have overide methods in car, bicycle and helicopter for cost, duration etc, do I need to show them? How?

clas%20diagram.JPG


Thanks!!
 
Well the reason I ask is im using inheritance, the car does not have its own methods, just its own values... as below

Vehicle:

Code:
/*This class is the parent class for the vehicles car, bike and helicopter, it sets several methods.*/

public class Vehicle {

   protected int cost; //This int is used in getCost.
   protected int rent; //This int is used in getRent.
   protected int mile; //This int is used in getMile.
   protected int type; //This int is used in getType.
   protected boolean inStock; //This boolean is used in getStock and setStock.
   protected int duration; //This int is used in getDuration.
   protected int totalCost; //This int is used in getTotalCost.
   protected int mileTotal; //This int is used in getMileTotal.
  
   public Vehicle(int c, int r, int m, int t, boolean i, int d, int tc, int mm) {
        cost = c; //This defines cost as c.
        rent = r; //This defines rent as r.
        mile = m; //This defines mile as m.
        type = t; //This defines type as t.
        inStock = i; //This defines inStock as i.
        duration = d; //This defines duration as d.
        totalCost = tc; //This defines totalCost as tc.
        mileTotal = mm; //This defines mileTotal as mm.
     }
    public int getCost() { //This will get the cost of a vehicle.
        return this.cost;
    }
    public int getRent() { //This will get the amount of time for one vehicle rental period.
        return this.rent;
    }
    public int getMile() { //This will return the max allowed miles per rental period, where applicable.
        return this.mile;
    }
    public int getType() { //This is used in defining what type of vehicle a vehicle is.
        return this.type;
    }
    public boolean getStock() { //This is used to check whether a specific vehicle is in stock.
        return this.inStock;
    }
    public void setStock(boolean inStock) { //This is used to update the stock information of a vehicle, true for instock, false for out of stock.
        this.inStock = inStock;
    }
    public int getDuration() { //This is used to get the total duration a vehicle is being rented for.
        return this.duration;
    }
    public int getTotalCost() { //This is used to get the total cost of a rental.
        return this.totalCost;
    }
    public int getMileTotal() { //This is used to get the total allowed miles, where aplicable.
        return this.mileTotal;
    }
}

Car:

Code:
/*This class extends the vehicle class, inheriting properties from it, and defining its own values where apropriate.*/

public class Car extends Vehicle {

    public Car(int cost, int rent, int mile, int type, boolean inStock, int duration, int totalCost, int mileTotal) {
        super(cost, rent, mile, type, inStock, duration, totalCost, mileTotal); 
    }
    public int getCost() { //This sets the cost of one rental period to 250.
        return (250);
    }
    public int getRent() { //This sets the max time per rental period to 168.
        return (168);
    }
    public int getMile() { //This sets the max number of miles per rental period to 1000.
        return (1000);
    }
    public int getType() { //This defines what type of vehicle this is. 
        return 1;
    }
}
 
Welshy said:
As they're inherited, it's implied that the class already has access to them, so you don't need to put them in them. Ignore my first post.
Thanks, will leave it as it is then :) Almost finished my testing as well, so yay!
 
Back
Top Bottom