Question

In: Computer Science

Give a UML example illustrating aggregation. Include classes, fields, methods, instance fields etc. Use one supper...

Give a UML example illustrating aggregation. Include classes, fields, methods, instance fields etc. Use one supper class and two sub classes. Include pseudo code for at least one method of each class. (Put your name on every piece of paper). Also explain the whole part relationship and if this is a deep copy or a shallow copy?

PROGRAMMING LANGUAGE - JAVA (IF NEEDED)

PLEASE ANSWER IT ASAP. THANKS IN ADVANCE!

Solutions

Expert Solution

Description : Aggregation is a special form of association. It is a relationship between two classes like association, however its a directional association, which means it is strictly a one way association. It represents a HAS-A relationship.

2. For example consider three classes Student class and Address class. Every student has an address so the relationship between student and address is a Has-A relationship. But if you consider its vice versa then it would not make any sense as an Address doesn’t need to have a Student necessarily.

Same with the class collages ,Every collage has an address so the relationship between collage and address is a Has-A relationship.

we need AggregationTo maintain code re-usability.

Student Has-A Address (Has-a relationship between student and address)
College Has-A Address (Has-a relationship between college and address)

UMAL diagram forAggregation

pseudo code:

class Address
{
   int streetNum;
   String city;
   String state;
   String country;
   Address(int street, String c, String st, String coun)
   {
       this.streetNum=street;
       this.city =c;
       this.state = st;
       this.country = coun;
   }
}
class StudentClass
{
   int rollNum;
   String studentName;
   //Creating HAS-A relationship with Address class
   Address studentAddr; 
   StudentClass(int roll, String name, Address addr){
       this.rollNum=roll;
       this.studentName=name;
       this.studentAddr = addr;
   }
   ...
}
class College
{
   String collegeName;
   //Creating HAS-A relationship with Address class
   Address collegeAddr; 
   College(String name, Address addr){
       this.collegeName = name;
       this.collegeAddr = addr;
   }
   ...
}

Related Solutions

1. Describe the difference between instance methods and class methods in Java and give an example...
1. Describe the difference between instance methods and class methods in Java and give an example of each. 2. A class variable is visible to and shared by all instances of a class. How would such a variable be used in an application? 3. Describe the difference between abstract classes and concrete classes, giving an example of each. 4. Explain how data are encapsulated and information is hidden in Java? 5. Explain the difference between a class and an interface...
Q What is a quality use case in UML? Give an example of it?
Q What is a quality use case in UML? Give an example of it?
Give examples of chemical methods of disinfection and the advantages and disadvantages of each example, include...
Give examples of chemical methods of disinfection and the advantages and disadvantages of each example, include alcohols, Halogens, phenol and phenolics, biguanides, bisphenols and heavy metals.
Use JAVA BASICS  classes, aggregation and manipulating arrays of objects. I DO NOT WANT THE SAME SOLUTION...
Use JAVA BASICS  classes, aggregation and manipulating arrays of objects. I DO NOT WANT THE SAME SOLUTION WHICH ALREADY EXISTS ON CHEG. DO NO USE ARRAY LIST Scenario: A dog shelter would like a simple system to keep track of all the dogs that pass through the facility. The system must record for each dog: dogId (int) - must be unique name (string) age (double) - cannot be less than 0 or more than 25 breed (string) sex (char) – m...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and width) as the calling object, this method should...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and width) as the calling object, this method should...
Interrupts are used in many fields of industry. Give an example of the applications of interrupt....
Interrupts are used in many fields of industry. Give an example of the applications of interrupt. You can also share the interrupts that may be use in your senior project.
Objectives • Use the static methods and static fields. •Use the method-call/return mechanism. • Use the...
Objectives • Use the static methods and static fields. •Use the method-call/return mechanism. • Use the random-number generation. • Overload methods. Problem Specification Write a program that lets a user play "Rock, Paper, Scissors" against the computer or computer against computer. In user-computer game, the program should ask the user to choose one of the three choices, and then the computer randomly picks one (without knowing what the user has chosen). For this problem, the user should be asked to...
What is meant by the term sustainability and explain its 3 aspects? Include an example illustrating your comments.
                                                                                  The following is an extract from the latest sustainability report (2019) of the Woolworths Group: “It is through the power of partnerships that we will be able to amplify our impact and deliver on our bold ambitions to become...
What are the diagrams defined in the UML Standard. Give a one or two sentence description...
What are the diagrams defined in the UML Standard. Give a one or two sentence description of each one.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT