Commit 80162a0d authored by Martin Deinhofer's avatar Martin Deinhofer
Browse files

failure: class Course was not abstract

added examples for LabCourse and Webinar instantiation
parent 2f46046d
...@@ -6,7 +6,7 @@ package java_exercises3_1_1; ...@@ -6,7 +6,7 @@ package java_exercises3_1_1;
* @author mad * @author mad
* *
*/ */
public class Course { public abstract class Course {
private String name; private String name;
private int id; private int id;
......
package java_exercises3_1_1; package java_exercises3_1_1;
import java.net.MalformedURLException;
import java.net.URL;
import java_exercises3_1_1.*; import java_exercises3_1_1.*;
/** /**
...@@ -8,7 +11,7 @@ import java_exercises3_1_1.*; ...@@ -8,7 +11,7 @@ import java_exercises3_1_1.*;
* *
*/ */
public class TestUni { public class TestUni {
public static void main(String[] args) { public static void main(String[] args) throws MalformedURLException {
//Instantiate student called Martin //Instantiate student called Martin
Student student=new Student("Martin",1); Student student=new Student("Martin",1);
University uni=new University(); University uni=new University();
...@@ -16,18 +19,27 @@ public class TestUni { ...@@ -16,18 +19,27 @@ public class TestUni {
uni.register(student); uni.register(student);
//Book Student Martin for the course Java Intro //Book Student Martin for the course Java Intro
Course course=new Course("Java Intro",1); Course labCourse=new LabCourse("Java Intro",1, new String[]{"Exercise 1","Exercise 2"});
//From here we can't access the member variables of class Course because they are private. //From here we can't access the member variables of class Course because they are private.
//Let's try to book the course by a Student. //Let's try to book the course by a Student.
course.book(student); labCourse.book(student);
//Book Alumni Peter for course Java Intro //Book Alumni Peter for course Java Intro
Alumni alumni=new Alumni("Peter"); Alumni alumni=new Alumni("Peter");
//Also alumnis are allowed to book a course. //Also alumnis are allowed to book a course.
course.book(alumni); labCourse.book(alumni);
//But alumnis are not allowed to register. If you uncomment the follwing line you will get a compile error. //But alumnis are not allowed to register. If you uncomment the follwing line you will get a compile error.
//uni.register(alumni); //uni.register(alumni);
Course webinar=new Webinar("Java for Embedded",2,new URL("http://es.technikum-wien.at/webinar/"));
webinar.book(student);
webinar.book(alumni);
//Existent courses
System.out.println("\nThe following courses exist:");
System.out.println(labCourse);
System.out.println(webinar+"\n");
//Both alumnis and students implement the Attendee interface and hence provide a method called getName. //Both alumnis and students implement the Attendee interface and hence provide a method called getName.
System.out.println("Name of Student: "+student.getName()+", Name of Alumni: "+alumni.getName()); System.out.println("Name of Student: "+student.getName()+", Name of Alumni: "+alumni.getName());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment