This is the question...
When writing an aggregate class, you should be careful not to unintentionally create "security holes" that can allow code outside the class to modify private data inside the class.
In this example, the Course class is an aggregate class; it has instructor(a String) and a textbook (a Book) objects as fields.
The UML Diagram for the Course class is below:
+ instructor: String
+ textbook: Book
+ getInstructor(): String
+ getTextbook(): Book
Book is a class that has author (a String) and title (a String) as fields.
The UML Diagram for the Book class is below:
- author: String
- title: String
+ Book():
+ getAuthor():String
+ getTitle(): String
+ setAuthor(au:String): void
+ setTitle(ti:String): void
You are given the partial definition of the Course class to modify. Define TWQ (2) methods- getInstructor() and getTextbook()for the Course class. The getInstructor returns the instructor field and getTextbook returns a copy of the textbook object. (Refer to the UML diagram of Course class above.)
(NOTE: Do not worry about writing the definiton of the Book class. It has already been defined for you. You can call the methods in the Book class specified in the UML Diagram.)
// Use the following startup code:
class Course{
public String instructor;
public Book textbook;
// ----Insert Your Code Below ----
//--------End of Your Code ----
}//end class
And this is the code I have so far, but I cannot get the getTextbook() method correct.
When writing an aggregate class, you should be careful not to unintentionally create "security holes" that can allow code outside the class to modify private data inside the class.
In this example, the Course class is an aggregate class; it has instructor(a String) and a textbook (a Book) objects as fields.
The UML Diagram for the Course class is below:
+ instructor: String
+ textbook: Book
+ getInstructor(): String
+ getTextbook(): Book
Book is a class that has author (a String) and title (a String) as fields.
The UML Diagram for the Book class is below:
- author: String
- title: String
+ Book():
+ getAuthor():String
+ getTitle(): String
+ setAuthor(au:String): void
+ setTitle(ti:String): void
You are given the partial definition of the Course class to modify. Define TWQ (2) methods- getInstructor() and getTextbook()for the Course class. The getInstructor returns the instructor field and getTextbook returns a copy of the textbook object. (Refer to the UML diagram of Course class above.)
(NOTE: Do not worry about writing the definiton of the Book class. It has already been defined for you. You can call the methods in the Book class specified in the UML Diagram.)
// Use the following startup code:
class Course{
public String instructor;
public Book textbook;
// ----Insert Your Code Below ----
//--------End of Your Code ----
}//end class
And this is the code I have so far, but I cannot get the getTextbook() method correct.
public String getInstructor()
{
return instructor;
}
public Book getTextbook()
{
textbook = new Book(textbook);
}
}