Question: Can someone import all this code into a project and find out why the code doesn't work. All I need is someone to fix the

Can someone import all this code into a project and find out why the code doesn't work. All I need is someone to fix the code and get an output from the client class. (Should be a table) Please send back all the updated codes from the classes when done. (Sorry they are screenshots, Chegg won't let me paste all text) Thank you

Can someone import all this code into a project and find out

====

Client class:

public class Client {

public static void main(String[] args) { long[][] resultsArray = new long[8][3]; long[][] resultsLinked = new long[8][3];

int row = 0;

for (int n = 10; n arrayBag = new ArrayBag(n); LinkedBag linkedBag = new LinkedBag();

long start, stop, elapsed;

// Timing test for ArrayBag start = System.currentTimeMillis(); for (int i = 0; i

// Timing test for LinkedBag start = System.currentTimeMillis(); for (int i = 0; i

row++; }

// Print results for ArrayBag System.out.println("ArrayBag:"); print2dAsciiTable(resultsArray);

// Print results for LinkedBag System.out.println("LinkedBag:"); print2dAsciiTable(resultsLinked); }

/** * Prints a 2-dimensional array of long in a nicely formatted ASCII table. * @param data the data to print */ public static void print2dAsciiTable(long[][] data) { System.out.println("+----------------------+---------------+---------------+"); System.out.println("| N | Add Time (ms) | Remove Time (ms) |"); System.out.println("+----------------------+---------------+---------------+"); for (int row = 0; row

}

==========

ArrayBag.java

public class ArrayBag implements Bag { private E[] list; private int numberOfEntries; private static final int DEFAULT_CAPACITY = 25;

public ArrayBag() { this(DEFAULT_CAPACITY); }

@SuppressWarnings("unchecked") public ArrayBag(int initialCapacity) { numberOfEntries = 0; list = (E[]) new Object[initialCapacity]; }

public int getCurrentSize() { return numberOfEntries; }

@Override public boolean isEmpty() { return numberOfEntries == 0; }

@Override public void add(E newEntry) { if (numberOfEntries == list.length) { list = Arrays.copyOf(list, 2 * list.length); } list[numberOfEntries++] = newEntry; }

public void addTest(E newEntry) { if (numberOfEntries == list.length) { list = Arrays.copyOf(list, 2 * list.length); } list[numberOfEntries] = newEntry; numberOfEntries++; }

public E removeTest() { if (isEmpty()) { return null; } else { E removedEntry = list[numberOfEntries - 1]; list[numberOfEntries - 1] = null; numberOfEntries--; return removedEntry; } }

@Override public E remove() { return removeTest(); } }

=====

LinkedBag class

public class LinkedBag implements Bag { private Node firstNode; private int numberOfEntries;

public LinkedBag() { firstNode = null; numberOfEntries = 0; }

public int getCurrentSize() { return numberOfEntries; }

@Override public boolean isEmpty() { return numberOfEntries == 0; }

@Override public void add(E newEntry) { Node newNode = new Node(newEntry); newNode.next = firstNode; firstNode = newNode; numberOfEntries++; }

public void addTest(E newEntry) { Node newNode = new Node(newEntry); newNode.next = firstNode; firstNode = newNode; numberOfEntries++; }

public E removeTest() { if (isEmpty()) { return null; } else { E removedEntry = firstNode.data; firstNode = firstNode.next; numberOfEntries--; return removedEntry; } }

@Override public E remove() { return removeTest(); }

private class Node { private T data; private Node next;

private Node(T dataPortion) { this(dataPortion, null); }

private Node(T dataPortion, Node nextNode) { data = dataPortion; next = nextNode; } } }

========

Bag interface

why the code doesn't work. All I need is someone to fix

=======

SinglyLinkedList class

the code and get an output from the client class. (Should bea table) Please send back all the updated codes from the classeswhen done. (Sorry they are screenshots, Chegg won't let me paste all

ArrayBag.java Bag.java Client.java LinkedBag.java SinglyLinkedList.java blic interface Bag { int size (); boolean isEmpty (); void clear(); int getFrequencyof (E e); boolean contains (E e); void add (E e); E remove (E e); E remove (); E get (int i); String tostring (); boolean equals (Object o)

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!