CS 227 Project 6A: Implementing PriorityList with Array and LinkedList - Prof. R. Mercer, Study Guides, Projects, Research of Computer Science

A university project for computer science students where they are required to implement the prioritylist abstract data type (adt) using two different data structures: arrayprioritylist and linkedprioritylist. The project goals include understanding how generic classes store collections, using exceptions to handle invalid arguments, and implementing interfaces. The prioritylist interface, instructions for writing the arrayprioritylist class, and testing guidelines.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/31/2009

koofers-user-35k-2
koofers-user-35k-2 šŸ‡ŗšŸ‡ø

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C Sc 227 Project 6A ArrayPriorityList<E> implements PriorityList<E>
Due Date for 6A and 6B: LinkedPriorityList: Both classes and unit tests are due Friday, 13-March @
11:00 am with the day before Spring Break lecture held in 906 Gould Simpson for those who have not
completed 6A and 6B.
Collaboration: Complete by yourself
Preview: This project asks you to implement the PriorityList ADT with ArrayPriorityList<E>
first and then with LinkedPriortyList<E>. This project has the following goals:
Implement an ADT using two different data structures (array now, linked later)
Understand how generic classes safely store collections of the same type element
Use exceptions to handle invalid arguments
Implement interfaces
A PriorityList stores a collection of elements as a zero-based indexed list where the element at index 0 is
considered to have higher priority than the element at index 1. The element at index size()-1 has the
lowest priority. A PriorityList stores a collection of just one type of element that can be any type. The
PriorityList ADT is given as a Java interface with comments. Each method must behave as specified in
the comments.
1. PriorityList
Either retype the interface below or get the following file into your project.
http://www.cs.arizona.edu/classes/cs227/spring09/projects/PriorityList.java
/**
* This interface describes an abstract data type to store elements where
* indexes represent priorities and the priorities can change in several ways.
*
* @author Rick Mercer
* @param <E>
* The type of all elements stored in this collection
*/
public interface PriorityList<E> {
/**
* Return the number of elements currently in this PriorityList
*
* @return The number of elements in this PriorityList
*/
public int size();
/**
* Return true if there are zero elements in this PriorityList *
*
* @return true if size() == 0 or false if size() > 0
*/
public boolean isEmpty();
/**
* If possible, insert the element at the given index. If index is out of
* range, throw new IllegalArgumentException();. For example, when size is
* 3, the only possible values for index are 0, 1, 2, and 3.
*
* @param index
* The index of the element to move.
* @param el
* The element to insert
* @throws IllegalArgumentException
*/
public void insertElementAt(int index, E el) throws IllegalArgumentException;
pf3
pf4

Partial preview of the text

Download CS 227 Project 6A: Implementing PriorityList with Array and LinkedList - Prof. R. Mercer and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

C Sc 227 Project 6A ArrayPriorityList implements PriorityList

Due Date for 6A and 6B: LinkedPriorityList: Both classes and unit tests are due Friday, 13-March @

11:00 am with the day before Spring Break lecture held in 906 Gould Simpson for those who have not

completed 6A and 6B.

Collaboration: Complete by yourself

Preview: This project asks you to implement the PriorityList ADT with ArrayPriorityList

first and then with LinkedPriortyList. This project has the following goals:

Implement an ADT using two different data structures (array now, linked later)

Understand how generic classes safely store collections of the same type element

Use exceptions to handle invalid arguments

Implement interfaces

A PriorityList stores a collection of elements as a zero-based indexed list where the element at index 0 is

considered to have higher priority than the element at index 1. The element at index size()-1 has the

lowest priority. A PriorityList stores a collection of just one type of element that can be any type. The

PriorityList ADT is given as a Java interface with comments. Each method must behave as specified in

the comments.

1. PriorityList

Either retype the interface below or get the following file into your project.

http://www.cs.arizona.edu/classes/cs227/spring09/projects/PriorityList.java

  • This interface describes an abstract data type to store elements where
  • indexes represent priorities and the priorities can change in several ways.
  • @author Rick Mercer
  • @param
  • The type of all elements stored in this collection */ public interface PriorityList {
  • Return the number of elements currently in this PriorityList
  • @return The number of elements in this PriorityList */ public int size();
  • Return true if there are zero elements in this PriorityList *
  • @return true if size() == 0 or false if size() > 0 */ public boolean isEmpty();

/**

  • If possible, insert the element at the given index. If index is out of
  • range, throw new IllegalArgumentException();. For example, when size is
  • 3, the only possible values for index are 0, 1, 2, and 3.
  • @param index
  • The index of the element to move.
  • @param el
  • The element to insert
  • @throws IllegalArgumentException */ public void insertElementAt( int index, E el) throws IllegalArgumentException;
  • If possible, return a reference to the element at the given index. If
  • index is out of range, throw new IllegalArgumentException(); When size
  • is 3, the only possible values for index are 0, 1, and 2.
  • @param index
  • The index of the element to move.
  • @return A reference to to element at index index.
  • @throws IllegalArgumentException */ public E getElementAt( int index) throws IllegalArgumentException;

/**

  • If possible, remove the element at the given index. If index is out of
  • range, throw new IllegalArgumentException();
  • @param index
  • The index of the element to move.
  • @throws IllegalArgumentException */ public void removeElementAt( int index) throws IllegalArgumentException;

/**

  • If possible, swap the element located at index with the element at
  • index+1. An attempt to lower the priority of the element at index
  • size()-1 has no effect. If index is out of range, throw new
  • IllegalArgumentException();
  • @param index
  • The index of the element to move
  • @throws IllegalArgumentException */ public void lowerPriorityOf( int index) throws IllegalArgumentException;
  • If possible, swap the element located at index with the element at
  • index-1. An attempt to raise the priority at index 0 has no effect. If
  • index is out of range, throw new IllegalArgumentException();
  • @param index
  • The index of the element to move
  • @throws IllegalArgumentException */ public void raisePriorityOf( int index) throws IllegalArgumentException;
  • Return a copy of all elements as an array of Objects that is the size of
  • this PriorityList and in the same order. If there are no elements in this
  • list, return new Object[0];. A change to the return value must not affect
  • this ArrayPriorityList object.
  • @return An array of Objects where capacity == size() */ public Object[] toArray();
  • If possible, move the element at the given index to the end of this list.
  • An attempt to move the last element to the last has no effect. If the
  • index is out of range, throw new IllegalArgumentException();
  • @param index
  • The index of the element to move.
  • @throws IllegalArgumentException */ public void moveToLast( int index) throws IllegalArgumentException;

@Test public void testGetters() { // Arguments: 1. Movie Title 2. Star Rating from 1.. Movie m1 = new Movie("The Matrix Revolutions", 4); Movie m2 = new Movie("The Lord of the Rings, Return of the King", 5); Movie m3 = new Movie("Click", 2);

assertEquals ("The Matrix Revolutions", m1.getTitle()); assertEquals ("The Lord of the Rings, Return of the King", m2.getTitle()); assertEquals ("Click", m3.getTitle());

assertEquals ("The Matrix Revolutions ****", m1.toString()); assertEquals ("The Lord of the Rings, Return of the King *****", m2.toString()); assertEquals ("Click **", m3.toString()); }

5. Submit to Web-Cat

Submit this to Project ArrayPriorityList and work with it until you have 100% code coverage and

100% problem coverage (no style points count).

6. Optional: Run a GUI that uses your ArrayPriorityList class

Once you have finished a class that implements PriorityList class, see it used in an event driven

program that has a graphical user interface. Get this file into your project http://www.cs.arizona.edu/classes/cs227/spring09/projects/PriorityListGUI.java

Grading Criteria (50 points, subject to change)

____+35 Web-Cat correctness and code coverage: To get 100 points, you will need 100% code coverage

and 100% problem coverage (Rick's tests pass and you exercised all methods). These 100 points are

derived from Web-Cat. You may submit as many times as you wish until you have 100% on both. Notice

that a multiplication feature is employed that means 90% code coverage and 90% problem coverage

results in 0.9 * 0.9 * 100 81/100 points. This is only 81% rather than 90%.

____+15 You used an array data structure for ArrayPriorityList -15 for any other scenario such as

using an existing Java class.