79 lines
2.6 KiB
Java
79 lines
2.6 KiB
Java
/**
|
|
* Tests the tasks.
|
|
*
|
|
* @author Marcus
|
|
*/
|
|
public class Main {
|
|
|
|
|
|
public static void main(String[] args) {
|
|
// test the student class
|
|
Person student1 = new Student("Schweinsteiger", 33);
|
|
Person student2 = new Student("Mueller", 7);
|
|
Person student3 = new Student("Ronaldo", 7);
|
|
System.out.println("getName(): Schweinsteiger");
|
|
System.out.println("Your code: " + student1.getName());
|
|
System.out.println();
|
|
System.out.println(" getId(): 33");
|
|
System.out.println("Your code: " + student1.getId());
|
|
System.out.println();
|
|
System.out.println(" equals(): true");
|
|
System.out.println("Your code: " + student1.equals(student1));
|
|
System.out.println(" equals(): true");
|
|
System.out.println("Your code: " + student2.equals(student3));
|
|
System.out.println(" equals(): false");
|
|
System.out.println("Your code: " + student1.equals(student3));
|
|
|
|
// test the average operation
|
|
double[] values = new double[] { 1, 2, 3 };
|
|
System.out.println();
|
|
System.out.println("average(): 2.0");
|
|
System.out.println("Your code: " + Operation.average(values));
|
|
System.out.println("average(): IllegalArgumentException");
|
|
try {
|
|
Operation.average(null);
|
|
System.out.println("Your code: no exception" );
|
|
} catch (Exception e) {
|
|
System.out.println("Your code: " + e.getClass().getSimpleName());
|
|
}
|
|
System.out.println("average(): IllegalArgumentException");
|
|
try {
|
|
Operation.average(new double[0]);
|
|
System.out.println("Your code: no exception" );
|
|
} catch (Exception e) {
|
|
System.out.println("Your code: " + e.getClass().getSimpleName());
|
|
}
|
|
|
|
// test the list implementation
|
|
System.out.println();
|
|
LinkedList list = new LinkedList();
|
|
String[] entries = new String[] { "a", "b", "c" };
|
|
for (int i = entries.length - 1; i >= 0; i--) {
|
|
list.prepend(entries[i]);
|
|
System.out.println("prepend(): " + entries[i]);
|
|
System.out.println(" size(): " + (entries.length - i));
|
|
System.out.println("Your code: " + list.size());
|
|
}
|
|
for (int i = 0; i < entries.length; i++) {
|
|
System.out.println(" get(" + i + "): " + entries[i]);
|
|
System.out.println("Your code: " + list.get(i));
|
|
}
|
|
System.out.println(" get(-1): IllegalArgumentException");
|
|
try {
|
|
list.get(-1);
|
|
System.out.println("Your code: no exception" );
|
|
} catch (Exception e) {
|
|
System.out.println("Your code: " + e.getClass().getSimpleName());
|
|
}
|
|
System.out.println(" get(10): IllegalArgumentException");
|
|
try {
|
|
list.get(10);
|
|
System.out.println("Your code: no exception" );
|
|
} catch (Exception e) {
|
|
System.out.println("Your code: " + e.getClass().getSimpleName());
|
|
}
|
|
|
|
}
|
|
|
|
}
|