Question: I am having difficulty setting up the Iterator and CourseIterator JAVA Assignment Class: Holds the details of an assignment toString(): returns a string representation of

I am having difficulty setting up the Iterator and CourseIterator

JAVA

Assignment Class:

Holds the details of an assignment

toString(): returns a string representation of title, description, and topic

Course Class:

Holds an array of max 5 assignments, when you reach the end of the array, the array will double in size

Holds the name and title of the course

addAssignment -> Accepts the assignment, title, description, topic and points

createIterator -> returns a new CourseIterator using the Assignment array

getAssignmentWeights -> returns to you the weight of each assignment, assuming they are all equally weighted out of 100

toString -> returns a string representation of the name and title of the course

growArray(Assignment[] first): returns an array of twice the size with the same data

CourseIterator Class:

Implements the java.util Iterator

Constructor -> accepts an array of assignments

next(): Returns the next assignment, if there is one, and null otherwise

hasNext(): returns true if there more assignments to iterate over

Course - assignments: Assignment[] - count: int - name: String - title: String

+ Course(String name) + addAssignment(String title, String description, String topic, int points) + createIterator(): CourseIterator + getAssignmentWeights(): double + toString(): String - growArray(Assignment[] first): Assignment[]

<> Iterator + hasNext(): bool + next(): Object

Assignment - title: String - description: String - topic: String - points: int + Assignment(String title, String description, String topic, int points) + toSring(): String

CourseIterator - assignments: Assignment[] - position: int + CourseIterator(Assignment[] assignments) + hasNext(): bool + next(): Assignment

public class CourseDriver {

public static void main(String[] args) { Course csce247 = new Course("CSCE 247", "Software Engineering"); csce247.addAssignment("Strategy Design Pattern", "Implement the Stragety Design Pattern to build robots", "Design Patterns", 10); csce247.addAssignment("Observer Design Pattern", "Implement the Observer Design Pattern to similate a baby cry", "Design Patterns", 10); csce247.addAssignment("Decorator Design Pattern", "Implement the Decorator Design Pattern to build Christmas trees", "Design Patterns", 10); csce247.addAssignment("Factory Design Pattern", "Implement the Factory Design Pattern to build cereal", "Design Patterns", 10); csce247.addAssignment("Singleton Design Pattern", "Implement the Singleton Design Pattern to build a library", "Design Patterns", 10); csce247.addAssignment("Command Design Pattern", "Implement the Command Design Pattern to build a Document Editor", "Design Patterns", 10); csce247.addAssignment("Adapter Design Pattern", "Implement the Adapter Design Pattern to build a CD to Cassette Converter", "Design Patterns", 10); csce247.addAssignment("Template Design Pattern", "Implement the Template Design Pattern to simulate a worker", "Design Patterns", 10); csce247.addAssignment("Iterator Design Pattern", "Implement the Iterator Design Pattern to loop over assignments", "Design Patterns", 10); CourseIterator assignmentIterator = csce247.createIterator(); System.out.println("******** " + csce247 + " ******** "); System.out.println("Assignment List:"); while(assignmentIterator.hasNext()) { Assignment assignment = assignmentIterator.next(); System.out.println("- " + assignment); } System.out.println(" Each assignment has a weight of: " + csce247.getAssignmentWeights() + " %"); } }

Sample Output

Assignment List: - Strategy Design Pattern: Implement the Stragety Design Pattern to build robots, covers: Design Patterns - Observer Design Pattern: Implement the Observer Design Pattern to similate a baby cry, covers: Design Patterns - Decorator Design Pattern: Implement the Decorator Design Pattern to build Christmas trees, covers: Design Patterns - Factory Design Pattern: Implement the Factory Design Pattern to build cereal, covers: Design Patterns - Singleton Design Pattern: Implement the Singleton Design Pattern to build a library, covers: Design Patterns - Command Design Pattern: Implement the Command Design Pattern to build a Document Editor, covers: Design Patterns - Adapter Design Pattern: Implement the Adapter Design Pattern to build a CD to Cassette Converter, covers: Design Patterns - Template Design Pattern: Implement the Template Design Pattern to simulate a worker, covers: Design Patterns - Iterator Design Pattern: Implement the Iterator Design Pattern to loop over assignments, covers: Design Patterns

Each assignment has a weight of: 11.0 %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!