anon1996
anon1996

Reputation: 41

Converting Java Code to a UML diagram

I have to convert the following Java code to a UML diagram, however I'm not sure whether I have done the associations between the classes correctly. Please you advise me whether or not the UML diagram is correct.

public class Booking {

    private String name;

    private Time time;

    private Table[] tables;

    public Booking ( String n, int st, int en, int num ){
    }

    public int getStart (  ){
        return 1;
    }

    public int getEnd (  ){
        return 1;
    }

    public Table[] getTables (  ){
        return new Table[3];
    }

    public int getBookingSize (  ){
        return 1;
    }
}
public class Time {

    private int startHour;

    private int endHour;

    public Time ( int st, int en ){
    }

    public int getStart (  ){
        return 1;
    }

    public int getEnd (  ){
        return 1;
    }
}
public class Table {

    private int number;

    private int seats;

    public Table ( int num, int sz ){
    }

    public int getNumber (  ){
        return 1;
    }

    public int getSeats (  ){
        return 1;
    }
}
public class Restaurant {

    private Booking[] bookings;

    public void makeBooking ( String n, int st, int en, int s ){
    }


    public void cancelBooking ( String n ){
    }

    public Table[] getTables ( String n ){
        return new Table[2];
    }

    public int getStTime (String n) {
        return 1;
    }

    public int getEndTime (String n) {
        return 1;
    }
}

enter image description here

Upvotes: 2

Views: 9162

Answers (2)

Msai 143
Msai 143

Reputation: 1

 +------------------+                     +--------------------+
 |  Input Text     |                     |  Pre-processing   |
 | (Plant Symptoms)|                     | (Tokenization,    |
 |                  |                     |  Embedding, etc.) |
 +--------+---------+                     +--------+-----------+
          |                                          |
 +--------v-----------+         +--------------------v-------------+
 |  Language Model    |         |    Convolutional Neural Network  |
 | (ULM)               |         |       (CNN) for Image Analysis  |
 |                     |         |                                |
 |    +------------+   |         |   +-------------+  +--------+ |
 |    | LSTM Layer |   |         |   | Convolution |  | Fully  | |
 |    | 1          |   |         |   |  Layers     |  |   Connected| |
 |    +------------+   |         |   +-------------+  |  Layers  | |
 |          |          |         |            |        +----------+ |
 |    +-----v-----+    |         |   +--------v-------+            |
 |    | LSTM Layer |    |         |   |   Pooling Layer |            |
 |    | 2          |    |         |   |    (e.g. Max)    |            |
 |    +------------+    |         |   +------------------+            |
 |          |          |         |            |                       |
 |    +-----v-----+    |         |   +--------v-------+            |
 |    | LSTM Layer |    |         |   |  Flatten Layer  |            |
 |    | 3          |    |         |   +------------------+            |
 |    +------------+    |         |            |                       |
 |          |          |         |   +--------v-------+            |
 |    +-----v-----+    |         |   | Fully Connected |            |
 |    |  Output    |    |         |   |    Layers for    |            |
 |    |  Layer     |    |         |   |  Classification  |            |
 |    +------------+    |         |   +------------------+            |
 |          |          |         |            |                       |
 +----------v----------+         +------------v-----------------------+
            |                                      |
 +----------v----------+                           |
 |  Softmax Activation |                           |
 |  (Output Probabilities)|                        |
 +----------------------+                           |
                                                  |
                                    +------------v----------------+
                                    |    Disease Prediction    |
                                    |    (e.g. Healthy,       |
                                    |     Diseased, etc.)     |
                                    +--------------------------+

Upvotes: -1

Peter Uhnak
Peter Uhnak

Reputation: 10197

I will ignore methods and attributes, because they are trivial and not interesting (and getters should ideally be omitted).

enter image description here

There are several differences to your diagram:

  • Restaurant may not have any bookings at all, so it should be *, and not 1..*
  • Booking needs only one Time, because Time already contains the start and end
  • I don't know why Restaurant has start and end time. I will assume it's to show opening hours (which is a single instance of a Time.
  • According to your code you can have Booking on more than one Table. In your diagram only one was possible.
  • One Table may have many Bookings. In your diagram it could have only one. (Of course there is run-time constraint that two Bookings shouldn't book the same Table within the same Time period, but that should be expressed in OCL or as a note)
  • Added role names to the association endpoints (period,openingHours,...)

More notes:

  • Time should either contain a single time, or it should be renamed to Period or TimeInterval. The current naming is confusing.
  • Multiplicity on the other side of relations from Time can be omitted (since they do not have much meaning here).

Upvotes: 1

Related Questions