Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROJECT REQUIREMENTS This project involves two parts: 1. Implement the ListADT , OrderedListADT , and UnorderedListADT a. using a linked structure; b. using a fixed-end

PROJECT REQUIREMENTS

This project involves two parts:

1. Implement the ListADT , OrderedListADT, and UnorderedListADT

a. using a linked structure;

b. using a fixed-end array structure;

The UML description of the three interfaces is given in Figure 1.

2. Using a List to organize and manage a StudentList.

You should NOT use the List and Arrays classes from Java library. To be specific, DO NOT import java.util.* ;

Figure 1: UML diagram of the ListADTs.

Implementation:

Your implementation must conform to the ListADT, OrderedListADT, and UnorderedListADT interface as showed above and include at least all of the public and private members that are discussed in class. To be specific,

1) Write a Student Class that implements Comparable interface. You will need to implement the constructor, the compareTo() method, the toString() method, and the getters and setters methods.

public class Student implements Comparable {

// Code implementation here }

2) Write a class ArrayList to implement the ListADT interface.

public class ArrayList implements ListADT {

// ArrayList implementation here

}

3) Write a class OrderedArrayList which extends the ArrayList class and implements the OrderedListADT.

public class OrderedArrayList extends ArrayList implements OrderedListADT {

// OrderedArrayList implementation here

}

4) Write a class ArrayList to implement the ListADT interface.

public class ArrayList implements ListADT {

// ArrayList implementation here

}

5) Write a class UnorderedArrayList which extends the ArrayList class and implements the UnorderedListADT interface.

public class UnorderedArrayList extends ArrayList implements UnorderedListADT {

// UnorderedArrayList implementation here

}

UnOrderedLIST ADT

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

ch06list;

public interface

ListADT/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package ch06list;

public interface ListADT {

//remove methods

public T removeFirst();

public T removeLast();

public T remove(T target);

// peak

public T first();

public T last();

public boolean contains(T target);

// general

public int size();

public boolean isEmpty();

}

UnorderedListADT extends ListADT {

public void addToFront(T elem);

public void addToRear(T elem);

public void addAfter(T elem, T target);

}

OrderedListADT

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

public interface OrderedListADT extends ListADT {

public void add(T elem);

}

Stack Interface

/**

* Defines the interface to a stack collection.

* @author Lewis and Chase

* @version 4.0

*/

public interface StackADT

{

/**

* Adds the specified element to the top of this stack.

* @param element element to be pushed onto the stack

*/

public void push(T element);

/**

* Removes and returns the top element from this stack.

* @return the element removed from the stack

*/

public T pop();

/**

* Returns (without removing) the top element of this stack.

* @return the element on top of the stack

*/

public T peek();

/**

* Returns true if this stack contains no

elements.

* @return true if the stack is empty

*/

public boolean isEmpty();

/**

* Returns the number of elements in this stack.

* @return the number of elements in the stack

*/

public int size();

/**

* Returns a string representation of this stack.

* @return a string representation of the stack

*/

public String toString();

}

import java.util.Arrays;

import java.util.NoSuchElementException;

/**

* An array implementation of a stack in which the

* bottom of the stack is fixed at index 0.

*

* @author Lewis and Chase

* @version 4.0

*/

public class ArrayStack implements StackADT

{

private final static int DEFAULT_CAPACITY = 100;

private int top;

private T[] stack;

/**

* Creates an empty stack using the default capacity.

*/

public ArrayStack()

{

this(DEFAULT_CAPACITY);

}

ArrayStack

/**

* Creates an empty stack using the specified capacity.

* @param initialCapacity the initial size of the array

*/

public ArrayStack(int initialCapacity)

{

top = 0;

stack = (T[])(new Object[initialCapacity]);

}

/**

* Adds the specified element to the top of this stack, expanding

* the capacity of the array if necessary.

* @param element generic element to be pushed onto stack

*/

public void push(T element)

{

if (size() == stack.length) expandCapacity();

stack[top] = element;

top++;

}

EXAMPLE OUTPUT

run:

Part I ----- Test Student Class -------

Step # 1 test Student constructor and toString method

Evidence: Student name is Test and has a GPA of 0.0

Step # 2 test Student Setter and Setter methods

Evidence: My name is: Yun

Evidence: My GPA is: 4.0

----------------------------------------------------------------------------------------

Part II ----- Test OrderedArrayList Class -------

Step # 3 test the constructor of OrderedArrayList for Student type data.

Evidence: studentOrderedList is created

Step # 4 test the add() method of OrderedArrayList for Student type data.

Evidence: The Current Student List includes:

Student name is E and has a GPA of 2.7

Student name is F and has a GPA of 2.8

Student name is C and has a GPA of 2.9

Student name is A and has a GPA of 3.0

Student name is D and has a GPA of 3.2

Student name is B and has a GPA of 3.9

Step # 5 test the removeFirst() method of OrderedArrayList for Student type data.

Evidence: The Current Student List includes after removing the first element:

Student name is F and has a GPA of 2.8

Student name is C and has a GPA of 2.9

Student name is A and has a GPA of 3.0

Student name is D and has a GPA of 3.2

Student name is B and has a GPA of 3.9

Step # 6 test the removeLast() method of OrderedArrayList for Student type data.

Evidence: The Current Student List includes after removing the last element:

Student name is F and has a GPA of 2.8

Student name is C and has a GPA of 2.9

Student name is A and has a GPA of 3.0

Student name is D and has a GPA of 3.2

Step # 7 test the remove() method of OrderedArrayList for Student type data.

Evidence: The Current Student List includes:

Student name is F and has a GPA of 2.8

Student name is C and has a GPA of 2.9

Student name is D and has a GPA of 3.2

Step # 8 test the first() method of OrderedArrayList for Student type data.

Evidence: First Element: Student name is F and has a GPA of 2.8

Step # 9 test the last() method of OrderedArrayList for Student type data.

Evidence: Last Element: Student name is D and has a GPA of 3.2

Step # 10 test the contains() method of OrderedArrayList for Student type data.

Evidence: Does it contain a Student named A with a GPA of 3.0? false

Evidence: Does it contain a Student named D with a GPA of 3.2? true

Step # 11 test the isEmpty() method of OrderedArrayList for Student type data.

Evidence: Is it Empty? false

Step # 12 test the size() method of OrderedArrayList for Student type data.

Evidence: Size of List: 3

----------------------------------------------------------------------------------------

Part III ----- Test UnOrderedArrayList Class -------

Step # 13 test the constructor of UnorderedArrayList for Student type data.

Evidence:studentUnorderedList is created

Evidence: The Current Student List includes:

Student name is B and has a GPA of 3.9

Step # 14 test the addToFront() method of UnorderedArrayList for Student type

data.

Evidence: The Current Student List after adding to the front:

Student name is A and has a GPA of 3.0

Student name is B and has a GPA of 3.9

Step # 15 test the addToRear() method of UnorderedArrayList for Student type

data.

Evidence: The Current Student List after adding to the rear:

Student name is A and has a GPA of 3.0

Student name is B and has a GPA of 3.9

Student name is F and has a GPA of 2.8

Step # 16 test the addAfter() method of UnorderedArrayList for Student type data.

Evidence: The Current Student List after adding 3 elements using addAfter():

Student name is A and has a GPA of 3.0

Student name is B and has a GPA of 3.9

Student name is C and has a GPA of 2.9

Student name is D and has a GPA of 3.2

Student name is E and has a GPA of 2.7

Student name is F and has a GPA of 2.8

Step # 17 test the removeFirst() method of UnorderedArrayList for Student type

data.

Evidence: The Current Student List after removing the first element:

Student name is B and has a GPA of 3.9

Student name is C and has a GPA of 2.9

Student name is D and has a GPA of 3.2

Student name is E and has a GPA of 2.7

Student name is F and has a GPA of 2.8

Step # 18 test the removeLast() method of UnorderedArrayList for Student type

data.

Evidence: The Current Student List after removing the last element:

Student name is B and has a GPA of 3.9

Student name is C and has a GPA of 2.9

Student name is D and has a GPA of 3.2

Student name is E and has a GPA of 2.7

Step # 19 test the remove() method of UnorderedArrayList for Student type data.

Evidence: The Current Student List after removing a Student with name E

and GPA 2.7:

Student name is B and has a GPA of 3.9

Student name is C and has a GPA of 2.9

Student name is D and has a GPA of 3.2

Step # 20 test the first() method of UnorderedArrayList for Student type data.

Evidence: First Element: Student name is B and has a GPA of 3.9

Step # 21 test the last() method of UnorderedArrayList for Student type data.

Evidence: Last Element: Student name is D and has a GPA of 3.2

Step # 22 test the contains() method of UnorderedArrayList for Student type data.

Evidence: Does it contain a student with name A and a GPA of 3.0? false

Evidence: Does it contain a student with name B and GPA of 3.9? true

Step # 23 test the isEmpty() method of UnorderedArrayList for Student type data.

Evidence: Is it empty? false

Step # 24 test the size() method of UnorderedArrayList for Student type data.

Evidence: Size of List: 3

BUILD SUCCESSFUL (total time: 0 seconds)

Repeat the above 24 steps for LinkedList

implementation.

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

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

More Books

Students also viewed these Databases questions