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

Give a Uml diagram illustarting aggregation. Include classes, fields methods instance fields etc. Use one supper...
Give a Uml diagram illustarting aggregation. Include classes, fields methods instance fields etc. Use one supper class and two sub classes includes pseudo code for at least one method of each class. also expalin the whole part relationship in detail.
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.
Activity 10: Methods of Coping For each of the following situations, give one example of an...
Activity 10: Methods of Coping For each of the following situations, give one example of an emotion-focused method of coping (i.e., seeking sympathy, rationalizing, redirection of attention) and one example of a problem-focused method of coping (i.e., taking direct action to deal with the problem). You can review pgs. 523-538 (section 14.4) for a refresher on what an emotion-focused and problem-focused method are. One of your co-workers avoids you and describes you in an unfavorable and mean way to others....
Provide an example of a research plan that would use a one-way ANOVA. Include in your...
Provide an example of a research plan that would use a one-way ANOVA. Include in your example the IV & DV and what you would do with the data you are collecting and how the groups are formed.
On your own words, talk briefly about two of the inventory costing methods, give one example...
On your own words, talk briefly about two of the inventory costing methods, give one example of each method.
Heuristics are mental shortcuts. Select one and give me an example of how you use it...
Heuristics are mental shortcuts. Select one and give me an example of how you use it when you shop.
1. Use reverse assumption analysis to analyze an University. 2. Give one example of a retailer...
1. Use reverse assumption analysis to analyze an University. 2. Give one example of a retailer that uses standalone stores as opposed to stores located in malls. Why do you think retailers opt for this sales channel?
1. Explain one mechanism that bacteria use to become resistant to antibiotics. Give one example of an antibiotic-resistant bacterium.
  1. Explain one mechanism that bacteria use to become resistant to antibiotics. Give one example of an antibiotic-resistant bacterium. 2. Explain one reason why Healthcare-Associated Infections (HAIs) are on the rise. Give one example of an HAI.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT