[go: up one dir, main page]

0% found this document useful (0 votes)
8 views44 pages

Computer Applications - Class 10 ICSE Boards Project

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
0% found this document useful (0 votes)
8 views44 pages

Computer Applications - Class 10 ICSE Boards Project

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
You are on page 1/ 44

ICSE

COMPUTER PROJECT
2024-2025

NAME: Naman Kumar

CLASS: 10 SECTION: C

CLASS ROLL NUMBER: 20


INDEX.

Q1 ) Write a program to accept a String and print the number of digits,


alphabets and special characters in the string.
Q2) Write a program to calculate the factorial of a number input by the
user.
Q3 ) Write a program to input a number and check and print whether
it is a Pronic number or not.
Q4) Write a program to input a string from the user and print its
palindrome
Q5)Design a class to overload a function area( ) {according to the
instructions given)
Q6) Write a program to calculate the sum of all elements in a 2D array.
Q7) Design a class name ShowRoom (constructor program- according
to the instructions given there)
Q8) Write a program to input twenty names in an array. Arrange these
names in descending order of letters, using the bubble sort technique.
Q9 ) Write a program in Java to accept a string in lower case and
change the first letter of every word to upper case. Display the new
string.
Q10) Using switch statement, write a menu driven program(according
to the instructions given there)
Q11) Write a program to accept a number and check and display
whether it is a Niven number or not.
Q12) Design a class with the following specifications:(constructor
porgram with class name Student)
Q13) Define a class to accept a string, and print the characters with the
uppercase and lowercase reversed, but all the other characters should
remain the same as before.
Q14) Design a class to overload a function series( ) (Function
overloading to print different series)
Q15) Write a program to input a sentence and convert it into uppercase
and count and display the total number of words starting with a letter
'A'.
Q1 ) Write a program to accept a String and print the number of
digits, alphabets and special characters in the string.
Example:
S = "abcd!@123”

Output:
Number of digits – 3
Number of letters – 4
Number of Special characters – 2

import java.util.Scanner;
public class Count
{ // class begins
public static void main(String args[])
{ //main method begins

Scanner ab = new Scanner(System.in);

System.out.println("Enter a string:");
String str = ab.nextLine(); // Entering the string

int a= 0;
int sc = 0;
int d = 0;

for (int i = 0; i < str.length; i++)


{ // for loop begins
Char ch = str.charAt(i);
if (Character.isLetter(ch)
a++; // adding 1 to the number of alphabets if the character is
a letter

else if (Character.isDigit(ch))
d++; // adding 1 to the number of digits if the character is a
digit

else
sc++; // adding 1 to the number of special character if the
character is a special character(not a letter or a number)

} // loop ends

// printing the values


System.out.println("No. of Digits = " + d);
System.out.println("No. of Alphabets = " + a);
System.out.println("No. of Special Characters = " + sc);

} // closing main method


} // closing class
Variable Description Table:

Variable Type Description


ab Scanner Used to take input from the user.
str String Used to imput a string
Stores the number of alphabets or letters in
a int
the string.
Stores the number of special characters in
sc int
the string.
d int Stores the number of digits in the string.
Loop variable used to iterate through the
i int
series.
To extract the characters of the string one by
ch Character
one
Q2) Write a program to calculate the factorial of a number
input by the user.

import java.util.Scanner;
public class FactorialCalculator
{ // class begins
public static void main(String[] args)
{ // main method begins
Scanner sc = new Scanner(System.in);

// Input the number from the user


System.out.print("Enter a number: ");
int num = sc.nextInt();

long f = 1; // Initialize factorial as 1

// Calculating factorial using a loop


for (int i = 1; i <= num; i++) {
f=f* i; // Multiply each number from 1 to the input number
}

// Displaying the result


System.out.println("The factorial of " + num + " is: " + f);
}// closing main method
} // closing class

Variable Description Table:


Variable Type Description
sc Scanner Used to take input from the user.
num int Stores the number for which the factorial is calculated.
f long Stores the calculated factorial value.
i int Loop variable used to iterate from 1 to the input number.
Q3 ) Write a program to input a number and check and
print whether it is a Pronic number or not. (Pronic number
is the number which is the product of two consecutive
integers)

import java.util.Scanner;

public class PronicNumber


{// class begins
public static void main(String args[])
{ // main method begins
int num=0;
Scanner sc = new Scanner(System.in);

// asking the user to enter the number to be checked


System.out.print("Enter the number to check: ");
num = sc.nextInt();

boolean isPronic = false; // initializing boolean variable isPronic


with false and changing it to true if the number is a Pronic number

for (int i = 1; i <= num - 1; i++)


{ // for loop begins
if (i * (i + 1) == num)
{
isPronic = true;
break;
}
} // for loop ends

if (isPronic)
System.out.println(num + " is a pronic number");
else
System.out.println(num + " is not a pronic number");
} // closing main method
} //closing class

Variable Description Table:


Variable Type Description
sc Scanner Used to take input from the user.
num int Asks the user to enter the number.
Helps to check whether the number is a Pronic Number or
isPronic boolean
not.
i int Loop variable used to traverse the array.
Q4) Write a program to input a string from the user and print its
palindrome

import java.util.Scanner;

public class StringReverse


{ //class begins
public static void main(String[] args)
{ // main method begins
Scanner sc = new Scanner(System.in);

// Asking the user to Input the string


System.out.print("Enter a string: ");
String str= sc.nextLine();

// Initializing a variable to store the reversed string


String r= "";

// Reverse the string using a loop


for (int i = 0;i<str.length();i++)
{ // for loop begins
Char ch= str.charAt(i);
r=ch+r // Add each character in reverse order
} // for loop ends
// Display the reversed string
System.out.println("The palindrome of the string is: " + r);

} // closing main method


} // closing class

Variable Description Table:


Variable Type Description
sc Scanner Used to take input from the user.
str String Stores the original string entered by the user.

r String Stores the reversed version of the input string.

i int Loop variable used to traverse the string in reverse.

ch char Extract a character from the string

Q5)Design a class to overload a function area( ) as follows:


1. double area (double a, double b, double c) with three double
arguments, returns the area of a scalene triangle using the
formula:
area = √(s(s-a)(s-b)(s-c))
where s = (a+b+c) / 2
2. double area (int a, int b, int height) with three integer
arguments, returns the area of a trapezium using the formula:
area = (1/2)height(a + b)
3. double area (double diagonal1, double diagonal2) with two
double arguments, returns the area of a rhombus using the
formula:
area = 1/2(diagonal1 x diagonal2)

import java.util.Scanner;

public class Overloading


{ // class begins

// Method to calculate area of a triangle using three sides


double area(double a, double b, double c) {
double s = (a + b + c) / 2; // Semi-perimeter calculation
double x = s * (s - a) * (s - b) * (s - c); // Heron's formula
double area = Math.sqrt(x); // Square root to get the area
return area; // Return the area
}
// Method to calculate area of a trapezium
double area(int a, int b, int h) {
double area = (1.0 / 2.0) * h * (a + b); // Area formula for trapezium
return area; // Return the area
}

// Method to calculate area of a rhombus


double area(double d1, double d2) {
double area = 1.0 / 2.0 * d1 * d2; // Area formula for rhombus
return area; // Return the area
}
}

Variable Description Table:


Variable Type Description
a double Length of side 1 (for triangle)
b double Length of side 2 (for triangle).
c double Length of side 3 (for triangle)
s double Semi-perimeter of the triangle.
x double Intermediate result for area calculation
area double Final result of area calculation
h double Height of the trapezium
d1 double Diagonal 1 of the rhombus
d2 double Diagonal 2 of the rhombus
Variable Type Description

Q6) Write a program to calculate the sum of all elements in a 2D


array.
import java.util.*;
public class Array_sum2D { // class begins
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Input the number of rows and columns


System.out.print("Enter the number of rows: ");
int row = sc.nextInt();
System.out.print("Enter the number of columns: ");
int col = sc.nextInt();

// Declare and input elements for the 2D array


int[][] arr = new int[row][col];
System.out.println("Enter the elements of the 2D array:");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
arr[i][j] = sc.nextInt(); // Reading each element into the array
}
}

// Calculate the sum of all elements in the array


int sum = 0;
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
sum += arr[i][j]; // Add each element to the sum
}
}

// Display the sum of all elements


System.out.println("The sum of all elements in the 2D array is: " +
sum);
}
}

Variable Description Table:


Variable Type Description
sc Scanner Used to take input from the user.
row int Stores the number of rows in the 2D array.
col int Stores the number of columns in the 2D array.
arr int[][] Stores the elements of the 2D array.
sum int Holds the sum of all the elements in the 2D array.
Loop variables used to traverse through the rows and
i, j int
columns of the 2D array.

Q7)
Design a class name ShowRoom with the following description:
Instance variables / Data members:
String name — To store the name of the customer
long mobno — To store the mobile number of the customer
double cost — To store the cost of the items purchased
double dis — To store the discount amount
double amount — To store the amount to be paid after discount
Member methods:
ShowRoom() — default constructor to initialize data members
void input() — To input customer name, mobile number, cost
void calculate() — To calculate discount on the cost of purchased
items, based on following criteria

Cost Discount (in percentage)

Less than or equal to ₹10000 5%

More than ₹10000 and less than or equal to


10%
₹20000

More than ₹20000 and less than or equal to


15%
₹35000

More than ₹35000 20%

void display() — To display customer name, mobile number, amount


to be paid after discount.
Write a main method to create an object of the class and call the
above member methods.
import java.util.Scanner;

public class ShowRoom { // class begins


String name;
long mobno;
double cost;
double dis;
double amount;

// Constructor to initialize variables


public ShowRoom() {
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}

// Method to input customer details


public void input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter customer name: ");
name = sc.nextLine(); // Get customer name
System.out.print("Enter customer mobile no: ");
mobno = sc.nextLong(); // Get customer mobile number
System.out.print("Enter cost: ");
cost = sc.nextDouble(); // Get product cost
}

// Method to calculate discount and final amount


public void calculate() {
int disPercent = 0;
if (cost <= 10000)
disPercent = 5;
else if (cost <= 20000)
disPercent = 10;
else if (cost <= 35000)
disPercent = 15;
else
disPercent = 20;

dis = cost * disPercent / 100.0; // Calculate discount


amount = cost - dis; // Final amount after discount
}

// Method to display customer and product details


public void display() {
System.out.println("Customer Name: " + name);
System.out.println("Mobile Number: " + mobno);
System.out.println("Amount after discount: " + amount); // Display
final amount
}

public static void main(String args[]) {


ShowRoom obj = new ShowRoom();
obj.input(); // Call input method
obj.calculate(); // Call calculate method
obj.display(); // Call display method
}
}

Variable Description Table:

Variable Type Description


sc Scanner Used to take input from the user.

name String To store the name of the customer

mobno long To store the mobile number of the customer

cost double To store the cost of the items purchased

dis double To store the discount amount

dispercent double To store the discount percentage


Q8) Write a program to input twenty names in an array. Arrange
these names in descending order of letters, using the bubble sort
technique.

import java.util.Scanner;
public class Bubblesort_descending
{ // class begins
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String names[] = new String[20];
System.out.println("Enter 20 names:");
for (int i = 0; i < names.length; i++) {
names[i] = sc.nextLine(); // Read each name into the array
}

// Bubble Sort to arrange names in descending order


for (int i = 0; i < names.length - 1; i++) {
for (int j = 0; j < names.length - 1 - i; j++) {
if (names[j].compareToIgnoreCase(names[j + 1]) < 0) { //
Compare and swap names
String t = names[j + 1];
names[j + 1] = names[j];
names[j] = t;
}
}
}

// Display sorted names


System.out.println("\nSorted Names");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i]); // Print each sorted name
}
}
}

Variable Description Table:


Variable Type Description
sc Scanner Used to take input from the user.
names String[] Array of names
t String Temporary variable for swapping names.
Loop variables for performing the sorting and to inpt the
i,j boolean
values in the array

Q9 ) Write a program in Java to accept a string in lower case and


change the first letter of every word to upper case. Display the new
string.
Sample input: we are in cyber world
Sample output: We Are In Cyber World
import java.util.Scanner;

public class Uppercase_Initials { // class begins


public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence:");
String sent = sc.nextLine(); // Input sentence
String w = "";

// Convert first letter of each word to uppercase


for (int i = 0; i < sent.length(); i++) {
if (i == 0 || sent.charAt(i - 1) == ' ') {
w = w + Character.toUpperCase(sent.charAt(i)); // Capitalize
first letter
} else {
w += sent.charAt(i); // Add the rest of the characters as they
are
}
}

// Display the modified sentence


System.out.println(w);
}
}
Variable Description Table:
Variable Type Description
sc Scanner Used to take input from the user.
sent String Stores the sentence entered by the user
w String Stores the words with the initial as capitals
Loop variable used to traverse through each character of the
i int
string.

Q10) Using switch statement, write a menu driven program for the
following:

1. To find and display the sum of the series given below:


S = x1 - x2 + x3 - x4 + x5 .......... - x20
(where x = 2)
2. To display the following series:
1 11 111 1111 11111
For an incorrect option, an appropriate error message should be
displayed.

import java.util.Scanner;

public class Series_Switchcase


{ // class begins
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
System.out.println("1. Sum of the series");
System.out.println("2. Display series");
System.out.print("Enter your choice: ");
int choice = sc.nextInt(); // Read user choice

switch (choice) {
case 1:
int sum = 0;
for (int i = 1; i <= 20; i++) {
int x = 2;
int term = (int)Math.pow(x, i); // Calculate the term
if (i % 2 == 0)
sum -= term; // Subtract if index is even
else
sum += term; // Add if index is odd
}
System.out.println("Sum=" + sum); // Display the sum
break;

case 2:
int term = 1;
for (int i = 1; i <= 5; i++) {
System.out.print(term + " "); // Print the series
term = term * 10 + 1; // Update the term (for series like 1, 11,
111, ...)
}
break;

default:
System.out.println("Incorrect Choice"); // Handle incorrect choice
break;
}
}
}

Variable Distribution Table:


Variable Type Purpose
choice int User's choice for series calculation
sum int Sum of the series in case 1.
Variable Type Purpose
term int Individual term of the series in case 2
x Int Base for series calculation
i int Loop Variable
sc Scanner Used to take input from the user.

Q11) Write a program to accept a number and check and display


whether it is a Niven number or not.
(Niven number is that number which is divisible by its sum of
digits.).
Example:
Consider the number 126. Sum of its digits is 1 + 2 + 6 = 9 and 126
is divisible by 9.

import java.util.Scanner;

public class NivenNumber


{ // class begins
public void checkNiven()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter number: ");
int num = sc.nextInt(); // Read the number
int copy = num; // Store the original number

int sum = 0;

// Calculate the sum of digits


while (copy != 0) {
int d = copy % 10; // Get the last digit
copy /= 10; // Remove the last digit
sum += d; // Add the digit to the sum
}

// Check if the number is divisible by the sum of its digits


if (num % copy == 0)
System.out.println(num + " is a Niven number");
else
System.out.println(num + " is not a Niven number");
}

public static void main(String args[])


{
NivenNumber obj = new NivenNumber();
obj.checkNiven(); // Call the method to check if the number is a
Niven number
}
}

Variable Distribution Table:


Variable Type Purpose
sc Scanner To take input from the user.
num int Input number from the user
Copy of the orignal number to perform
copy int
the calculations
sum int Sum of the digits of the number
d int Individual digit of the number
obj NivenNumber Instance of the NivenNumber class
Q12) Design a class with the following specifications:
Class name: Student
Member variables:
name — name of student
age — age of student
mks — marks obtained
stream — stream allocated
(Declare the variables using appropriate data types)
Member methods:
void accept() — Accept name, age and marks using methods of
Scanner class.
void allocation() — Allocate the stream as per following criteria:

mks stream

>= 300 Science and Computer

>= 200 and < 300 Commerce and Computer

>= 75 and < 200 Arts and Animation

< 75 Try Again

void print() – Display student name, age, mks and stream allocated.
Call all the above methods in main method using an object.

import java.util.Scanner;

public class Student { // class begins

// Declaring instance variables


String name;
int age;
double mks;
String stream;

// Method to accept user input for student details


public void accept() {
Scanner in = new Scanner(System.in);

// Taking student name as input


System.out.print("Enter student name: ");
name = in.nextLine();

// Taking student age as input


System.out.print("Enter age: ");
age = in.nextInt();

// Taking student marks as input


System.out.print("Enter marks: ");
mks = in.nextDouble();
}

// Method to allocate stream based on marks


public void allocation() {
// Allocating stream based on the marks obtained
if (mks < 75)
stream = "Try again"; // Marks less than 75: try again
else if (mks < 200)
stream = "Arts and Animation"; // Marks between 75 and 200:
Arts and Animation
else if (mks < 300)
stream = "Commerce and Computer"; // Marks between 200 and
300: Commerce and Computer
else
stream = "Science and Computer"; // Marks above 300: Science
and Computer
}

// Method to display the student's details


public void print() {
System.out.println("Name: " + name); // Printing name
System.out.println("Age: " + age); // Printing age
System.out.println("Marks: " + mks); // Printing marks
System.out.println("Stream allocated: " + stream); // Printing allocated
stream
}

// Main method to create an object and test the methods


public static void main(String args[]) {
Student obj = new Student(); // Creating a Student object
obj.accept(); // Calling accept method to take input
obj.allocation(); // Calling allocation method to allocate stream
obj.print(); // Calling print method to display the details
}
}

Variable Distribution Table:


Variable Type Purpose
in Scanner To take input from the user.
name String Stores the student's name
age int Stores the student's age
mks double Stores the student's marks
stream String Stores the allocated stream
Instance of the Student class to access
obj Student
methods

Q13) Define a class to accept a string, and print the characters with
the uppercase and lowercase reversed, but all the other characters
should remain the same as before.
EXAMPLE:
INPUT : WelCoMe_2022
OUTPUT : wELcOmE_2022
import java.util.Scanner;

public class Case_Change { // class begins

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
System.out.println("Enter a string:");// Asking the user to input string

String str = in.nextLine();


String rev = ""; // String to store the result

for (int i = 0; i < str.length(); i++) {


char ch = str.charAt(i); // Getting the character at the current
index

// Switch case for letters


if (Character.isLetter(ch)) {
if (Character.isUpperCase(ch)) {
rev += Character.toLowerCase(ch);
}
else {
rev += Character.toUpperCase(ch);
}
}
else {
rev += ch; // Append non-letter characters as is
}
}

System.out.println(rev); // Print the modified string


}
}

Variable Distribution Table:


Variabl
Type Purpose
e
str String Stores the input string from the user
rev String Stores the result string after case change
ch char Stores the current character in the loop
in Scanner Scanner object to take input from the user

Q14) Design a class to overload a function series( ) as follows:

(a) void series (int x, int n) – To display the sum of the series given below:

x1 + x2 + x3 + .......... xn terms

(b) void series (int p) – To display the following series:

0, 7, 26, 63 .......... p terms


(c) void series () – To display the sum of the series given below:

1/2 + 1/3 + 1/4 + .......... 1/10

import java.util.*;

public class OverloadSeries

{ // class begins

// Method to calculate the sum of x raised to the power of i from 1 to


n
void series(int x, int n) {
long sum = 0;
for (int i = 1; i <= n; i++) {
sum += Math.pow(x, i); // Adding x^i to the sum
}
System.out.println("Sum = " + sum);
}

// Method to print the terms where each term is (i^3 - 1) for i from 1
to p
void series(int p) {
for (int i = 1; i <= p; i++) {
int term = (int)(Math.pow(i, 3) - 1); // (i^3 - 1)
System.out.print(term + " "); // Printing each term
}
System.out.println();
}

// Method to calculate the sum of the series 1/2 + 1/3 + ... + 1/10
void series() {
double sum = 0.0;
for (int i = 2; i <= 10; i++) {
sum += 1.0 / i; // Adding 1/i to the sum
}
System.out.println("Sum = " + sum);
}
}

Variable Distribution Table:


Variable Type Purpose
Stores the cumulative sum for the respective
sum long/double
series
The base number for calculating powers in the
x int
first method
n int The number of terms for the power series
p int The limit for the second method's series
Stores the value of each term in the second
term int
method
i int Loop counter for iterating through the series
Q15) Write a program to input a sentence and convert it into
uppercase and count and display the total number of words
starting with a letter 'A'.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF
INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with letter 'A' = 4
import java.util.Scanner;

public class Initials_A


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a string: ");
String sent = in.nextLine(); // Input string
sent = " " + sent; // Add leading space
int c = 0; // Counter for words starting with 'A'
sent = sent.toUpperCase(); // Convert to uppercase

// Check for words starting with 'A'


for (int i = 0; i < sent.length - 1; i++) {
if (str.charAt(i) == ' ' && str.charAt(i + 1) == 'A')
c++;
}

System.out.println("Total number of words starting with letter 'A' = " +


c);
}
}
Variable Distribution Table:
Variable Type Purpose
sent String Input sentence form the user
c int Counts words starting with 'A'
i int Loop Variable
in Scanner Reads input from user
THANK YOU

You might also like