Skip to main content
eick-at moodle
  • Home
  • Calendar
  • More
You are currently using guest access
Log in
eick-at moodle
Home Calendar
Expand all Collapse all
  1. OOP with JAVA
  2. Basics of object-oriented programming with Java
  3. Task: Use case diagram, class diagram, object diagram and sequence diagram

Task: Use case diagram, class diagram, object diagram and sequence diagram

Completion requirements
Opened: Sunday, 5 May 2019, 12:00 AM
Due: Sunday, 5 May 2019, 12:00 AM

Draw use case diagram, class diagram, object diagram and sequence diagram for the following program code:

 1 public class Checkout {
 2     private String name;
 3     private double cashInsert;
 4     private double cashPosition;
 5 
 6     public Checkout(String name, double cashInsert, double cashPosition)
 7     {
 8         this.name = name;
 9         this.cashInsert = cashInsert;
10         this.cashPosition = cashPosition;
11     }
12     public double getCashInsert()
13     {
14         return cashInsert;
15     }
16     public double getCashPosition()
17     {
18         return cashPosition;
19     }
20 }

 1 import java.util.ArrayList;
 2 
 3 public class Supermarket {
 4     String name;
 5     private double totalDayTaking;
 6     ArrayList<Checkout> checkouts = new ArrayList<Checkout>();
 7 
 8     public Supermarket(String name)
 9     {
10         this.name = name;
11     }
12     public void addCheckout(Checkout k)
13     {
14         checkouts.add(k);
15     }
16     public double calculateDayTakings()
17     {
18         totalDayTaking = 0;
19         for (Checkout checkout: checkouts)
20             totalDayTaking += checkout.getCashPosition() - checkout.getCashInsert();
21         return totalDayTaking;
22     }
23 }

 1 import java.util.ArrayList;
 2 
 3 public class MainOffice {
 4 
 5     ArrayList<Supermarket> supermarkets = new ArrayList<>();
 6 
 7     public void addSupermarket(Supermarket Supermarket)
 8     {
 9         supermarkets.add(Supermarket);
10     }
11     public double calculateTotalDayTakings()
12     {
13         double totalDayTakings = 0;
14         for (Supermarket Supermarket: supermarkets)
15             totalDayTakings += Supermarket.calculateDayTakings();
16         return totalDayTakings;
17     }
18 }


 1 public class Main {
 2 
 3     public static void main(String[] args) {
 4 
 5         MainOffice mo1 = new MainOffice();
 6         Supermarket s1 = new Supermarket("Walmart");
 7         Supermarket s2 = new Supermarket("Aldi");
 8 
 9         // Aggregation
10         mo1.addSupermarket(s1);
11         mo1.addSupermarket(s2);
12 
13         // Composition
14         s1.addCheckout(new Checkout("Checkout 1", 250, 1700));
15         s1.addCheckout(new Checkout("Checkout 2", 125, 1279));
16 
17         s2.addCheckout(new Checkout("South 1", 125, 1279));
18         s2.addCheckout(new Checkout("South 2", 46, 865));
19         s2.addCheckout(new Checkout("North 1", 74, 523));
20 
21         System.out.println(mo1.calculateTotalDayTakings());
22     }
23 }
You are currently using guest access (Log in)
Data retention summary
Get the mobile app
Powered by Moodle