Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. a) Write Java code with appropriate documentation comments to define a generic Java interface named TreeADT. This interface should specify FOUR typical operations applicable

image text in transcribedimage text in transcribed

6. a) Write Java code with appropriate documentation comments to define a generic Java interface named TreeADT. This interface should specify FOUR typical operations applicable to a tree only. Instances of classes which implement TreeADT must also support the operation of an enhanced for statement. (10 marks) b) Consider the following definitions for classes LinkedNode and LinkedMultiSet. Class LinkedNode is expected to model a node in a linear linked structure designed to model a generic collection. public class LinkedNode { 2 3 private T element; private LinkedNode next; 5 6 7 // Constructor(s) omitted /** Returns the node that follows this one. +/ public LinkedNode next() { return next; } 10 11 12 13 14 /** Sets the node that follows this one. +/ public void set Next (LinkedNode node) { next = node; 15 16 17 } 18 19 20 21 /*+ Returns the element stored in this node. / public i element() { return element; 23 24 25 28 27 /+* Sets the element stored in this node. / public void setElement (T elem) element - elem; 1 2 (Question 6 continued...) import java.util.Iterator; 3 public class LinkedMultiSet implements MultiSetADT { // the first node in the LinkedMultiSet private LinkedNode contents; // constructors and other method implementation omitted 4 5 7 8 9 10 public int size() { // implementation detail omitted 1 11 12 13 14 15 16 public boolean contains (I element) { // implementation detail omitted 17) i) Class LinkedNode contains an error. Identify the error in class LinkedNode and explain TWO issues this error would cause Write out the required modification(s) to class LinkedNode so as to correct the error identified in your answer. You must clearly indicate the location of your modification(s) using the given line numbers. (7 marks) ii) Write a public method for class LinkedMultiSet that returns the sum of a LinkedMultiSet object and a specified MultiSet ADT object. (8 marks)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions