Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What does it mean - in your own words - to think in terms of objects? 2. Defi

ID: 3797629 • Letter: 1

Question

1. What does it mean - in your own words - to think in terms of objects?

2. Define in your own words the 3 Class Relationships in section 10.4

Answer Questions

What is association? What is aggregation? What is composition?

How do you convert an integer into a string? How do you convert a numeric string into an integer? How do you convert a double number into a string? How do you convert a numeric string into a double value?

What is the difference between StringBuilder and StringBuffer?

What is the internal storage for characters in a string and a string builder?

10.4. Association Assaelation is a general binary relationship that describes an activity between two classes. For example, a student taking course is an asociation between the Student class and the Course class, and a faculty member teaching a course is an association between the Faculty class and the Course class. These associations can be represented in UML graphical notation, as shown in Figure 10.4. Take FIGURE 10.4 This UML diagram shows that a student may take any number of courses. a faculty member may teach at most three courses, course may have from five to sixty stu- dents, and a course is taught by only one faculty member. An association is illustrated by a solid line between two classes with an optional label that describes the relationship. In Figure laA, the labels are Tale and Teach. Each relationship may have an optional small black triangle that indicates the direction of the relationship. In this figure, the direction indicates that a student takes a course as opposed to a course student). Each class involved in the relationship may haveamle namethatdescribes the role i plays in the relationship. In Figure 10.A teacher is the role name for Faculty. Each class involved in an association may specify a multiplicity, which is placed at the multiplicity side of the class to specify how many of the class's objects are involved in the relationship in UML. A multiplicity could be a number or an interval that specifies how many of the class's objects are involved in the relationship. The character means an unlimited number of objects, and the interval indicates that the number of objects is between m and n, usively. In Figure 10.4, each student may take any number of courses, and each course must have at least five and at most sixty students. Each course is taught by only member, and a faculty member may teach from zero to three courses per semester. In Java code, you can implement associations by using data fields and methods. For exam- ple, the relationships in Figure 10.4 may be implemented using the classes in Figure 105. The

Explanation / Answer

1)
Association :
Association is a kind of relation between entities or objects.
An association can be one-many, many-many,many-one
relationships.
For example, student and Teacher has association.
Teacher taught student(s).
One teacher can teach multiple students.
One teacher taught one student.
Multiple teachers taught multiple students.


Aggregation :
Aggregation is a special kind of association.
One object contains anohter object called as aggregation.
In general, aggregation means "has-a" relationship.
For example, Car "has a " steering.
Store "has " item(s)

Composition:
Composition is another form of association.
Composition is a strong and the inner object completely
depends on its owning object and one without other cannot
exist.

For example, Customer have an account.
An account cannot exist without an Customer.
Whenever a customer is created, then Account also
be created in a Bank.Without account, no customer
exists.

2)

Conversion of integer to string
int value=10;
String value=Integer.toString(value);

Conversion of string to integer
string value="10";
int n=Integer.parseInt(value);

Conversion of double to string
double value=9.5;
String value=Double.toString(value);

Conversion of string to double
string value="10";
double n=Double.parseDouble(value);

3)
Difference between StringBuilder and StringBuffer is
synchronization.

StringBuffer is synchronized. When the java program
using threads to modify the content of the stringBuffer
using the methods , the contect of string is preserved
against modifying the threads in synchronized order.
Thread safety is most important when the critical section
of code is executed in program by several methods to
preserve its consistency.

Where as StringBuilder cannot support synchronized
feature for thread safety.


4)
String stores characters in a fixed length array of memory size.
String immutatble(cannot be modifiable).

StringBuilder is mutable.It creats a array of intial size of length 16.
Then stores the chracters in the stringBuilder.

The append method of StringBuilder class ensures the size
of the string builder using ensureCapacity method.
StringBuilder creates a new length for the character inserted
into the stringbuilder object.