UML Class Example public class Sales private String
UML Class Example public class Sales{ private String name; private double[] monthly. Profit; public // } public // } } Sales(String name 1){ void read. Profits(){ void display. Profits(){ double highest. Profit(){ Sales - name: string - monthly. Profit : double[] + + + Sales(in name 1: string) read. Profits(): void display. Info(): void highest. Profit(): double Total. Profit(): double deserve. Bonus(in amount: double): boolean double total. Profit(){ boolean deserve. Bonus(double amount){
If you have trouble remembering the difference between composition and aggregation, just think of the alphabet. Composition means destroy and the letters 'c' and 'd' are next to each other.
+ Purchase Order After adding one product PRP 1 Calling Environment Product p
+ After adding one product Product Group PDP 1 Calling Environment Copy Product p
UML Object Models: Aggregation, and Composition Example 3: Car - name : string -id : string -seat. Nb : int -year : int -ncel : int +Car(in n : string, in d : string, in s : int, in y : int, in size : int) +display() +is. Full() : bool +copy. Car(in ca : Car) +add. Element(in el : Car. Elements) : bool +Price. Car() : double +. . . (in. . ) * 1 Ksu. Cars -nbc : int +Ksu. Cars(in size : int) +display() +is. Empty() : bool +search. Car(in ce : string) : int +get. Car(in nm : string) : Car +Average. Price(in y : int) : double +. . (in. . . . ) +remove(in s : string) : bool Car. Elements -code : string -price : double 1 * +Car. Elements(in c : string, in p : double) +Car. Element(in E : Car. Elements) +display() +. . . (in. . )
Question: Implement all the classes with all their methods using the following descriptions. Description of the different classes: Class Car. Elements: ü The method display () displays the code and the price. ü + ……. . (in ……. . ) : if you need an other methods in this class you can add it. You can’t add another constructor. Class Car: · name • id • seat. Nb : Number of seats · year : Production year of car · ncel : number of Car. Elements object currently in an object of the class Car. · And other attribute(s) deduced from the UML diagram. ü display (): Displays all the attributes of an object Car. ü add. Element (Car. Elements el): This method receives a Car. Elements object and adds it to the Car object. ü price. Car(): Returns the sum of the Car. Elements price in an object of the class Car. + ……. . (in ……. . ) : if you need an other methods in this class you can add it. Class Ksu. Cars: · nbc : number of Car currently in an object of the class Ksu. Car. · And other attribute(s) deduced from the UML diagram. ü display (): Displays all the attributes of an object Ksu. Cars. ü search (String ce): This method receives a String representing the name of a Car object and returns the array index of the car object. ü get. Car (String nm): This method receives a String representing the id of a Car object and returns the Car object if it’s exist. ü remove. Car (String s): Removes a Car according to its name. It will return a value true if the operation has been completed successfully, or false if not. ü Average. Price(int y): Calculates the average price of all car in an object of class Ksu. Cars that produced after the year y. ü + ……. . (in ……. . ) : if you need an other methods in this class you can add it.
Case Study • For each of the three UML class descriptions, write the corresponding java code. • Write a class with a main method to test the three classes (Test the “add” methods)
- Slides: 24