Question

In: Computer Science

Using Java, Complete LinkedListSet: package Homework3; public class LinkedListSet <T> extends LinkedListCollection <T> { LinkedListSet() {...

Using Java, Complete LinkedListSet:

package Homework3;
public class LinkedListSet <T> extends LinkedListCollection <T> {
LinkedListSet() {
}
public boolean add(T element) {
// Code here
return true;
}
}

Homework3 class:

public class Homework3 {
public static void main(String[] args) {
ArrayCollection ac1 = new ArrayCollection(); // Calling Default
Constructor
ArrayCollection ac2 = new ArrayCollection(2); // Calling overloaded
constructor
ArraySet as1 = new ArraySet();
ac2.add("Apple");
ac2.add("Orange");
ac2.add("Lemon"); // This can't be added into ac2 as collection is full
System.out.println(ac2.remove("Apple")); // This should return true
System.out.println(ac2);
ac2.enlarge(10);
ac2.add("Watermelon");
System.out.println("Equals: " + ac1.equals(ac2));
as1.add("Avocado");
as1.add("Avocado"); // This will not be added, since the
collection is "set"
}
}

Solutions

Expert Solution

import java.util.LinkedHashSet;
public class Demo
{
   public static void main(String[] args)
   {
       LinkedHashSet<String> linkedset =
                       new LinkedHashSet<String>();

       // Adding element to LinkedHashSet
       linkedset.add("A");
       linkedset.add("B");
       linkedset.add("C");
       linkedset.add("D");

       // This will not add new element as A already exists
       linkedset.add("A");
       linkedset.add("E");

       System.out.println("Size of LinkedHashSet = " +
                                   linkedset.size());
       System.out.println("Original LinkedHashSet:" + linkedset);
       System.out.println("Removing D from LinkedHashSet: " +
                           linkedset.remove("D"));
       System.out.println("Trying to Remove Z which is not "+
                           "present: " + linkedset.remove("Z"));
       System.out.println("Checking if A is present=" +
                           linkedset.contains("A"));
       System.out.println("Updated LinkedHashSet: " + linkedset);
   }
}


Related Solutions

Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T...
Using this BubbleSort implementation in Java: public class BubbleSort<T extends Comparable<T>> {    private static <T extends Comparable<T>>    void swap(T[] data, int index1, int index2)    {       T temp = data[index1];       data[index1] = data[index2];       data[index2] = temp;    }    public void sort(T[] data)    {       int position, scan;       for (position = data.length - 1; position >= 0; position--)       {          for (scan = 0; scan <= position - 1; scan++)          {...
Using Java, Complete the LinkedListBag down below by using the (LinkedListCollection.java:) package Homework3; public class LinkedListBag...
Using Java, Complete the LinkedListBag down below by using the (LinkedListCollection.java:) package Homework3; public class LinkedListBag extends LinkedListCollection { LinkedListBag() { } public T grab() { T result; Node cursor = head; int rand = (int) (Math.random() * size()); // Some code in here.. result = cursor.getInfo(); remove(result); return result; } } LinkedListCollection.java: package Homework3; public class LinkedListCollection <T> { protected Node<T> head = null; public LinkedListCollection() { } public boolean isEmpty() { return head == null; } public int...
Using Java Languse, Complete ArraySet.java down below by using (Array collection) : package Homework3; public class...
Using Java Languse, Complete ArraySet.java down below by using (Array collection) : package Homework3; public class ArraySet extends ArrayCollection { public ArraySet() { } public ArraySet(int size) { super(size); } public boolean add(T element) { // Complete your code here return true; } } ArrayCollection.java: package Homework3; public class ArrayCollection { protected static final int DEFAULT_CAPACITY = 100; protected T[] elements; protected int numberOfElements; public ArrayCollection() { this(DEFAULT_CAPACITY); } public ArrayCollection(int size) { elements = (T[]) new Object[size]; numberOfElements =...
Using the following in Java- package intersectionprinter; import java.awt.Rectangle; public class IntersectionPrinter { public static void...
Using the following in Java- package intersectionprinter; import java.awt.Rectangle; public class IntersectionPrinter { public static void main(String[] args) { Rectangle r1 = new Rectangle(0,0,100,150); System.out.println(r1);    Rectangle r2 = new Rectangle(50,75,100,150); System.out.println(r2);    Rectangle r3 = r1.intersection(r2);    } } Write a program that takes both Rectangle objects, and uses the intersection method to determine if they overlap. If they do overlap, then print it's coordinates along with its width and height. If there is no intersection, then have the...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    *...
Using Java The given class SetInterface.java is : public interface SetInterface<T> {    /**    * Gets the current number of entries in this set.    *    * @return The integer number of entries currently in the set.    */    public int getSize();    /**    * Sees whether this set is empty.    *    * @return True if the set is empty, or false if not.    */    public boolean isEmpty();    /**    *...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and the current score of the PacmanGame. A score is a name and value that a valid name only contains the following characters: A to Z a to z 0 to 9 and must have a length greater than 0. The value is a integer that is equal to or greater than 0. Implement this for Assignment 1 Constructor Summary Constructors Constructor Description ScoreBoard() Creates...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and...
Package pacman.score Class ScoreBoard Object ScoreBoard public class ScoreBoard extends Object ScoreBoard contains previous scores and the current score of the PacmanGame. A score is a name and value that a valid name only contains the following characters: A to Z a to z 0 to 9 and must have a length greater than 0. The value is a integer that is equal to or greater than 0. Implement this for Assignment 1 Constructor Summary Constructors Constructor Description ScoreBoard() Creates...
USING JAVA: Complete the following class. input code where it says //TODO. public class BasicBioinformatics {...
USING JAVA: Complete the following class. input code where it says //TODO. public class BasicBioinformatics { /** * Calculates and returns the complement of a DNA sequence. In DNA sequences, 'A' and 'T' are * complements of each other, as are 'C' and 'G'. The complement is formed by taking the * complement of each symbol (e.g., the complement of "GTCA" is "CAGT"). * * @param dna a char array representing a DNA sequence of arbitrary length, * containing only...
Language: Java Topic: Deques Using the following variables/class: public class ArrayDeque<T> { /** * The initial...
Language: Java Topic: Deques Using the following variables/class: public class ArrayDeque<T> { /** * The initial capacity of the ArrayDeque. * * DO NOT MODIFY THIS VARIABLE. */ public static final int INITIAL_CAPACITY = 11; // Do not add new instance variables or modify existing ones. private T[] backingArray; private int front; private int size; Q1: write a method called "public void addLast(T data)" which adds an element to the back of a Deque. If sufficient space is not available...
Fix the following java code package running; public class Run {    public double distance; //in...
Fix the following java code package running; public class Run {    public double distance; //in kms    public int time; //in seconds    public Run prev;    public Run next;    //DO NOT MODIFY - Parameterized constructor    public Run(double d, int t) {        distance = Math.max(0, d);        time = Math.max(1, t);    }       //DO NOT MODIFY - Copy Constructor to create an instance copy    //NOTE: Only the data section should be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT