CITY MONTESSORI SCHOOL
Gomti Nagar - I
CT & ICT
CLASS – 8
Subject – Fundamentals of Java
Holiday Homework
1. Case Study
Q: You are using a Calculator app. When you press '=' it gives you the result, but you don’t
know the internal calculations.
A: The OOP concept applied here is Encapsulation.
Why? Because the internal logic (data and methods) is hidden from the user. The calculator
performs the operation internally and only shows the final result.
2. Case Study
Q: A parent class Shape has a method draw(). The subclasses Circle, Rectangle, and Triangle
each provide their own version of draw().
A: The OOP concept used here is Polymorphism.
Explanation: Polymorphism allows methods to behave differently based on the object
calling them. Each subclass provides its own implementation of the draw() method.
3. Predict the Output
int a = 17, b = 3, result;
result = a % b;
System.out.println(result);
Answer: a) 2
4. Evaluate the following
If a = 12, b = 5
b = a / b + b % 3;
Answer: b = 4
5. Convert into Java Expressions:
A = b * b + 4 * a * c;
x = (a + b) * (a - b);
F = m * a;
E = 0.5 * m * v * v;
area = 3.14 * r * r;
6. Java Program to Print Name, Class, Roll No:
class PersonalInfo {
public static void main(String[] args) {
System.out.print("Name: ");
System.out.print("Vinayak\n");
System.out.print("Class: ");
System.out.print("8\n");
System.out.print("Roll No: ");
System.out.print("50");
}
}
7. Program to Calculate Speed:
class Speed {
public static void main(String[] args) {
int distance = 50;
int time = 1;
int speed = distance / time;
System.out.println("Speed = " + speed + " km/hr");
}
}
8. Program to Calculate Simple Interest:
import java.util.Scanner;
class SimpleInterest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Principal: ");
double p = sc.nextDouble();
System.out.print("Enter Rate of Interest: ");
double r = sc.nextDouble();
System.out.print("Enter Time: ");
double t = sc.nextDouble();
double si = (p * r * t) / 100;
System.out.println("Simple Interest = " + si);
}
}
9. Assign Java Data Types:
A = 45 → int A = 45;
B = 'A' → char B = 'A';
C = "Java" → String C = "Java";
D = 67.89 → double D = 67.89;
F = 23.567f → float F = 23.567f;
10. Debug the Program:
Incorrect:
class Division {
void calculate(double a, b) {
double result = a / b;
System.out.println("Result is : " + result);
}
}
Correct:
class Division {
void calculate(double a, double b) {
double result = a / b;
System.out.println("Result is : " + result);
}
}