Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need someone to write a client class for this code. The pictures with the square is what I need. I have attached the four

I need someone to write a client class for this code. The pictures with the square is what I need. I have attached the four codes below that you will need to use. If you need to change them for any reason you may but ArrayBag and LinkedBag should be done already. (Focus on writing a client that will produce a final output) For the answer please put paste all codes and the client class along with proof of the output you received. (I could not paste every code so you will have to manually type out the screenshots from some, my apologies.)

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

========

For the ArrayBag.java class: (Again these code are complete and do not need working, but if they do then you may alter them. I need a client class and an output.)

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

}

}

======

For the LinkedBag.java 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;

}

}

}

======

For the Bag.java interface: (Sorry for screenshots) image text in transcribed

==========

For the SinglyLinkedList.java class:

image text in transcribedimage text in transcribedimage text in transcribed Sorry about the screenshots again, but I have requested this question many times and only the ArrayBag and LinkedBag are being changed. I need a client class and an output to complete the question. Please put all the codes into the answer with updates, thank you for writing the client class.

Restrictions: You cannot use any predefined Java classes in writing this lab. You CAN import the java.util.Random class. All output in this assignment must use the printf method. System.out.print and System.out.println cannot be used. You must use the System.out.printf method for all output. Create a NetBeans project using the standard naming convention, i.e. Lab04- LastFM and save it to a location like the desktop or your flash drive. In the project you will do the following: Copy the following classes from your Lab103 assignment into the source code directory for this assignment: - Bag - ArrayBag - LinkedBag - SinglyLinkedList If your Lab103 assignment is incomplete and/or incorrect you need to, at a minimum, correctly complete the methods needed for this this assignment. In this assignment you are going to try and measure the speed differences between an array-based structure and a linked-based structure. You will use your ArrayBag and LinkedBag for these measurements. You want to be careful that features like the ArrayBag automatically expanding when it needs more space or the ArrayBag shifting items to the left to fill in empty gaps do not impact the measurements. You also do not want to traverse the LinkedBag looking for an item to remove. To avoid these problems, add the following methods to your ArrayBag and/or LinkedBag classes: To the ArrayBag class add: public void addTest( E e ) this method adds to the end of the array. public E removeTest( ) this method removes the last item at the end of the array. Note that by adding and removing from the end of the array no left-shifting of values will be needed. To the LinkedBag class add: public void addTest( E e ) this method adds to the head of the linkedList public E removeTest( ) this method removes from the head of the linkedList Note by adding and removing from the head of the linkedList it will not be necessary to traverse the list. If you implement the above methods correctly they should all have O(1) performance. Note that these are methods for your ArrayBag and LinkedBag classes. You should not make any changes to the SinglyLinkedList class. Of course, the methods for the LinkedBag class will still need to call the corresponding methods in the SinglyLinkedList class. Write a Client program that does that tests the ArrayBag and LinkedBag as following: - 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 ASCIl 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 'l' - 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 ASCII table for this assignment is given at the end of this assignment. public 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); \} public void clear() \{ head = null; tail = null; size =0; \} public boolean contains (E e) \{ Node E current = head; while (current != null) f if (current.getElement() . equals (obj:e)) return true; current = current.getNext (); \} return false; \} public E get(int i) f if (i = size) throw new IndexOutOfBoundsException("Index: " +i Node E> current = head; for (int index =0; index

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Structure Of The Relational Database Model

Authors: Jan Paredaens ,Paul De Bra ,Marc Gyssens ,Dirk Van Gucht

1st Edition

3642699588, 978-3642699580

More Books

Students also viewed these Databases questions

Question

=+No job too large! No schedule too tight! Give us a call today!

Answered: 1 week ago

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago