Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA 1.Write a program that thoroughly tests the class LinkedBag. 2. Listing 3-4 shows the inner class Node with set and get methods. Revise the

JAVA

1.Write a program that thoroughly tests the class LinkedBag. 2. Listing 3-4 shows the inner class Node with set and get methods. Revise the class LinkedBag so that it invokes these set and get methods instead of accessing the private data fields data and next directly by name. 3. Listing 3-5 shows Node as a class within a package that also contains LinkedBag. Revise LinkedBag to use this version of Node. 4. Revise Node and LinkedBag as described in Segment 3.29. 5. Define a class LinkedSet that represents a set and implements the interface given in Listing 1-5 of Chapter 1. Use the class LinkedBag in your implementation. Then write a program that adequately demonstrates your implementation. 6. Repeat the previous project, but use a chain of linked nodes instead of the class LinkedBag. 7. Define a class DoublyLinkedBag that implements the ADT bag by using a doubly linked chain, as shown in Figure 3-11. Use the inner class of nodes that Exercise 12 defines. 8. Repeat the previous project, but define set and get methods in the inner class of nodes. 9. Use the classes for a set or a bag, as defined in this chapter or described in the previous projects, to create a spell checker. Consult the details given in Projects 6 and 7 of Chapter 2.

You will write the "LinkedBag" class, and a main program named "Project1.java" testing the methods defined for the LinkedBag object.

project is listed below with its references. along with interface file - Baginterface.java (picture)

image text in transcribed

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Projects 1. Write a program that thoroughly tests the class LinkedBag. 2. Listing 34 shows the inner class Node with set and get methods. Revise the class LinkedBag so that it invokes these set and get methods instead of accessing the private data fields data and next directly by 3. Listing 3-5 shows Node as a class within a package that also contains LinkedBag. Revise LinkedBag to use this name. version of Node. 4. Revise Node and LinkedBag as described in Segment 3.29. 5. Define a class LinkedSet that represents a set and implements the interface given in Listing 1-5 of Chapter 1 . Use the class LinkedBag in your implementation. Then write a program that adequately demonstrates your implementation. 6. Repeat the previous project, but use a chain of linked nodes instead of the class LinkedBag. 7. Define a class DoublyLinkedBag that implements the ADT bag by using a doubly linked chain, as shown in Figure 3-11. Use the inner class of nodes that Exercise 12 defines. 8. Repeat the previous project, but define set and get methods in the inner class of nodes. 9. Use the classes for a set or a bag, as defined in this chapter or described in the previous projects, to create a spell checker. Consult the details given in Projects 6 and 7 of Chapter 2. LISTING 3-4 The inner class Node with set and get methods private class Node f private T data; // Entry in bag private Node next; // Link to next node private Node( T dataPortion) \{ this(dataportion, nu17); 3 // end constructor private Node(T dataPortion, Node nextNode) \{ data = dataPortion; next = nextNode; \} // end constructors private T getData( return data; \} // end getData private void setData( T newData) \{ data = newData; \} // end setData private Node getNextNode() f return next; f // end getNextNode private void setNextNode(Node nextNode) \{ next = nextNode; J /I end setNextNode 3. // end Node LISTING 3-5 The dass Node with p package BagPackage: class NodecTs f private T data; private Node next; Node (T dataPortion) //. The constructor's name is Node, not NodecTs \{ this(dataportion, nu11): 3 // end constructor A Class Node That Has Set and Get Methods 123 29 As an inner class with a declared generic type. The version of LinkedBag just described in Listing 3-6 could define Node as an inner class. Node would be similar to the class given in Listing 3-5, but would require the following changes: - Omit the package statement. - Make the class, constructors, and methods private. - Replace the generic type T with another identifier, such as S. Since both LinkedBag and Node declare generic types, they must use different identifiers to represent them. Project 4 at the end of the chapter asks you to revise Node and LinkedBag as described here. A doublv linked chain for Exercises 12, 13, 14, and 15, and Project 7 An interface that describes the operations of a bag of objects. (eauthor Frank M. Carrano gauthor Timothy M. Henry (aversion 5.0 blic interface BagInterface /** Gets the current number of entries in this bag. areturn The integer number of entries currently in the bag. *l public int getcurrentSize(); I *o Sees whether this bag is empty. ereturn True if the bag is empty, or false if not. */ pubtic boolean isEmpty(); i a Adds a new entry to this bag. eparam newentry The object to be added as a new entry. greturn True if the addition is successful, or fatse if not. */ public boolean add (T newentry); I*k Removes one unspecified entry from this bag, if possible. greturn Either the removed entry, if the removal. was successful, or null. public T remove(): I*k Renoves one occurrence of a given entry fron this bag, if possible. eparam anEntry The entry to be removed. greturn True if the removal was successful, or faise if not. */ public boolean remove(T anEntry); /*k Removes all entries from this bag. */ public void clear(); / * Counts the number of times a given entry appears in this bag. eparam anEntry The entry to be counted. ereturn. The number of times anEntry appears in the bag. public int getFrequencyof (T anEntry); K* Tests whether this bag contains a given entry. eparam anEntry. The entry to find. ereturn True if the bag contains anEntry, or false if not. */ public bootean contains ( T anEntry); I* Retrieves all entries that are in this bag. areturn A newly allocated array of ail the entries in the bag. Note: If the bag is, empty, the returned array is empty. */ public TI] toArray(); Il end BagInterface

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

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago