0% found this document useful (0 votes)
15 views6 pages

CSE215.4 Problem Set B Summer 2024

Uploaded by

Ajom Khan
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)
15 views6 pages

CSE215.4 Problem Set B Summer 2024

Uploaded by

Ajom Khan
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
You are on page 1/ 6

‭Problem Set - B‬

‭Ques No. 1‬
‭ roblem Statement:‬
P
Person‬‭with attributes‬‭
‭Create a class‬‭ name‬‭and‬‭
age‬
‭.‬‭Include:‬

‭‬ A
● ‭ constructor to initialize attributes.‬
display()‬‭method to print person details.‬
‭●‬ ‭A‬‭

‭UML Class Diagram:‬

‭Input:‬

‭erson p =‬‭
P new‬‭
Person(‬
"John"‬
‭ ,‬‭
‭ 25‬
);‬

p.display();‬

‭Output:‬

‭ame: John‬
N
Age:‬‭
‭ 25‬

‭Ques No. 2‬
‭ roblem Statement:‬
P
Student‬‭with:‬
‭Create a class‬‭

‭‬ n
● ‭ame‬ id‬
‭,‬‭ gpa‬‭attributes.‬
‭, 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:‬

‭ame: Alice, ID:‬‭


N 101‬, GPA: Not available‬

Name: Bob, ID:‬‭
‭ 102‬, GPA:‬‭
‭ 3.8‬

‭Ques No. 3‬
‭ roblem Statement:‬
P
Printer‬‭with a polymorphic‬‭
‭Create a class‬‭ print()‬‭method:‬

‭●‬ ‭
print(int n)‬
‭: Prints an integer.‬
‭●‬ ‭
print(String s)‬
‭: Prints a string.‬

‭Input:‬
‭rinter p =‬‭
P new‬‭Printer();‬
p.print(‬
‭ 123‬
‭ );‬

p.print(‬
‭ "Hello"‬
‭ );‬

‭Output:‬

‭23‬
1
Hello‬

‭Ques No. 4‬
‭ roblem Statement:‬
P
Employee‬‭with a‬‭
‭Create a class‬‭ work()‬‭method. Create‬‭a subclass‬‭
Developer‬‭that inherits‬
Employee‬‭and overrides‬‭
‭ work()‬
‭.‬

‭UML Class Diagram:‬


‭Input:‬
‭mployee e =‬‭
E new‬‭Employee();‬
Developer d =‬‭
‭ new‬‭
Developer();‬
e.work();‬

d.work();‬

‭Output:‬
‭mployee is working.‬
E
Developer is coding.‬

‭Ques No. 5‬
‭ roblem Statement:‬
P
Appliance‬‭with‬‭
‭Create an abstract class‬‭ turnOn()‬‭and‬‭
turnOff()‬‭methods. Implement‬
Light‬‭and‬‭
‭these in‬‭ Fan‬‭classes.‬

‭UML Class Diagram:‬


‭Input:‬
‭ight l =‬‭
L new‬‭
Light();‬
Fan f =‬‭
‭ new‬‭
Fan();‬
l.turnOn();‬

f.turnOff();‬

‭Output:‬
‭ight is turned on.‬
L
Fan is turned off.‬

‭Ques No. 6‬
Drawable‬‭with a‬‭
‭ reate an interface‬‭
C draw()‬‭method.‬‭Implement it in‬‭
Circle‬‭and‬‭
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.‬

‭UML Class Diagram:‬


‭Input:‬
‭og d =‬‭
D new‬‭
Dog(‬
"Rover"‬
‭ );‬

d.makeSound();‬

‭Output:‬
Rover says Woof!‬

‭Ques No. 8‬
‭ roblem Statement:‬
P
Playable‬‭with‬‭
‭Create an interface‬‭ start()‬‭and‬‭
stop()‬‭methods. Implement in‬‭
Video‬‭and‬
Audio‬
‭ ‭.‬

‭Input:‬
‭ideo v =‬‭
V new‬‭
Video();‬
Audio a =‬‭
‭ new‬‭
Audio();‬
v.start();‬

a.stop();‬

‭Output:‬
‭ideo playing.‬
V
Audio stopped.‬

‭Ques No. 9‬
Transport‬‭with‬‭
‭Create a class‬‭ move()‬ Bus‬‭
‭. Subclass‬‭ and‬‭
Car‬‭overrides‬‭
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.‬

‭Ques No. 10‬


‭ roblem Statement:‬
P
Machine‬‭and an interface‬‭
‭Create an abstract class‬‭ Operable‬‭with‬‭
operate()‬‭method.‬
Machine‬‭and‬‭
‭Implement‬‭ Operable‬‭in‬‭
Robot‬
‭.‬

‭UML Class Diagram:‬

‭Input:‬
‭obot r =‬‭
R new‬‭
Robot();‬
r.operate();‬

‭Output:‬
Robot is operating.‬

You might also like