CSE215.4 Problem Set B Summer 2024
CSE215.4 Problem Set B Summer 2024
Ques No. 1
roblem Statement:
P
Personwith attributes
Create a class nameand
age
.Include:
A
● constructor to initialize attributes.
display()method to print person details.
● A
Input:
erson p =
P new
Person(
"John"
,
25
);
p.display();
Output:
ame: John
N
Age:
25
Ques No. 2
roblem Statement:
P
Studentwith:
Create a class
n
● ame id
, gpaattributes.
, and
● Constructors to initialize with different combinations of attributes.
showInfo()to print student details.
● A method
Input:
tudent s1 =
S new
Student(
"Alice"
,
101);
Student s2 =
new
Student(
"Bob"
,
102,
3.8);
s1.showInfo();
s2.showInfo();
Output:
Ques No. 3
roblem Statement:
P
Printerwith a polymorphic
Create a class print()method:
●
print(int n)
: Prints an integer.
●
print(String s)
: Prints a string.
Input:
rinter p =
P newPrinter();
p.print(
123
);
p.print(
"Hello"
);
Output:
23
1
Hello
Ques No. 4
roblem Statement:
P
Employeewith a
Create a class work()method. Createa subclass
Developerthat inherits
Employeeand overrides
work()
.
Output:
mployee is working.
E
Developer is coding.
Ques No. 5
roblem Statement:
P
Appliancewith
Create an abstract class turnOn()and
turnOff()methods. Implement
Lightand
these in Fanclasses.
Output:
ight is turned on.
L
Fan is turned off.
Ques No. 6
Drawablewith a
reate an interface
C draw()method.Implement it in
Circleand
Square
classes.
Input:
ircle c =
C new
Circle();
Square s =
new
Square();
c.draw();
s.draw();
Output:
rawing a circle.
D
Drawing a square.
Ques No. 7
roblem Statement:
P
Implement the following UML class diagram.
Output:
Rover says Woof!
Ques No. 8
roblem Statement:
P
Playablewith
Create an interface start()and
stop()methods. Implement in
Videoand
Audio
.
Input:
ideo v =
V new
Video();
Audio a =
new
Audio();
v.start();
a.stop();
Output:
ideo playing.
V
Audio stopped.
Ques No. 9
Transportwith
Create a class move() Bus
. Subclass and
Caroverrides
move()method.
Input:
ransport t =
T new
Transport();
Bus b =
new
Bus();
ar c =
C new
Car();
t.move();
b.move();
c.move();
Output:
ransport is moving.
T
Bus is moving on the road.
Car is moving on the road.
Input:
obot r =
R new
Robot();
r.operate();
Output:
Robot is operating.