|
The Sequential Numeric Linear List Implementation assignment requires you to enter a given implementation and refine a test program.
|
init:
deps-jar:
compile-single:
run-single:
>>> testAddB
>>> Add 1, 2, 3, 4, 5, 6 to a new empty list.
( 6.0 5.0 4.0 3.0 2.0 1.0 )
Exception in thread "main" java.lang.UnsupportedOperationException: Not yet implemented
at testers.SequentialNumericLinearListTest.testAddE(SequentialNumericLinearListTest.java:47)
at testers.SequentialNumericLinearListTest.main(SequentialNumericLinearListTest.java:18)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
|
/*
* NumericLinearList.java
*
* Created on June 15, 2006, 6:11 AM
*/
package datatypes.list.numeric.sequential;
import datatypes.list.numeric.*;
public class NumericLinearList implements NumericLinearListADT {
private static final int LIMIT = 200;
private Double numbers[];
private int size;
public NumericLinearList() {
numbers = new Double[LIMIT];
size = 0;
}
public String toString() {
String result = "";
result = result + "( ";
for ( int i = 0; i < size; i++ ) {
result = result + numbers[i].doubleValue() + " ";
}
result = result + ")";
return result;
}
public void addB(Double data) {
for ( int i = size-1; i >= 0; i-- ) {
numbers[i+1] = numbers[i];
}
numbers[0] = data;
size++;
}
public void addE(Double data) {
numbers[size] = data;
size++;
}
public void addN(Double data, int n) {
for ( int i = size-1; i >= n; i-- ) {
numbers[i+1] = numbers[i];
}
numbers[n] = data;
size++;
}
public int length() {
return size;
}
public boolean emptyp() {
return ( size == 0 );
}
public boolean memberp(Double data) {
for ( int i = 0; i < size; i++ ) {
if ( numbers[i].equals(data) ) {
return true;
}
}
return false;
}
private int indexOf(Double data) {
for ( int i = 0; i < size; i++ ) {
if ( numbers[i].equals(data) ) {
return i;
}
}
return -1;
}
public void delete(int n) {
for ( int i = n+1; i <= size; i++ ) {
numbers[i-2] = numbers[i-1];
}
size--;
}
public void delete(Double data) {
int n = indexOf(data);
deletex(n);
}
public void deletex(int x) {
for ( int i = x; i < size-1; i++ ) {
numbers[i] = numbers[i+1];
}
size--;
}
public Double nth(int n) {
return numbers[n-1];
}
}
/*
* SequentialNumericLinearListTest.java
*
*/
package testers;
import datatypes.list.numeric.sequential.*;
public class SequentialNumericLinearListTest {
public SequentialNumericLinearListTest() {
}
public static void main(String[] args) {
// note: toString() is tested throughout the program
testAddB();
testAddE();
testAddN();
testEmptyp();
testLength();
testMemberp();
testNth();
testDeleters();
}
private static void testAddB() {
System.out.println("\n>>> testAddB");
NumericLinearList b = createB();
display(b);
}
static private NumericLinearList createB() {
System.out.println(">>> Add 1, 2, 3, 4, 5, 6 to a new empty list.");
NumericLinearList nll = new NumericLinearList();
nll.addB(new Double(1));
nll.addB(new Double(2));
nll.addB(new Double(3));
nll.addB(new Double(4));
nll.addB(new Double(5));
nll.addB(new Double(6));
return nll;
}
private static void testAddE() {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void testAddN() {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void testEmptyp() {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void testLength() {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void testMemberp() {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void testNth() {
throw new UnsupportedOperationException("Not yet implemented");
}
private static void testDeleters() {
throw new UnsupportedOperationException("Not yet implemented");
}
static private void display(NumericLinearList nnl)
{
System.out.print(nnl.toString() + "\n");
}
}
|