Not so last min, last min uni work, Programing and UML

Soldato
Joined
11 Apr 2003
Posts
4,208
Location
Notts
Hi all, I have an assignment due for programing (again) and I have done very little work on UML Diagrams, My first 2 tasks are:

1) A UML use-case diagram for the system, including all important actors
who will use the system. You should also include a short commentary
on this diagram, describing the process that you used to develop the
diagram. [17%]

2) A UML class diagram, including appropriate methods and attributes
for each class in the system. Again, a commentary on your design
process should be handed in too. [16%]

The problem I have is this:

Code:
Fitzroy Bailey, the owner of Rockall Vehicle Rental Agency, wishes to set up
a stock-control system to manage hiring, invoicing, and customer records.
Bailey should be able to determine how many vehicles are on hire at a given
moment, and what the rental income to date is. The shop hires bicycles by
the half-day, cars by the week (with an additional charge if a car is used
for more than an average of 1,000 miles/week), and helicopters by the hour.
When a customer hires a vehicle, an employee must record their name and
address, and ensure that the hiring information is recorded, including the
length of time for which the vehicle has been hired. Everyone who hires a
vehicle must pay for it at the time of hiring.

Would this Use case diagram for the problem be correct?

use_Case.JPG


“A customer rents a vehicle”. This is related to both the customer, who wishes to rent, and the employee who must arrange the rental. The employee will perform a “check on the customers rental history” to see if he or she is will be loaned a vehicle, this action extends the “Rent vehicle” use case.

Once it has been decided that the customer will rent a vehicle, the action of renting the vehicle includes two actions,” invoicing the customer” for the cost of the rental (getting payment) and making sure they have what the “stock” the customer wants.

The customer also needs to “return the vehicle”, the employee again deals with this, the process of returning the vehicle included “checking how long the vehicle was out” and “issuing any extra costs” resulting in extended rentals, this will also be added to the “customers records”.

The employee will update all of the “customers records”, with details such as current rentals, reliability, return times etc. Finally the shop (or boss) will deal with hiring, and firing of staff, meaning they relate to the employee, they will also have a copy of the customer records, and be responsible for preparing the customer invoices.
 
Last edited:
Just done very similar a few weeks back. Do your actors not have to be presented on the outside of the diagram? We were doing it such that your customer was on the left, and all people that worked for/with the company were on the right, then all processes in the middle, makes it look a lot tidier. Im also pretty sure that every relationship need to be labelled, i have no sodding idea what the hell is going on in most of those links.

I also keep getting the diagrams the wrong wa around, but would your multiplicity not be in a different diagram altogether, i.e. class diagram.
 
Hows This?

usecase2.JPG


A customer, can “rent” or “return” a vehicle from the shop, each time they come in their record will be accessed, “if” they are a new customer, then a new record will be added.

If they are returning then the system will check if they returned the vehicle on time, it will also check its mileage if it is a car, and “if” need be an additional bill will be issued to the customer.

When the customer is renting, then first stock will be checked, and if the vehicle they want is in stock they will be invoiced/billed.

The employee is in charge of managing the customers records, adding additional information etc.

The shop manages the hiring of staff.

Need to make sure I have covered:

Code:
Identification of all major use cases, with clear justification
 
Last edited:
Also is this class diagram ok?

classdiagram.JPG


Shop accesses vehicle information and customer records. It stores the dates, and times in which vehicles are rented and returned, it also finds out if what the customer wants is in stock, and issues them with invoices.

Customer records holds information on the customer, their name, address and if they are currently renting anything, it also deals with rent requests and rent returns.

Vehicle stores information on the vehicles currently in stock, car, bicycle and helicopter, it finds out the mileage (If a car) and the rental duration. It also gets the cost of renting the vehicle for the set amount of time.

Need to make sure I have covered:

Code:
Correct usage of methods and attributes and relationships between classes, good narrative description

Code:
Show inheritance on class diagram
 
Last edited:
Amoeba said:
Why do you have cost and maximumRentalTime in your Vehicle subclasses, and not in Vehicle itself?
Because the cost of each vheicle is different, as is the amount of time each vheicle can be rented?
 
I think you have failed to grasp the basic concepts of OO :p Explain to me what inheritance is, and whilst you are doing it see if you can work out where you went wrong.
 
Im trying to make ths system, so I can

Find existing customers
Add new customers and assign them a customer number

Just wondering, how can I make it so the system search customer numbers, and if it finds them it fetches the details, else returns an error message, else I would have to program in each new customer, rather than letting new ones be input
 
OK I will do my best, but I am feeling ill and tired so may not make a great amount of sense ;)

Where do you keep references to all your CustomerRecord instances? From your class diagram I do not see a collection of any sort. I would suggest you have a Map of some sort (HashMap?) in the Shop class to store these. A Map essentially maps objects (key) to objects (value), and stores them - read the API for more details. In this case you could refer to your CustomerRecords by using the customer number (int).. it's as simple as doing
Code:
map.put(newCustomer.getCustomerNumber(), newCustomer)
(where newCustomer is an instance of your CustomerRecord and getCustomNumber() returns the customer number as an int. Then to retrieve it all you have to do is
Code:
map.get(123)
where 123 is the customer number you are after. If there isn't a value with key 123 then it will return null, and you can print an error.

The above hopefully answers your question about how to search your customer records for a specific customer.. However at closer inspection of your class diagram there are various mistakes.. For example, no int for customer number in CustomerRecord, various methods in Vehicle seem to be associated with variables that are not there (checkInStock()?) etc.

Also as I said before, there is no need for cost and maximumRentalTime to not be in the Vehicle class. Although they would be in the same class, the different instances of the subclasses can have different values for them :) (This is called inheritance and is one of the main ideas behind OO programming).

Sorry if I rambled a bit, I am going to bed now ;)
 
So esentialy, I can create a new object, and store in my values e.g

Customer new = new Customer(address,phoneNumber);

and each time I run this I could add it automaticaly to a hashmap, so say the first time I run, customer number = 1, second, 2 etc?

Also what is the best way to represent an address? I have never done anything that involves anything but a number, so I have no idea how to make java accept and store say 30, Land Road, England, NGR 443...
 
To add that to a HashMap you could do:

Code:
HashMap<Integer,Customer> hashmap = new HashMap<Integer,Customer>();
Customer new = new Customer(address,phoneNumber); 

hashmap.put(new.getID(),new);

Or at least I think it's something along those lines :o

A String should be sufficient to store an address, e.g.

Code:
String address = "123 A Road";

edit:

A quick example I threw together in Netbeans:

Code:
import java.util.HashMap;

public class Main {
    
    int id;
    String name;
    
    /** Creates a new instance of Main */
    public Main(int id, String name) {
        this.id = id;
        this.name = name;
    }
    
    public int getID() {
        return id;
    }
    
    public String getName() {
        return name;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        HashMap<Integer,Main> hashmap = new HashMap<Integer,Main>();
        Main main = new Main(123,"Test Object"); 

        hashmap.put(main.getID(),main);
        
        System.out.println(hashmap.get(123).getName());
    }
}

Prints out:

Code:
Test Object
 
Last edited:
Some reason it wont accept .put, and I had to alter quite abit of the code for it to compile
 
Last edited:
Strange, I just copy and pasted that in to notepad and used javac/java instead of Netbeans and it compiled/ran fine :confused:

Which bits did you have to alter?
 
Phil99 said:
Strange, I just copy and pasted that in to notepad and used javac/java instead of Netbeans and it compiled/ran fine :confused:

Which bits did you have to alter?

Well so far I have this:

Code:
import java.util.HashMap;

public class Test {
    
    int id;
    String name;
    
    /** Creates a new instance of Main */
    public Test(int id, String name) {
        this.id = id;
        this.name = name;
    }
    
    public int getID() {
        return id;
    }
    
    public String getName() {
        return name;
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        HashMap hashmap = new HashMap();
        Test test = new Test(1,"Food Is Yummy"); 
        Test test2 = new Test(2,"You Suck");
        

        hashmap.put(test.getID());
        
        System.out.println(hashmap.get(1).getName());
        System.out.println(hashmap.get(2).getName());
        System.out.println(hashmap.get(1).getName());
    }
}

Im using BlueJ To compile and atm its returning cannot resolve symbol - metod put(int)
 
jcb33 said:
Well so far I have this:

Im using BlueJ To compile and atm its returning cannot resolve symbol - metod put(int)

Looks like you forgot to tell the HashMap what types of variables to expect (look up Generics for more info)

Code:
HashMap[b]<Integer,Test>[/b] hashmap = new HashMap[b]<Integer,Test>[/b]();

You also need to pass the object you want to be stored with relation to the key you're supplying to the put() method as well otherwise you're just trying to store a key with nothing actually linked to it.

The bits in the < > tell it what to expect; the first (Integer) is the type of object the key should be and the second is the type the value you want it to return when you look up the key should be.

With the HashMap above the method signature for the put method in the HashMap object would look something like this:

Code:
public void put(int key, Test value)

If that helps to explain it at all.

The API explains more: http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html
 
Last edited:
Back
Top Bottom