100% found this document useful (1 vote)
25 views22 pages

Core Java Programs for ISC Class 12

The document outlines a Class 12 Computer Science project titled 'A Collection of Core Java Programs' for the academic session 2024-2025. It includes a certificate of originality, acknowledgments, an introduction to the project and Java programming, as well as ten detailed Java programming assignments covering various concepts. Each program is presented with a problem statement, source code, and inputs/outputs to demonstrate functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
25 views22 pages

Core Java Programs for ISC Class 12

The document outlines a Class 12 Computer Science project titled 'A Collection of Core Java Programs' for the academic session 2024-2025. It includes a certificate of originality, acknowledgments, an introduction to the project and Java programming, as well as ten detailed Java programming assignments covering various concepts. Each program is presented with a problem statement, source code, and inputs/outputs to demonstrate functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ISC Class 12 Computer Science Project

File
Academic Session: 2024-2025
Topic: A Collection of Core Java Programs
Submitted by:
Class: 12
ISC Roll Number:
Submitted to:
(Internal Examiner)
[External Examiner's Name] (External Examiner)

Certificate of Originality
This is to certify that, a student of Class XII at, with ISC Roll Number, has successfully
completed this Computer Science project titled 'A Collection of Core Java Programs' for the
academic year 2024-2025.
This project is the result of the student's own bonafide work and investigation. The work is
original and has been completed in partial fulfillment of the requirements for the Indian School
Certificate (ISC) Examination. The content of this project has not been submitted, either in
whole or in part, for any other examination or degree.
The programs and solutions herein are the student's own work, completed under my
supervision.

____________________ ____________________
(Signature of Student) (Signature of Teacher / Internal Examiner)

____________________ ____________________
(Signature of External Examiner) (Signature of Principal)
[Principal's Name]
School Stamp:

Acknowledgement
I would like to express my profound gratitude to my computer science teacher, ****, for their
invaluable guidance, constant encouragement, and insightful feedback throughout this project.
Their expertise was instrumental in navigating the complexities of the Java programming
language and the specific requirements of the ISC project.
I also extend my sincere thanks to our Principal, [Principal's Name], for providing the
necessary facilities and a conducive learning environment in the school's computer laboratory,
which was essential for the completion of this work.
I am deeply grateful to my parents and family for their unwavering support, patience, and
motivation, which helped me complete this project on time.
Finally, I would like to thank my friends and classmates for their constructive discussions and for
creating a collaborative and supportive atmosphere.

Table of Contents
1. Introduction
○ 1.1. Introduction to the Project
○ 1.2. Introduction to the Java Programming Language
2. Java Programming Assignments
○ 2.1. Program 1: Prime Number Checker
○ 2.2. Program 2: Armstrong Number Checker
○ 2.3. Program 3: String Palindrome Checker
○ 2.4. Program 4: Sum and Average of a 1D Array
○ 2.5. Program 5: Count Vowels and Consonants
○ 2.6. Program 6: Unique-Digit Number Checker
○ 2.7. Program 7: Caesar Cipher Text Encryption
○ 2.8. Program 8: Factorial (using Recursion)
○ 2.9. Program 9: Palindrome Number (using Recursion)
○ 2.10. Program 10: Simple Inheritance Demonstration
3. Project Conclusion
4. Bibliography

1. Introduction
1.1. Introduction to the Project
The objective of this project is to design, develop, and document a collection of Java programs
that demonstrate a comprehensive understanding of the programming concepts prescribed by
the ISC Class 12 Computer Science syllabus. This project file serves as the practical record
(Paper II) of the programming assignments completed during the academic year.
The Council for the Indian School Certificate Examinations (CISCE) mandates that students
complete a significant number of practical assignments, with a minimum of 35 assignments
expected over the year. This project file presents 10 exemplary programs, meticulously
documented to serve as a high-quality model for the complete portfolio. The structure and depth
applied to these 10 programs represent the standard intended for all practical assignments.
In accordance with the ISC project guidelines, each program is presented using a 3-part
structure :
1. Problem Statement: A clear and concise definition of the program's objective.
2. Source Code: The complete, commented Java program.
3. Inputs & Outputs: A minimum of five sets of test data, including sample inputs and their
corresponding outputs, to demonstrate the program's correctness and handling of edge
cases.
The selected programs cover a breadth of topics from the syllabus, including number properties,
string manipulation, 1D arrays, recursive algorithms, and the principles of Object-Oriented
Programming (OOP).
1.2. Introduction to the Java Programming Language
The programs in this project are all implemented using the Java programming language. Java is
a high-level, class-based, object-oriented programming language developed by James Gosling
at Sun Microsystems and released in May 1995.
Core Principle: Write Once, Run Anywhere (WORA)
Java's most defining feature is its principle of "Write Once, Run Anywhere" (WORA). This is
achieved through a two-stage process:
1. Compilation: Java source code (.java file) is compiled into an intermediate form called
bytecode (.class file), not into native machine code.
2. Interpretation: This bytecode can run on any device, regardless of its underlying
architecture, as long as it has a Java Virtual Machine (JVM) installed. The JVM acts as
an interpreter that translates the universal bytecode into specific machine instructions for
that device.
Key Features of Java
Java's design incorporates several key features that have made it one of the most popular
programming languages in the world :
● Object-Oriented Programming (OOP): Java is fundamentally an object-oriented
language. Almost everything in Java is an object, which organizes programs around data
(objects) and behaviors (methods). This project demonstrates key OOP concepts like
classes, objects, inheritance, and polymorphism.
● Platform Independent: As a result of the JVM and the WORA principle, a Java program
compiled on one operating system (e.g., Windows) can run without modification on any
other (e.g., macOS, Linux).
● Robust and Secure: Java is designed for reliability. It features automatic memory
management through a process called "garbage collection," which prevents common
programming errors related to memory leaks. Its security features, built into the JVM, help
protect systems from untrusted code.
● Multithreaded: Java has built-in support for multithreading, allowing a program to
perform multiple tasks concurrently. This is essential for modern applications, such as
games and web servers.
● Versatile: Java is used across a vast array of applications, including enterprise-level web
applications, big data processing, cloud computing, and, notably, as the primary language
for Android mobile app development.
This project utilizes these features to solve a variety of computational problems, providing a
practical foundation in this powerful language.

2. Java Programming Assignments


2.1. Program 1: Prime Number Checker
Problem Statement
Write a program to accept an integer from the user and check if it is a prime number. A prime
number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
The program should handle edge cases like 0, 1, and 2.
Source Code
import [Link];

/**
* ISC Program to check if a number is a prime number.
*/
public class PrimeChecker {

public static void main(String args) {


Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();

boolean isPrime = true;

// 0 and 1 are not prime numbers


if (number <= 1) {
isPrime = false;
} else {
// Check for factors from 2 up to the square root of the
number
for (int i = 2; i <= [Link](number); i++) {
if (number % i == 0) {
// If a factor is found, it's not prime
isPrime = false;
break;
}
}
}

if (isPrime) {
[Link](number + " is a prime number.");
} else {
[Link](number + " is not a prime number.");
}

[Link]();
}
}

Inputs & Outputs


Input/Output 1 (Prime):
Enter a number: 29
29 is a prime number.

Input/Output 2 (Not Prime):


Enter a number: 33
33 is not a prime number.

Input/Output 3 (Prime):
Enter a number: 97
97 is a prime number.

Input/Output 4 (Edge Case - 1):


Enter a number: 1
1 is not a prime number.
Input/Output 5 (Edge Case - 2):
Enter a number: 2
2 is a prime number.

2.2. Program 2: Armstrong Number Checker


Problem Statement
Write a program to check if a given number is an Armstrong number. An Armstrong number is a
number that is equal to the sum of its own digits each raised to the power of the number of
digits. Example (3-digit): 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. Example (4-digit): 1634 =
1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634.
Source Code
import [Link];

/**
* ISC Program to check if a number is an Armstrong number.
*/
public class ArmstrongNumber {

public static void main(String args) {


Scanner scanner = new Scanner([Link]);
[Link]("Enter a number: ");
int number = [Link]();

int originalNumber, remainder, n = 0;


double result = 0.0;

originalNumber = number;

// Store the number of digits in n


n = [Link](number).length();

// Calculate the sum of powers of digits


while (originalNumber!= 0) {
remainder = originalNumber % 10;
result += [Link](remainder, n);
originalNumber /= 10;
}

// Check if the result is equal to the original number


if ((int)result == number) {
[Link](number + " is an Armstrong number.");
} else {
[Link](number + " is not an Armstrong
number.");
}

[Link]();
}
}

Inputs & Outputs


Input/Output 1 (3-Digit Armstrong):
Enter a number: 153
153 is an Armstrong number.

Input/Output 2 (4-Digit Armstrong):


Enter a number: 1634
1634 is an Armstrong number.

Input/Output 3 (Not Armstrong):


Enter a number: 123
123 is not an Armstrong number.

Input/Output 4 (3-Digit Armstrong):


Enter a number: 371
371 is an Armstrong number.

Input/Output 5 (Not Armstrong):


Enter a number: 400
400 is not an Armstrong number.

2.3. Program 3: String Palindrome Checker


Problem Statement
Write a program to accept a string from the user and check if it is a palindrome. A palindrome is
a string that reads the same forwards and backwards, ignoring case. Example: "Radar", "Level",
"racecar".
Source Code
import [Link];

/**
* ISC Program to check if a string is a palindrome (iterative).
*/
public class StringPalindrome {

public static void main(String args) {


Scanner scanner = new Scanner([Link]);
[Link]("Enter a string: ");
String input = [Link]();

boolean isPalindrome = true;

// Convert to lowercase for case-insensitive comparison


String str = [Link]();

int left = 0;
int right = [Link]() - 1;
// Use two pointers, one at the start and one at the end
while (left < right) {
if ([Link](left)!= [Link](right)) {
isPalindrome = false;
break;
}
left++;
right--;
}

if (isPalindrome) {
[Link]("\"" + input + "\" is a palindrome.");
} else {
[Link]("\"" + input + "\" is not a
palindrome.");
}

[Link]();
}
}

Inputs & Outputs


Input/Output 1 (Palindrome, Mixed Case):
Enter a string: Radar
"Radar" is a palindrome.

Input/Output 2 (Palindrome):
Enter a string: racecar
"racecar" is a palindrome.

Input/Output 3 (Not Palindrome):


Enter a string: Java
"Java" is not a palindrome.

Input/Output 4 (Palindrome):
Enter a string: level
"level" is a palindrome.

Input/Output 5 (Not Palindrome):


Enter a string: GeeksForGeeks
"GeeksForGeeks" is not a palindrome.

2.4. Program 4: Sum and Average of a 1D Array


Problem Statement
Write a program to create a single-dimensional integer array of size n, where n is entered by the
user. Accept n integers from the user, store them in the array, and then calculate and display
the sum and average of all the elements in the array.
Source Code
import [Link];
/**
* ISC Program to find the sum and average of elements in a 1D array.
*/
public class ArraySumAverage {

public static void main(String args) {


Scanner scanner = new Scanner([Link]);

[Link]("Enter the number of elements in the array:


");
int n = [Link]();

int arr = new int[n];


int sum = 0;

// Check if the array is empty


if (n <= 0) {
[Link]("Array is empty. No sum or average to
calculate.");
return;
}

[Link]("Enter " + n + " elements:");


for (int i = 0; i < n; i++) {
arr[i] = [Link]();
sum += arr[i]; // Calculate sum as we input
}

// Calculate average
double average = (double) sum / n;

[Link]("Sum of array elements: " + sum);


[Link]("Average of array elements: " + average);

[Link]();
}
}

Inputs & Outputs


Input/Output 1:
Enter the number of elements in the array: 5
Enter 5 elements:
1
2
3
4
5
Sum of array elements: 15
Average of array elements: 3.0
Input/Output 2:
Enter the number of elements in the array: 3
Enter 3 elements:
10
20
30
Sum of array elements: 60
Average of array elements: 20.0

Input/Output 3:
Enter the number of elements in the array: 4
Enter 4 elements:
5
5
5
5
Sum of array elements: 20
Average of array elements: 5.0

Input/Output 4:
Enter the number of elements in the array: 2
Enter 2 elements:
1
3
Sum of array elements: 4
Average of array elements: 2.0

Input/Output 5 (Edge Case):


Enter the number of elements in the array: 0
Array is empty. No sum or average to calculate.

2.5. Program 5: Count Vowels and Consonants


Problem Statement
Write a program to accept a string from the user. The program should then count and display
the total number of vowels (a, e, i, o, u) and consonants in the string. The check should be
case-insensitive. Non-alphabetic characters should be ignored.
Source Code
import [Link];

/**
* ISC Program to count vowels and consonants in a string.
*/
public class VowelConsonantCount {

public static void main(String args) {


Scanner scanner = new Scanner([Link]);
[Link]("Enter a string: ");
String str = [Link]();
int vowelCount = 0;
int consonantCount = 0;

// Convert the string to lowercase for easy checking


str = [Link]();

for (int i = 0; i < [Link](); i++) {


char ch = [Link](i);

// Check if the character is a vowel


if (ch == 'a' |

| ch == 'e' |
| ch == 'i' |
| ch == 'o' |
| ch == 'u') {
vowelCount++;
}
// Check if the character is a consonant (an alphabet but
not a vowel)
else if (ch >= 'a' && ch <= 'z') {
consonantCount++;
}
// Other characters (spaces, numbers, symbols) are
ignored.
}

[Link]("Number of vowels: " + vowelCount);


[Link]("Number of consonants: " + consonantCount);

[Link]();
}
}

Inputs & Outputs


Input/Output 1:
Enter a string: Hello World
Number of vowels: 3
Number of consonants: 7

Input/Output 2:
Enter a string: GeeksforGeeks
Number of vowels: 5
Number of consonants: 8

Input/Output 3:
Enter a string: This is a test!
Number of vowels: 4
Number of consonants: 7

Input/Output 4:
Enter a string: AEIOU
Number of vowels: 5
Number of consonants: 0

Input/Output 5:
Enter a string: 12345
Number of vowels: 0
Number of consonants: 0

2.6. Program 6: Unique-Digit Number Checker


Problem Statement
Write a program to accept two positive integers m and n (where m < n and both are < 30000).
The program must find and display all "unique-digit" integers in the range [m, n]. A unique-digit
integer is one with no duplicate digits (e.g., 102 is unique, 121 is not). The program must also
print the total frequency of such numbers found. If no such numbers are found, it should print
"NIL".
Source Code
import [Link];

/**
* ISC Program to find all unique-digit integers within a given range.
* A unique-digit integer has no duplicate digits.
*/
class UniqueDigit {

/**
* Checks if a number is a unique-digit number.
* @param num The number to check.
* @return true if the number has unique digits, false otherwise.
*/
public static boolean isUnique(int num) {
// visited will store whether a digit (0-9) has been seen.
boolean visited = new boolean;

// Make a copy of the number to avoid modifying the original


int tempNum = num;

// Handle 0 separately as it will be missed in the loop if num


is 0
if (tempNum == 0) {
return true;
}

while (tempNum > 0) {


int d = tempNum % 10; // Extract the last digit

// If the digit was already visited, it's a duplicate


if (visited[d]) {
return false;
}

// Mark this digit as visited


visited[d] = true;
tempNum = tempNum / 10; // Remove the last digit
}

// If loop completes, no duplicates were found


return true;
}

public static void main(String args) {


Scanner in = new Scanner([Link]);

[Link]("m = ");
int m = [Link]();
[Link]("n = ");
int n = [Link]();

// Validate the input range as per the problem statement


if (m > n |

| m >= 30000 |
| n >= 30000) {
[Link]("INVALID RANGE");
return; // Exit the program
}

int count = 0; // Frequency counter


[Link]("THE UNIQUE-DIGIT INTEGERS ARE: ");

String output = ""; // To store the numbers for clean printing

for (int i = m; i <= n; i++) {


if (isUnique(i)) {
if (count == 0) {
output += i; // First number
} else {
output += ", " + i; // Subsequent numbers
}
count++;
}
}

if (count == 0) {
[Link]("NIL");
} else {
[Link](output);
}

[Link]("FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: " +


count);
[Link]();
}
}

Inputs & Outputs


Input/Output 1 (Sample Data ):
m = 100
n = 120
THE UNIQUE-DIGIT INTEGERS ARE:
102, 103, 104, 105, 106, 107, 108, 109, 120
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 9

Input/Output 2 (Sample Data - NIL ):


m = 2520
n = 2529
THE UNIQUE-DIGIT INTEGERS ARE:
NIL
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 0

Input/Output 3 (Invalid Range - m > n):


m = 150
n = 100
INVALID RANGE

Input/Output 4 (Invalid Range - n too large):


m = 100
n = 35000
INVALID RANGE

Input/Output 5 (Test Case with Duplicates):


m = 220
n = 230
THE UNIQUE-DIGIT INTEGERS ARE:
230
FREQUENCY OF UNIQUE-DIGIT INTEGERS IS: 1

2.7. Program 7: Caesar Cipher Text Encryption


Problem Statement
Write a program to implement a Caesar Cipher. The program should accept a string (plaintext)
and a shift key (integer). It should then encrypt the message by shifting each letter by the shift
key value, wrapping around the alphabet. The program should only shift alphabetic characters
and leave all other characters (spaces, punctuation, numbers) as is. Example: "HELLO" with
shift 3 becomes "KHOOR".
Source Code
import [Link];

/**
* ISC Program to encrypt a message using the Caesar Cipher technique.
* It shifts only alphabetic characters, wrapping around the alphabet,
* and leaves non-alphabetic characters unchanged.
*/
public class CaesarCipher {

public static void main(String args) {


Scanner in = new Scanner([Link]);

[Link]("Enter the String for Encryption:");


String message = [Link]();

[Link]("Enter Shift Key:");


int shiftKey = [Link]();

// Use StringBuilder for efficient string concatenation


StringBuilder cipherText = new StringBuilder();

// Normalize the shift key to be in the range 0-25


int effectiveShift = shiftKey % 26;
if (effectiveShift < 0) {
effectiveShift += 26; // Handle negative shifts
}

// Iterate through each character of the message


for (int i = 0; i < [Link](); i++) {
char ch = [Link](i);

// Check if the character is an uppercase letter


if (ch >= 'A' && ch <= 'Z') {
// Apply the shift, wrap around using modulo 26
char newChar = (char)('A' + (ch - 'A' +
effectiveShift) % 26);
[Link](newChar);
}
// Check if the character is a lowercase letter
else if (ch >= 'a' && ch <= 'm') {
// Apply the shift, wrap around using modulo 26
char newChar = (char)('a' + (ch - 'a' +
effectiveShift) % 26);
[Link](newChar);
}
// If not a letter, append it unchanged [span_36]
(start_span)[span_36](end_span)
else {
[Link](ch);
}
}

[Link]("Ciphertext: " + [Link]());

[Link]();
}
}

Inputs & Outputs


Input/Output 1 (Sample Data ):
Enter the String for Encryption:
HELLO
Enter Shift Key:
3
Ciphertext: KHOOR

Input/Output 2 (Wrap-around Test):


Enter the String for Encryption:
ZEBRA
Enter Shift Key:
1
Ciphertext: AFCSB

Input/Output 3 (With Non-alphabetic ):


Enter the String for Encryption:
Encryption helps to secure data.
Enter Shift Key:
13
Ciphertext: Rapelcgvba urycf gb frpher qngn.

Input/Output 4 (Large Shift Key - should be same as 28 % 26 = 2):


Enter the String for Encryption:
Java
Enter Shift Key:
28
Ciphertext: Lcxc

Input/Output 5 (Negative Shift Key):


Enter the String for Encryption:
KHOOR
Enter Shift Key:
-3
Ciphertext: HELLO

2.8. Program 8: Factorial (using Recursion)


Problem Statement
Write a program to calculate the factorial of a non-negative integer n, entered by the user. The
solution must use a recursive method. The factorial of n (denoted n!) is the product of all
positive integers less than or equal to n. By definition, the factorial of 0 is 1 (0! = 1).
Source Code
import [Link];

/**
* ISC Program to find the factorial of a number using recursion.
* Uses 'long' to handle larger factorial values.
*/
public class RecursiveFactorial {

/**
* Recursive function to calculate factorial.
* @param n The number to calculate the factorial of.
* @return The factorial of n (n!).
*/
public static long factorial(long n) {
// Base Case: The condition that stops the recursion
if (n == 0 |

| n == 1) {
return 1; // 0! = 1 and 1! = 1
}
// Recursive Case: The function calls itself with a smaller
problem
else {
return n * factorial(n - 1); // e.g., 5 * factorial(4)
}
}

public static void main(String args) {


Scanner sc = new Scanner([Link]);
[Link]("Enter the number to find the factorial:");
int number = [Link]();

if (number < 0) {
[Link]("Factorial is not defined for negative
numbers.");
} else {
// Call the recursive method
long fact = factorial(number);
[Link]("Factorial of " + number + " is: " +
fact);
}

[Link]();
}
}

Inputs & Outputs


Input/Output 1 (Sample Data ):
Enter the number to find the factorial:
5
Factorial of 5 is: 120

Input/Output 2 (Base Case 0 ):


Enter the number to find the factorial:
0
Factorial of 0 is: 1
Input/Output 3 (Base Case 1 ):
Enter the number to find the factorial:
1
Factorial of 1 is: 1

Input/Output 4 (Sample Data ):


Enter the number to find the factorial:
8
Factorial of 8 is: 40320

Input/Output 5 (Test long data type ):


Enter the number to find the factorial:
20
Factorial of 20 is: 2432902008176640000

2.9. Program 9: Palindrome Number (using Recursion)


Problem Statement
Write a program to accept an integer num. The program must check if the number is a
Palindrome (reads the same forwards and backwards, e.g., 121) by using a recursive
technique to find the reverse of the number. It should then display an appropriate message.
Source Code
import [Link];

/**
* ISC Program to check if a number is a Palindrome
* using a recursive method to reverse the number.
*/
public class RecursivePalindrome {

/**
* Recursive function to reverse a number.
* It uses an 'accumulator' parameter 'rev' to build the reversed
number.
* @param n The remaining part of the number to be reversed.
* @param rev The reversed number built so far (accumulator).
* @return The fully reversed number.
*/
public static int reverse(int n, int rev) {
// Base Case: When the number is reduced to 0,
// the accumulator 'rev' holds the complete reversed number.
if (n == 0) {
return rev;
}

// Recursive Case:
// 1. Get the last digit of n
int last_digit = n % 10;
// 2. Add this digit to the end of 'rev'
int new_rev = (rev * 10) + last_digit;
// 3. Call itself with the 'n' (last digit removed) and the
new 'rev'
return reverse(n / 10, new_rev);
}

public static void main(String args) {


Scanner in = new Scanner([Link]);
[Link]("Enter the number:");
int num = [Link]();

if (num < 0) {
[Link]("Not a Palindrome (negative number).");
return;
}

// Call the recursive function


// The initial accumulator value is 0
int rev = reverse(num, 0);

[Link]("Reverse of n = " + rev);

// Check for Palindrome


if (num == rev) {
[Link]("Palindrome = Yes");
} else {
[Link]("Palindrome = No");
}

[Link]();
}
}

Inputs & Outputs


Input/Output 1 (Palindrome ):
Enter the number:
121
Reverse of n = 121
Palindrome = Yes

Input/Output 2 (Not Palindrome):


Enter the number:
123
Reverse of n = 321
Palindrome = No

Input/Output 3 (Large Palindrome ):


Enter the number:
123454321
Reverse of n = 123454321
Palindrome = Yes
Input/Output 4 (Single Digit):
Enter the number:
7
Reverse of n = 7
Palindrome = Yes

Input/Output 5 (Even Digits, Not Palindrome):


Enter the number:
1234
Reverse of n = 4321
Palindrome = No

2.10. Program 10: Simple Inheritance Demonstration


Problem Statement
This program demonstrates the core OOP concept of Inheritance. Create a superclass Person
with private instance variables name (String) and age (int), a parameterized constructor, and a
display() method. Create a subclass Student that extends Person. The Student class should
have its own private instance variables course (String) and marks (int). It must have a
parameterized constructor that uses the super() keyword to initialize the Person members. It
must also override the display() method to print all four details (name, age, course, and marks).
Write a main method in a separate driver class to create an object of the Student class, initialize
it, and call its display() method.
Source Code
/**
* File: [Link]
* The superclass (parent class) that defines a Person.
*/
class Person {
// Private data members
private String name;
private int age;

// Parameterized constructor for the Person class


public Person(String name, int age) {
[Link] = name;
[Link] = age;
}

// Display method for the Person class


public void display() {
[Link]("Name: " + name);
[Link]("Age: " + age);
}
}

/**
* File: [Link]
* The subclass (child class) that inherits from Person.
*/
class Student extends Person {
// Additional private data members for the Student class
private String course;
private int marks;

// Parameterized constructor for the Student class


public Student(String name, int age, String course, int marks) {
// Call the superclass (Person) constructor using super()
// This MUST be the first line of the constructor [span_51]
(start_span)[span_51](end_span)
super(name, age);

// Initialize its own members


[Link] = course;
[Link] = marks;
}

/**
* Overridden display method.
* It extends the functionality of the superclass's display
method.
*/
@Override
public void display() {
// Call the superclass's display method to print name and age
[span_53](start_span)[span_53](end_span)
[Link]();

// Print its own details


[Link]("Course: " + course);
[Link]("Marks: " + marks);
}
}

/**
* File: [Link]
* The main class to create objects and test the inheritance.
*/
public class SchoolDriver {
public static void main(String args) {
// --- Input/Output 1 ---
[Link]("--- Student 1 ---");
Student s1 = new Student("Rohan Sharma", 17, "Computer
Science", 95);
[Link](); // This calls the overridden display() in
Student

// --- Input/Output 2 ---


[Link]("\n--- Student 2 ---");
Student s2 = new Student("Priya Singh", 18, "Commerce", 88);
[Link]();
// --- Input/Output 3 ---
[Link]("\n--- Student 3 ---");
Student s3 = new Student("Arjun Mehta", 17, "Humanities", 91);
[Link]();

// --- Input/Output 4 ---


[Link]("\n--- Student 4 ---");
Student s4 = new Student("Aisha Khan", 18, "Science", 98);
[Link]();

// --- Input/Output 5 ---


[Link]("\n--- Student 5 ---");
Student s5 = new Student("Vikram Rao", 16, "Computer Science",
74);
[Link]();
}
}

Inputs & Outputs


This program is not interactive. The inputs are hard-coded in the main method of the
SchoolDriver class. The output is the console printout from executing the main method.
--- Student 1 ---
Name: Rohan Sharma
Age: 17
Course: Computer Science
Marks: 95

--- Student 2 ---


Name: Priya Singh
Age: 18
Course: Commerce
Marks: 88

--- Student 3 ---


Name: Arjun Mehta
Age: 17
Course: Humanities
Marks: 91

--- Student 4 ---


Name: Aisha Khan
Age: 18
Course: Science
Marks: 98

--- Student 5 ---


Name: Vikram Rao
Age: 16
Course: Computer Science
Marks: 74
3. Project Conclusion
This project file successfully demonstrates the design, implementation, and documentation of 10
core Java programs, each chosen to cover a key area of the ISC Class 12 Computer Science
syllabus. The practical experience gained from this work reinforces the theoretical concepts
learned in the classroom.
Through this collection, the following topics were implemented:
● Core Java Concepts: Use of loops, conditionals, user input (Scanner), and data types for
problem-solving (e.g., Prime Number, Armstrong Number).
● String Manipulation: Programs for checking a String Palindrome, counting
vowels/consonants, and implementing a Caesar Cipher provided experience in character-
level operations.
● Array Handling: The "Sum and Average of a 1D Array" program demonstrated basic
array traversal and aggregation.
● Recursive Algorithms: The Factorial and Palindrome Number programs illustrated the
power of recursion, requiring a clear definition of a "base case" and a "recursive case" to
solve problems elegantly.
● Object-Oriented Programming (OOP): The Inheritance program modeled a real-world
relationship, demonstrating the use of extends, super(), and method overriding, which are
foundational pillars of OOP.

Common questions

Powered by AI

An Armstrong number for a given number of digits is an integer such that the sum of its digits each raised to the power of the number of digits equals the number itself. To determine if a number is an Armstrong number in Java, you can: 1) Calculate the number of digits 'n' in the input number. 2) Iterate through each digit of the number, using modulus and division operations to extract digits. 3) Compute the power of each digit raised to 'n', adding this value to a sum. 4) Compare the sum to the original number. If they are equal, the number is an Armstrong number .

Challenges in implementing a Caesar Cipher text encryption in Java include handling character wrapping for letters at the end of the alphabet, maintaining case sensitivity, and avoiding encrypted output of non-alphabetic symbols wrongfully shifted. These can be addressed by: 1) Using modular arithmetic to wrap around 'z' to 'a'. 2) Retaining the case of input characters in output. 3) Checking if a character is alphabetical before shifting and encoding. Such precautions ensure a robust encryption process matching conventional Caesar Cipher rules .

To ensure a case-insensitive comparison when checking for a palindrome in Java, you can convert the string to either lower-case or upper-case using the built-in methods `toLowerCase()` or `toUpperCase()`. This conversion should be performed before comparison, ensuring the case is normalized. Then, compare characters from the start and end moving towards the center to check if they are the same. This technique helps in accurately identifying palindromes regardless of the text's case .

A project-based approach is pedagogically effective for ISC Class 12 students learning core Java concepts as it integrates theoretical knowledge with practical applications. This method enhances learning by allowing students to explore programming fundamentals in real-world contexts, fostering deeper understanding. Projects like designing multiple Java programs, as specified for the ISC syllabus, require learners to actively engage with concepts such as loops, conditionals, recursion, and OOP. Consequently, students develop high-order cognitive skills, including critical thinking, problem-solving, and design proficiency pertaining to Java fundamentals .

A Java program can utilize loops and conditionals by first converting the input string to lower-case to simplify vowel checking. Then, iterate through each character, using conditionals to check if it is a vowel by comparing it against known vowels ('a', 'e', 'i', 'o', 'u'). For consonants, check if the character is a non-vowel alphabetic character. Count vowels and consonants using separate counters while ignoring non-alphabetic characters. This approach efficiently utilizes loops and conditional checks to differentiate and count vowels and consonants .

In OOP, method overriding is significant as it allows a subclass to provide a specific implementation of a method already defined in its superclass. This facilitates polymorphism, enabling different behaviors for methods on objects based on their class types. For example, in a Java program where `Person` is a base class with a `display()` method, and `Student` is a subclass, `Student` can override `display()` to include additional details specific to `Student` (course, marks). This showcases how method overriding enables a subclass to refine or extend behaviors of its parent class .

Java handles user input to initialize an integer array using the `Scanner` class. First, you prompt the user for the size of the array. Then, you allocate the array based on this size. For each element index, the program accepts a user input to populate the array. To calculate the sum of elements, it iterates through the array, accumulating the sum in a variable. The average is derived by dividing the total sum by the number of elements (array size). Checking for a valid array size (non-zero) is critical to avoid division by zero or empty array operations .

The 'super()' keyword in Java is used in the context of inheritance to call the constructor of the superclass from the subclass. This is essential to ensure that the super class is fully constructed before methods and fields of the subclass can be accessed. For example, in a program with a base class 'Person' and a derived class 'Student', the 'Student' constructor uses 'super(name, age)' to invoke the 'Person' constructor to initialize inherited fields. This practice ensures the proper initialization of object states in an inheritance hierarchy .

To process an integer for unique digits within a range in Java, iterate through each number in the specified range using a loop. For each number, utilize a boolean array to track encountered digits. Extract each digit using modulus and division operations. If a digit repeats (flagged in the boolean array), the number is not unique. If the loop completes without repetition, the number has all unique digits. This approach leverages efficient memory use, as boolean arrays easily track digits without complex structures .

A recursive function in Java computes the factorial of a number by defining a base case and a recursive case. The base case returns a value for a simple instance of the problem (e.g., factorial of 0 is 1). The recursive case considers the factorial of 'n' as 'n' multiplied by the factorial of 'n-1'. The function continues to call itself with decremented values until it reaches the base case, allowing the calculation to resolve. The significance of these cases is to ensure that the recursion progresses towards a solution and terminates when complete .

You might also like