ICSE Class 10 Computer Applications (Java): 100/100 Master Code Vault & Algorithms
Learn how classes, constructors and overloaded methods organize Java programs, then trace searches, sorts and String operations. Short examples focus on following each algorithm step by step.

Questions with worked answers
Use these to practise clear, step-by-step answer writing.
ICSE 2024 Computer Applications (Section B — Class Design): Define a class named 'courier' with member variables String name, double weight, String address, double bill, char type ('D' for domestic, 'I' for international). Write methods: - void accept(): input name, weight, address, and type using Scanner. - void calculate(): compute bill at ₹800/kg for first 5 kg, ₹700/kg for next 5 kg, ₹500/kg above 10 kg; add ₹1500 extra if type == 'I'. - void print(): display all details. - main(): create an object and invoke the methods.
CISCE Marking Scheme (15 Marks = Class & Variables 2 + accept() 3 + calculate() slabs & 'I' surcharge 6 + print() & main() 2 + VDT 2):
```java
import java.util.Scanner;
public class courier {
String name, address;
double weight, bill;
char type;
void accept() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter name, address, weight (kg), type (D/I):");
name = sc.nextLine();
address = sc.nextLine();
weight = sc.nextDouble();
type = Character.toUpperCase(sc.next().charAt(0));
}
void calculate() {
if (weight <= 5)
bill = weight * 800;
else if (weight <= 10)
bill = 5 * 800 + (weight - 5) * 700;
else
bill = 5 * 800 + 5 * 700 + (weight - 10) * 500;
if (type == 'I')
bill += 1500;
}
void print() {
System.out.println("Name: " + name + "\nAddress: " + address);
System.out.println("Weight: " + weight + "\nType: " + type + "\nTotal Bill: Rs." + bill);
}
public static void main(String[] args) {
courier ob = new courier();
ob.accept();
ob.calculate();
ob.print();
}
}
```
Include a Variable Description Table (VDT) listing name, address, weight, bill, type with data types and purposes (2 marks).ICSE 2024 Specimen Computer Applications (Section B — Method Overloading): Define a class to overload the method display as follows: 1. void display(): print the triangle pattern for 5 rows: Row 1 prints '1', Row 2 prints '1 2', ..., Row 5 prints '1 2 3 4 5'. 2. void display(int n): extract each digit of n and print its square root on a separate line (e.g., for n = 4329, print √9, √2, √3, √4).
CISCE Marking Scheme (15 Marks = Class/main 2 + display() nested loops 6 + display(int n) digit extraction & Math.sqrt 5 + VDT 2):
```java
public class OverloadDisplay {
void display() {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
void display(int n) {
while (n > 0) {
int d = n % 10;
System.out.println(Math.sqrt(d));
n = n / 10;
}
}
public static void main(String[] args) {
OverloadDisplay ob = new OverloadDisplay();
ob.display();
ob.display(4329);
}
}
```
Dry-run check for n = 4329: d=9 -> 3.0; d=2 -> 1.414...; d=3 -> 1.732...; d=4 -> 2.0. Always include VDT (i, j, n, d).ICSE 2023 Computer Applications (Section B — Overloading & Lead Number): Define a class to overload void print() and void print(int n): 1. void print(): print 5 rows where each row i (1 to 5) prints the digit i four times (e.g. '1 1 1 1' up to '5 5 5 5'). 2. void print(int n): check whether n is a Lead Number (a number whose sum of even digits equals the sum of odd digits, e.g. 3669).
CISCE Marking Scheme (15 Marks = Nested loop 5 + Digit loop & parity check 8 + VDT 2):
```java
public class OverloadPrint {
void print() {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 4; j++) {
System.out.print(i + " ");
}
System.out.println();
}
}
void print(int n) {
int evenSum = 0, oddSum = 0, temp = n;
while (temp > 0) {
int d = temp % 10;
if (d % 2 == 0) evenSum += d;
else oddSum += d;
temp /= 10;
}
if (evenSum == oddSum)
System.out.println(n + " is a Lead Number");
else
System.out.println(n + " is NOT a Lead Number");
}
}
```
Dry-run for 3669: evenSum = 6 + 6 = 12; oddSum = 9 + 3 = 12 -> Lead Number.ICSE 2023 Computer Applications (Section B — Binary Search): Write a Java program to store 10 sorted integer graduation years {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010} in a single-dimensional array. Accept a year from the user and search for it using Binary Search. Print 'Record exists' with index if found, else 'Record does not exist'.
CISCE Marking Scheme (15 Marks = Array init & Scanner input 3 + Binary search while(low<=high) logic 8 + Output & flag 2 + VDT 2):
```java
import java.util.Scanner;
public class YearSearch {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int yr[] = {1982, 1987, 1993, 1996, 1999, 2003, 2006, 2007, 2009, 2010};
System.out.println("Enter graduation year:");
int key = sc.nextInt();
int low = 0, high = yr.length - 1, pos = -1;
while (low <= high) {
int mid = (low + high) / 2;
if (yr[mid] == key) {
pos = mid;
break;
} else if (yr[mid] < key) {
low = mid + 1;
} else {
high = mid - 1;
}
}
if (pos != -1) System.out.println("Record exists at index " + pos);
else System.out.println("Record does not exist");
}
}
```
Common Error: Writing linear search instead of binary search gives zero credit for the search logic marks.ICSE 2024 Computer Applications (Section B — Bubble Sort on Strings): Write a Java program to accept 10 city names into a String array, sort them in alphabetical (ascending) order using Bubble Sort, and display the sorted array.
CISCE Marking Scheme (15 Marks = Input 3 + Bubble Sort with compareTo() & swap 8 + Output 2 + VDT 2):
```java
import java.util.Scanner;
public class CityBubbleSort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String city[] = new String[10];
System.out.println("Enter 10 city names:");
for (int i = 0; i < 10; i++) city[i] = sc.nextLine();
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9 - i; j++) {
if (city[j].compareToIgnoreCase(city[j + 1]) > 0) {
String temp = city[j];
city[j] = city[j + 1];
city[j + 1] = temp;
}
}
}
System.out.println("Sorted Cities:");
for (int i = 0; i < 10; i++) System.out.println(city[i]);
}
}
```
Common Error: Using '>' operator on Strings (illegal in Java); must use .compareTo() or .compareToIgnoreCase().Complete study notes
A clear, structured version of the full chapter content.
1. Principles of Object-Oriented Programming (OOP)
Encapsulation: Wrapping code and data together into a single unit (class) with restricted access using access specifiers (
private,public,protected).Inheritance: Mechanism where an object acquires all the properties and behaviors of a parent class (
extendskeyword).Polymorphism: The ability of a message or method to be processed in more than one form (e.g., Method Overloading).
Abstraction: Hiding background implementation details and showing only essential features to the user.
2. Key Java Algorithms for Section B (Board Exam)
A. Binary Search Algorithm (Precondition: Array must be sorted)
public static int binarySearch(int arr[], int key) {
int low = 0, high = arr.length - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] == key) return mid;
else if (arr[mid] < key) low = mid + 1;
else high = mid - 1;
}
return -1; // Element not found
}B. Bubble Sort Algorithm (Ascending Order)
public static void bubbleSort(int arr[]) {
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}3. String Handling High-Yield Methods
s.length(): Returns total count of characters.s.charAt(index): Returns character at specified 0-based index.s.substring(start, end): Extracts substring fromstartup toend - 1.s.indexOf(ch): Returns first index ofchor-1if absent.s.compareTo(other): Compares strings lexicographically (returns difference in ASCII values).Character.isUpperCase(ch),Character.isLowerCase(ch),Character.isDigit(ch),Character.toUpperCase(ch).