Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How do I get this code to work without using the java.util Using java in netbeans please post full answer with what the ending output
How do I get this code to work without using the java.util Using java in netbeans please post full answer with what the ending output
Create a class called ManyStructures. It encapsulates an instance variable that is a long array. The length of the array should be dependent on an argument passed into a constructor. Include get and set methods so you can assign values to the elements of the array.
The ManyStructures class should also have the following methods.
getArray which returns a copy of the instance variable array. Note that I said "copy"!
getQueue which returns the data in the instance variable as a queue. The queue should have the functionality of the basic queue from your textbook.
getStack which returns the data in the instance variable array as a stack. The stack should have the functionality of the basic stack from your textbook.
getLinkedList which returns the data in the instance variable array as a linked list. The linked list should have the functionality of the basic linked list from your textbook. Note that in order to do this you will have to create something equivalent to the Link class from exercise A and embed the aray's long data within objects of that class.
Your project should contain any other classes you need to complete the test. Include a ManyStructuresDriver class that tests the ManyStructures class, its methods, and the data structures returned by the methods listed above..
NOTE: Just because it says "like the book" don't copy from the book, also don't use any java.util. packages
import java.util.Arrays;
class ManyStructures
private long dataArray;
public ManyStructuresint length
dataArray new longlength;
public long getArray
return dataArray.clone;
public void setElementint index, long value
if index && index dataArray.length
dataArrayindex value;
else
System.out.printlnIndex out of bounds.";
public long getElementint index
if index && index dataArray.length
return dataArrayindex;
else
System.out.printlnIndex out of bounds.";
return ; You can choose a suitable default value.
public Queue getQueue
return new QueuedataArrayclone;
public Stack getStack
return new StackdataArrayclone;
public LinkedList getLinkedList
LinkedList linkedList new LinkedList;
for long value : dataArray
linkedList.addvalue;
return linkedList;
class Queue
private long data;
private int front;
private int rear;
private int size;
public Queuelong dataArray
this.data dataArray.clone;
this.size dataArray.length;
this.front ;
this.rear size ;
Implement the basic queue methods enqueue dequeue, isEmpty, isFull, etc. here.
class Stack
private long data;
private int top;
private int size;
public Stacklong dataArray
this.data dataArray.clone;
this.size dataArray.length;
this.top size ;
Implement the basic stack methods push pop, isEmpty, isFull, etc. here.
class LinkedList
private Node head;
public void addlong value
Node newNode new Nodevalue;
if head null
head newNode;
else
Node current head;
while currentgetNext null
current current.getNext;
current.setNextnewNode;
Implement other linked list methods as needed.
class Node
private long data;
private Node next;
public Nodelong data
this.data data;
this.next null;
public long getData
return data;
public Node getNext
return next;
public void setNextNode next
this.next next;
class ManyStructuresDriver
public static void mainString args
Test ManyStructures class and its methods here
int arrayLength ;
ManyStructures manyStructures new ManyStructuresarrayLength;
Test getArray setElement and getElement methods
System.out.printlnOriginal Array: Arrays.toStringmanyStructuresgetArray;
manyStructures.setElement;
System.out.printlnModified Array: Arrays.toStringmanyStructuresgetArray;
System.out.printlnElement at index : manyStructures.getElement;
Test getQueue getStack and getLinkedList me
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started