0% found this document useful (0 votes)
3 views2 pages

Java Exercise9 - Abstract Class and Interface

The document outlines a Java exercise involving the creation of abstract classes and interfaces, including a GeometricObject class with Circle and Rectangle subclasses, and an Animal class with an Edible interface. It also describes the implementation of a Vehicle interface with Car and Motorcycle subclasses, and a University class containing static and non-static inner classes for Department and Student. The exercise requires writing test programs to implement these classes and accept user inputs.

Uploaded by

wuxizinapefu86
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Exercise9 - Abstract Class and Interface

The document outlines a Java exercise involving the creation of abstract classes and interfaces, including a GeometricObject class with Circle and Rectangle subclasses, and an Animal class with an Edible interface. It also describes the implementation of a Vehicle interface with Car and Motorcycle subclasses, and a University class containing static and non-static inner classes for Department and Student. The exercise requires writing test programs to implement these classes and accept user inputs.

Uploaded by

wuxizinapefu86
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Exercise9 [Abstract Class and Interface]

1. Write a Java program which defines an abstract GeometricObject class and contains two
abstract methods getArea() and getPerimeter() which are implemented in the subclasses Circle
and Rectangle as shown in the following class diagram. Write a test program which implements
all the classes and accept all the necessary inputs from keyboard.

GeometricObject
- color : String
- filled : boolean
- dateCreated : Date
#GeometricObject(c : String, f : boolean)
+ getColor() : String
+ setColor(c : String):void
+ isFilled(f: boolean): boolean
+ setFilled(f:boolean):void
+ getDeteCreated():Date
+ getArea():double
+getPerimeter():double

Circle Rectangle
-radius : double - width : double
+ Circle(c : String, f : Boolean, rad : double) - height : double
+ getRadius() : double + Rectangle(c : String, f : Boolean, w : double, h: double)
+ setRadius(rad : double):void + getWidth() : double
+ getDiameter():double + setWidth(w : double):void
+ prictCircle():void + getHeight(): double
+ setHeight(h:double):void
+ prictRectangle():void

2. Write a Java program which defines an abstract Animal class and an interface Edible and
contains two abstract methods howToEat() and sound() which are implemented in their
subclasses as shown in the following class diagram. Write a test program which implements all
the classes and accept all the necessary inputs from keyboard.

«interface» Animal
Edible
+sound(): String
+howToEat(): String

Fruit Chicken Tiger


- - -

Orange Apple
1
- -
3. Create an interface called Vehicle with methods start() and stop() and then create two
subclasses Car and Motorcycle these classes implement all the methods in the interface.
4. Create an outer class called University with static inner class Department and non-static inner
class Student as show in the following class diagram. Write a test program that implements the
inner classes.

University
+ universityName : String
+ location : String
+ University(location : String)
+ displayUniversity() : void

Department Student
~ departmentName : String ~ id : int
~ noOfStudent: int ~ name : String
~ Department(depName : String, noStud : int) ~ Student(id : int, name : String)
~ displayDepartment():void ~ displayStudent():void

You might also like