Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA ASSIGNMENT ASSIGNMENT DESCRIPTION: Build three classes that corresponds to the following provided interfaces. Be sure to use arrays in creating the classes (NOTE: do

JAVA ASSIGNMENT

ASSIGNMENT DESCRIPTION:

Build three classes that corresponds to the following provided interfaces. Be sure to use arrays in creating the classes (NOTE: do not use the built-in ArrayList class when creating the ArrayList like interface). Extend the sample driver provided below to completely test the FIFO nature of a Queue, the LIFO nature of a stack, and the arbitrary inserts and removes in an ArrayList - like structure.

ArrayList-like Interface

  • void insert(Object, int index): Add the object at the specified index.
  • Object remove(int index): Remove and return the object at the specified index.
  • int size()
  • String toString()
  • boolean isEmpty()
  • int getIndexOf(Object): Returns -1 if not found
  • boolean equals(Object): Compare sizes and elements in the data structure.
  • Object get(int index): Returns the object at index specified.

Stack Interface (LIFO)

  • void push(Object)
  • Object pop()
  • int size()
  • String toString()
  • boolean isEmpty()
  • boolean equals(Object)

Queue Interface (FIFO)

  • void enqueue(Object)
  • Object dequeue()
  • int size()
  • String toString()
  • boolean isEmpty()
  • boolean equals(Object)

Hints and Tips

  • Deliverables: You should turn in four .java files, three are for your classes and the fourth is your test harness (driver). Put the java files inside of a single .zip file. The file names do not need to include your name, but be sure your name is in the comments inside each file.
  • You should practice building drivers and even more advanced testing harnesses yourself. The above driver is merely a starting point that you can use to initially exercise your code. In lecture, we will talk about what a testing harness should do. For this assignment, you can just display the results of your test to screen. Once we've gone through exception handling, you will have all the skills needed to write the harness the way I described in class.
  • A reminder that Stacks should be LIFO, queues should be FIFO, and ArrayLists can add and remove in arbitrary order.
  • The data structures should hold objects of class Object.
  • Consider completing your ArrayList class, then using it for the other two classes. You only have to solve the trickier issues once.
  • Q: The list of methods I'm supposed to write seems to be missing methods I need in order for me to actually create and use an instance of the class. For instance, my ArrayList-like class, if it does not have an add or append method, cannot be used for anything. Can I create additional methods? A: Yes, you should create any methods you believe necessary in order to make the class work. The list of methods given above are just the ones we're looking for to grade.
  • Q: Do these structures hold a fixed size set of items (i.e., static), or can they grow at runtime? A: Your software should be able to automatically resize your array once capacity is reached, and may be tested beyond 100 elements. Remember that stacks, queues, etc. are (in the abstract) infinite capacity data structures.
  • Q: What is FIFO and LIFO? A: Good question.
  • Q: How will you test this code? A: Tests may use the same strategies and techniques shown to you in the first few HWs, but more complete.
  • Q: Are comments (file headers, method headers, inline comments) important? A: Comments are now worth almost 2 letter grades, so I'd include them.
  • Q: I think there is a way to relate these classes via inheritance. Should I do this? A: We'll cover this later in the quarter; you should use no inheritance for this assignment.

DRIVER:

public class ArrayBasedDataStructuresDriver {

public static void main(String[] args) {

stackTests();

queueTests();

arrayListTests();

}

private static void arrayListTests() {

//todo: make more tests here

ArrayList a = new ArrayList();

a.insert('B', 0);

a.insert('a',0);

a.insert('t',1);

System.out.println(a.toString());

System.out.printl("Index of a: " + a.getIndexOf('a');

while(a.isEmpty() == false) {

System.out.println(a.remove(0));

}

}

private static void queueTests() {

//todo: make more tests here

Queue a = new Queue();

a.enqueue('B');

a.enqueue('a');

a.enqueue('t');

System.out.println(a.toString());

while(a.isEmpty() == false) {

System.out.println(a.dequeue());

}

}

private static void stackTests() {

//todo: make more tests here

Stack a = new Stack();

a.push('B');

a.push('a');

a.push('t');

System.out.println(a.toString());

while(a.isEmpty() == false) {

System.out.println(a.pop());

}

}

}

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

Explain all drawbacks of application procedure.

Answered: 1 week ago

Question

Explain the testing process of accounting 2?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago