Question: Please update this general outline for a client class. You will to use the four classes I will provide to produce the ASCII table and

Please update this general outline for a client class. You will to use the four classes I will provide to produce the ASCII table and the output. This is just the outline and make sure to use the ArrayBag and LinkedBag classes provided below. I will paste as much as I can but the rest of the code with have to be a screenshot for you to copy. In the end you should have a total of 5 classes than can run and produce an output. Thank you

public class Client {

public static void main(String[] args) { long answer, start, stop, elapse;

long limit = 8192 + 1;

long results[][] = new long[15][3]; int row = 0;

for (long n = 2; n

start = System.nanoTime(); answer = facRecursive(n); stop = System.nanoTime(); elapse = stop - start; System.out.printf("facRecursive(%d) = %d took %d (nsec) ", n, answer, elapse); results[row][2] = elapse; row++; } System.out.printf(" ============================================== "); print2dArray( results ); System.out.printf(" ============================================== "); print2dAsciiTable( results ); }

/** * an iterative algorithm for factorial * * @param n * @return */ public static long facIterative(long n) { long ans = 1; for (long i = n; i > 0; i--) { ans = i * ans; } return ans; }

/** * a recursive algorithm for factorial * * @param n * @return */ public static long facRecursive(long n) { if (n

/** * prints a 2-dimensional array of long * @param data */ public static void print2dArray( long[][] data ) { for (int row = 0; row

Please update this general outline for a client class. You will touse the four classes I will provide to produce the ASCII tableand the output. This is just the outline and make sure to

=========

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.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;

}

}

}

==============

Bag.java interface

use the ArrayBag and LinkedBag classes provided below. I will paste as

========

SinglyLinkedList.java

much as I can but the rest of the code with haveto be a screenshot for you to copy. In the end youshould have a total of 5 classes than can run and produce

Again all you need to do is change the client outline to use ArrayBag and LinkedBag to produce an output.

Example of the ASCII table. - Note that the values line up in a tabular format. - You will need to change your font in your windows document to a non-proportional font, e.g. Courier New. Client program that does that tests the ArrayBag and LinkedBag as ing: For each structure: - Perform a timing test for each of these data structures. - Each timing test should measure how long it takes to add N Integers to the structure and then remove N integers from the structure. - Time measurements should be made in milliseconds. - A time measurement should include how long it takes to both add all N values to the structure and then remove all N values from the structure. - N should vary from 10 to 100,000,000 increasing N by a factor of 10 for each test. - Depending on your system you may run out of memory before you reach the maximum value of N. - If you run out of memory, just drop the maximum value of N by a factor of 10 until your program runs successfully. - For each timing test start with a new, empty data structure. - The overload constructor should be called when creating the ArrayBag instance and passed a value of N for that test. This will keep the ArrayBag from having to expand the size of its array during the test. - You must store your test results in a two-dimensional array. - Test results must be displayed in a nicely formatted ASCII table similar to the examples provided at the end of the assignment. For the ASCII table: - You must create a method that prints the ASCII table. - This method should be passed a two-dimensional array that holds the values to be printed. - Each cell is delimited by the vertical pipe symbol ' ' - Values in each cell are padded by 2 blank spaces - Numerical values use the comma thousand separator, e.g. 1,234,567 - Each column is just wide enough to display the widest entry in that column including the cell padding. - There is a separator line between each row of values. - This separator line is also printed at the top and the bottom of the table. - Note that the ' + ' plus symbols in the separator line, align with the vertical pipe symbols in the value rows. - This table can be a static table, i.e. the column widths do not have to automatically adjust to the values being printed. - Future assignments may require that you make the ASCII table dynamic. - An example of the ASCIl table for this assignment is given at the end of this assignment. bublic 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!