Classes

  1. Model the diagram shown on this slide with Rational Rose. Use the correct semantic entities for names, attributes, types, operations etc.
  2. Draw a class diagram for the following Java code:
    class Account {
    
       public String PIN;
       public String name;
       public int balance = 0;
       
    }
    
    interface CardUse {
    
       public int read(String PIN);
       public void reduceBy(int amount, String PIN);
    
    }
    
    class BankCard implements CardUse {
    
       private int usage = 0;
       private String owner;
       private Bank bank;
       
       public int read(String PIN) {...} 
       public void reduceBy(int amount, String PIN) {...}
        
    }
    
    class Bank {
    
      private Account [] accounts = new Account [10];
      private int number = 0;
    
      private Account findAccount(String name, String PIN) {...}
      public int getBalance(String PIN, String name) { ... }
      public String createAccount(String name, int startAmount) { ... }
      public CardUse getBankCard(String name, String PIN) { ... }
    }
  3. In the public transport persons are moved by transport vehicles between locations. This slide shows the use case. Implement the use case using Rational Rose. Below you find a short description of the use case. Double click on the use case and implement the description as class diagram.

    In the public transport system we find a transport vehicle. The transport vehicle can move a certain amount of people (with a maximum capacity) from location A to location B, but we do not know how this is done (it is abstract!); the transport vehicle may be standing at a location or it may be moving to a certain other location until it arrives at its destination. When it stands people may enter or leave the vehicle; never more people than the maximum capacity may be in the vehicle. We will never find a pure transport device in reality. A bus is a special transport device that moves on land, a boat is a transport device that moves on water. Both move at a maximum speed (for the car in km/h, for the boat on knots). The boat has a draught (how deep the water needs to be so that it can move). The bus has two doors that may be openend or closed. An amphibious bus is as well a bus as a boat.

  4. Implement the class diagram of exercise 1 above using Java.

Software Systems Institute ge.schroeder, jan-1999