Question: Please help using JAVA and show the OUTPUT Create the Intcoll5 class and run Intcoll5client. Incoll5 has one private data member c of type LinkedList
Please help using JAVA and show the OUTPUT
Create the Intcoll5 class and run Intcoll5client. Incoll5 has one private data member c of type LinkedList . Below are some of Intcoll5's methods and you need to write the code for the rest of its methods. Use only methods that appear in the LinkedListsDemo program we went over in class.
public Intcoll5(int i) { c = new LinkedList (); }
public void insert(int i)
{
Integer I=new Integer(i);
if ((i>0)&&(!c.contains(i))) { c.addFirst(I); }
}
The copy method should have the integers on the copied list in the same order
as they appear on obj's list.
****Below is the Generic Linked List program to help you*****
import java.util.*;
public class LinkedListsDemo
{
public static void main(String[] args)
{
LinkedList
LinkedList
LinkedList
int i=1;
while (i<=10)
{
Integerlist.add(new Integer(i));
i++;
}
System.out.println();
System.out.println("Integerlist has "+Integerlist.size()+"
integers.");
if (Integerlist.contains(new Integer(5)))
System.out.println("Integerlist contains 5");
else
System.out.println("Integerlist does not contain 5");
Integerlist.remove(new Integer(5));
if (Integerlist.contains(new Integer(5)))
System.out.println("Integerlist contains 5");
else
System.out.println("Integerlist does not contain 5");
System.out.println("Integerlist has "+Integerlist.size()+"
integers.");
System.out.println();
Integerlist.add(new Integer(5));
ListIterator
while (I.hasNext())
{
Integer n = I.next();
System.out.println(n.intValue());
}
I=Integerlist.listIterator();
while (I.hasNext())
{
Integer m = I.next();
Integer n = new Integer(2*m.intValue());
I.set(n); I.add(m);
}
System.out.println();
I=Integerlist.listIterator();
while (I.hasNext())
{
Integer n = I.next();
System.out.println(n.intValue());
}
I=Integerlist.listIterator();
while (I.hasNext())
{
Integer m = I.next();
if (m.intValue()>10)
I.remove();
}
System.out.println();
I=Integerlist.listIterator();
while (I.hasNext())
{
Integer n = I.next();
System.out.println(n.intValue());
}
Stringlist.add("Hello"); Stringlist.add("Goodby");
Stringlist.addFirst("ABC");
System.out.println();
ListIterator
while (J.hasNext())
{
String s = J.next();
System.out.println(s);
}
J=Stringlist.listIterator();
while (J.hasNext())
{
String s = J.next();
S.add(s);
}
System.out.println();
J=S.listIterator();
while (J.hasNext())
{
String s = J.next();
System.out.println(s);
}
System.out.println("DONE");
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
