P1-P5: rewrite to match current syllabus

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-06-05 00:09:49 +05:30
parent 9006831163
commit 539adc94da
7 changed files with 209 additions and 214 deletions

37
P3.java
View File

@@ -1,14 +1,27 @@
class P3 {
public static void main(String[] _args) {
int a = 5, b = -5, c = 55, mx;
interface Animal {
void makeSound();
}
if (a > b && a > c)
mx = a;
else if ( b > a && b > c)
mx = b;
else
mx = c;
class Cat implements Animal {
@Override
public void makeSound() {
System.out.println("Meow!");
}
}
System.out.println("max(" + a + ", " + b + ", " + c + ") = " + mx);
}
}
class Cow implements Animal {
@Override
public void makeSound() {
System.out.println("Moo!");
}
}
public class P3 {
public static void main(String[] args) {
Animal cat = new Cat();
Animal cow = new Cow();
cat.makeSound();
cow.makeSound();
}
}