Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
embedded_systems_public
Java-Exercises-3-OOP2
Commits
80162a0d
Commit
80162a0d
authored
Nov 22, 2017
by
Martin Deinhofer
Browse files
failure: class Course was not abstract
added examples for LabCourse and Webinar instantiation
parent
2f46046d
Changes
2
Show whitespace changes
Inline
Side-by-side
src/java_exercises3_1_1/Course.java
View file @
80162a0d
...
...
@@ -6,7 +6,7 @@ package java_exercises3_1_1;
* @author mad
*
*/
public
class
Course
{
public
abstract
class
Course
{
private
String
name
;
private
int
id
;
...
...
src/java_exercises3_1_1/TestUni.java
View file @
80162a0d
package
java_exercises3_1_1
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java_exercises3_1_1.*
;
/**
...
...
@@ -8,7 +11,7 @@ import java_exercises3_1_1.*;
*
*/
public
class
TestUni
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
throws
MalformedURLException
{
//Instantiate student called Martin
Student
student
=
new
Student
(
"Martin"
,
1
);
University
uni
=
new
University
();
...
...
@@ -16,18 +19,27 @@ public class TestUni {
uni
.
register
(
student
);
//Book Student Martin for the course Java Intro
Course
c
ourse
=
new
Course
(
"Java Intro"
,
1
);
Course
labC
ourse
=
new
Lab
Course
(
"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.
//Let's try to book the course by a Student.
c
ourse
.
book
(
student
);
labC
ourse
.
book
(
student
);
//Book Alumni Peter for course Java Intro
Alumni
alumni
=
new
Alumni
(
"Peter"
);
//Also alumnis are allowed to book a course.
c
ourse
.
book
(
alumni
);
labC
ourse
.
book
(
alumni
);
//But alumnis are not allowed to register. If you uncomment the follwing line you will get a compile error.
//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.
System
.
out
.
println
(
"Name of Student: "
+
student
.
getName
()+
", Name of Alumni: "
+
alumni
.
getName
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment