Question: Can someone go through all these codes under a project and figure out why it won't work? In the end I need the client class

Can someone go through all these codes under a project and figure out why it won't work? In the end I need the client class to run and print out a table, but I cannot get it to work correctly. The classes ArrayBag, LinkedBag and Client are having problems. Please help and paste all updated codes into the answer. Im sure that those 3 classes will need to be fixed. In the end please get an output so I can finally be done with this. Thank you. (5 Classes total need to be worked through and also I couldn't paste all the codes so you will have to manually enter some, my apologies)

Can someone go through all these codes under a project and figure

======

Code for the Client.java 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

}

========

Code for the ArrayBag.java class:

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(); } }

=====

Code for the LinkedBag.java

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; } } } ==========

Code for Bag.java interface:

out why it won't work? In the end I need the client

======

Code for SinglyLinkedList.java class:

class to run and print out a table, but I cannot getit to work correctly. The classes ArrayBag, LinkedBag and Client are havingproblems. Please help and paste all updated codes into the answer. Im

Again please go through all this code and help me. Paste all the codes back into the answer when done, thank you.

Source Packages ArrayBag.java Bag.java Client.java LinkedBag.java SinglyLinkedList.java blic interface Bag E>{ 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!