Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

W. H.

Smith Memorial School


Year – 2023-2024

Name – Ayush Gupta


th
Class – 10

Section – B

Subject – Computer Applications

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


INDEX

TOPIC NO. NAME PAGE NO.

1. ASSIGNMENT I 1

2. ASSIGNMENT II 7

3. ASSIGNMENT III 10

4. ASSIGNMENT IV 14

5. ASSIGNMENT V 17

6. ASSIGNMENT VI 23

7. ASSIGNMENT VII 28

8. ASSIGNMENT VIII 32

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Number Problems/Menu Driven programs based on usage of
loops/switch

ASSIGNMENT I
Using the switch statement, write a menu driven program for the
following:
⦁To print the Floyd’s triangle [Given below]
1
23
456
7 8 9 10
11 12 13 14 15
⦁To display the following pattern based on value of n. For example
if n=5 then print,
54321
4321
321
21
1

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Synopsis-
In this Java program, the main method presents a
menu to the user with two options: printing Floyd's
Triangle or displaying the pattern. The user can
choose an option by entering the corresponding
choice number.
Based on the user's choice, the program executes
the respective code block inside the switch
statement. For option 1, the user will get a Floyd’s
Triangle as shown in the question. For option 2, the
user is prompted to enter the value of n for the
pattern, and the desired pattern will be displayed
according to the value of n.

Solution code :-

import java.util.*;
public class assg1
{
public static void main(String args[])
{

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Scanner sc = new Scanner(System.in);
System.out.println("Menu : ");
System.out.println("1:Print Floyd's Triangle");
System.out.println("2:To display a following pattern based on
the value of
n”);
System.out.println("Enter your choice");
int ch = sc.nextInt();
switch(ch)
{
case 1:
int term = 1;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(term++ + " ");
}
System.out.println();
}
break;
case 2:
System.out.println("Enter the value of n");
int n = sc.nextInt();

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


for(int a=n;a>=1;a--)
{
for(int b=a;b>=1;b--)
{
System.out.print(b+" ");
}
System.out.println( );
}
break;
default:
System.out.println("Invalid Input");
}
}
}

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Variable Description table -

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Output Screen-

Assignment II
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File
Write a program in Java to accept a number and check whether it
belongs to the Fibonacci Series (sequence) or not. Fibonacci
Series: The Fibonacci Sequence is the series of numbers: 0, 1, 1,
2, 3, 5, 8, 13, 21, 34, … The first two numbers in the series is ‘0’
and ‘1’ and every next number is found by adding up the two
numbers before it. The 2 is found by adding the two numbers
before it (1+1) Similarly, the 3 is found by adding the two
numbers before it (1+2), And the 5 is (2+3), and so on! Example:
the next number in the sequence above would be 21+34 = 55
Here is a longer list: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,
377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368,
75025, 121393, 196418, 317811, …

Synopsis-
We will declare one variable called inputNumber and store
the user entered number in it. We will declare firstTerm,
secondTerm and thirdTerm, where firstTerm and secondTerm
are the starting number of Fibonacci series. Now we will run
the loop and generate Fibonacci series until they are less
than the inputNumber. If the last generated number is equal
to the inputNumber then the given number belongs to the
Fibonacci series. Otherwise the given number does not
belong to the Fibonacci series.
Solution Code:

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


import java.util.Scanner;
public class assg2
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter positive number :");
int inputNumber = sc.nextInt();
int firstTerm = 0;
int secondTerm = 1;
int thirdTerm = 0;
while (thirdTerm < inputNumber)
{
thirdTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = thirdTerm;
}
if(thirdTerm == inputNumber)
{
System.out.println("Number belongs to Fibonacci series");
}
else
{
System.out.println("Number doesn't belongs to Fibonacci

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


series");
}
}
}

Variable Description Table –

Output Screen-

Assignment III
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File
The International Standard Book Number (ISBN) is a unique
numeric book identifier, which is printed on every book. The ISBN
is based upon a 10-digit code. The ISBN is legal if 1*digit1
+2*digit2 + 3*digit3 + 4*digit4 + 5*digit5 + 6*digit6 + 7*digit7 +
8*digit8 + 9*digit9 + 10*digit10 is divisible by 11.
Example: For an ISBN 1401601499 Sum=1*1 + 2*4 + 0*0 + 4*1 +
5*6 + 6*0 + 7*1 + 8*4 + 9*9 + 10*9 = 253 which is divisible by 11.
Write a program to:
(i) input the ISBN code as a 10-digit number
(ii) If the ISBN is not a 10-digit number, output the message
“Illegal ISBN” and terminate the program
(iii) If the number is 10-digit, extract the digits of the number and
compute the sum as explained above.
If the sum is divisible by 11, output the message “Legal ISBN”. If
the sum is not divisible by 11, output the message “Illegal ISBN”.

Synopsis

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


This program takes a 10-digit ISBN number from
the user. First the program checks the number of
digits in the given number. If the number of digit
is not equal to 10, then it an illegal ISBN number. If
the number of digit is equal to 10, the program
further checks the sum of the digits of the
number as explained in the question. If the sum is
divisible by 11, then it is a legal ISBN number.

Solution code:
import java.util.*;
public class assg3
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the ISBN: ");
long isbn = in.nextLong();
int sum = 0, count = 0, m = 10;
if (count != 10)
{
System.out.println("Illegal ISBN");
System.out.println("Program Terminates.");
System.exit(0);

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


}
else
{
while (isbn != 0)
{
int d = (int)(isbn % 10);
count++;
sum += d * m;
m--;
isbn /= 10;
}
if (sum % 11 == 0)
{
System.out.println("Legal ISBN");
}
else
{
System.out.println("Illegal ISBN");
}
}
}
}

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Variable description table –

Output Screen-

Assignment IV

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


An Emirp number is a number which is prime backwards and
forwards. Example: 13 is an Emirp number since 13 and 31 are
both prime numbers. Write a program to accept a number and
check whether it is an Emirp number or not.
Synopsis-
The program takes a number from the user and checks whether it
is a prime number forwards. Then the program runs a loop and
reverses the number.
The program again checks that the reversed number is a prime
number or not. If it is also a prime number then the original
number is a Emirp number otherwise it is not an Emirp number.

Solution Code :

import java.util.*;
class assg4
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int n = sc.nextInt();
int c=0,r=0,sum=0,q=0;
for(int i=1;i<=n;i++)

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


{
if(n%i==0)
c++;
}
if(c==2)
{
while(n>0)
{
r = n%10;
n = n/10;
sum = sum*10+r;
}
for(int j = 1;j<=sum;j++)
{
if(sum%j==0)
q++;
}
if(q==2)
System.out.println("The number is an Emirp number");
else
System.out.println("The number is not an Emirp number");
}
else
System.out.println("The number is not an Emirp Number");

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


}
Variable Description table –

Output screen-

Assignment V

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Write a menu driven program in Java to provide the following
options to generate and print output based on user’s choice:
(a) To input a number and check whether it is a NEON number or
not
(b) To print the REPUNIT series: 1, 11, 111, 1111, …. upto 'n'
terms
(c) To print the sum of factorial of first n terms, where n is input by
the user.
For example if n=5 then sum=1+2+6+24+120=153 which is the
sum of 1!+2!+3!+4!+5!
A number is said to be NEON, if sum of all the digits of the
square of the number is equal to the number itself. For example 9
is a NEON number. (Workings: Square of 9 = 81. Sum of digits of
square: 8 + 1 = 9)
For an incorrect menu choice an appropriate error message
should be displayed.

Synopsis -

The program gives the user a menu in which there are three
options. If the user chooses option (a), the he will give a number
as input to check whether it is a NEON number or not. The
program runs a loop and checks the conditions to be that
number
a NEON number. If the user chooses option (b), he will get the
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File
REPUNIT series till ‘n’ terms he desires. The program runs a loop
and generates the REPUNIT series till ‘n’ terms. If the user
chooses option (c), he will get the sum of factorial till the terms
he
desires. The program runs a nested loop and calculate the sum
of
factorial till ‘n’ terms.

Solution Code :

import java.util.*;
class assg5
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Menu :");
System.out.println("(a): To input a number and check
whether it is a NEON number or not");
System.out.println("(b): To print the REPUNIT series: 1, 11,
111, 1111, …. upto 'n' terms");
System.out.println("(c): To print the sum of factorial of first n
terms.");
System.out.println("Enter your choice :");
char ch = sc.next().charAt(0);

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


switch (ch)
{
case 'a':
System.out.println("Enter a number:");
int n = sc.nextInt();
int temp=0, sq=0, r=0, sum=0;
sq = n*n;
temp = sq;
while(sq>0)
{
r = sq%10;
sq = sq/10;
sum = sum+r;
}
if(sum==n)
System.out.println("It is a NEON number");
else
System.out.println("It is not a NEON number");
break;
case 'b':
System.out.println("Enter the number of terms :");
int t = sc.nextInt();
int s=0;
for(int i = 1;i<=t;i++)

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


{
s = s*10+1;
System.out.print(s+", ");
}
break;
case 'c':
System.out.println("Enter the number of terms :");
int x = sc.nextInt();
long sumf = 0;
for(int h = 0;h<=x;h++)
{
long f = 1;
for(int j = 1;j<=h;j++)
{
f*=j;
}
sumf = sumf+f;
}
System.out.println("Sum of factorial till n terms -
"+sumf);
break;
default:
System.out.println("Invalid Input!")
}

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


}
}
Variable Description table-

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Output screen-

Assignment VI
A Credit card company allows a limit to spend Rs. 15000 to its clients.
It also offers
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File
cash back
facility according the table shown below. Input the amount spent by
the user and
display the cash back amount that he is entitled to.
Amount (in Rs.) Cash Back (in Rs.)
First 1000 100
Next 2000 200 + 2% of amount exceeding 1000
Next 4000 400 + 4% of amount exceeding 3000
Next 8000 800 + 8% of amount exceeding 8000
Write a program to declare the class 'Credit' that takes in the name of
the client and
the
amount spend by him. Calculate the cash back amount and print it
along with all the
other
input details.
(Assume there are 20 clients. Take details and print the requisite
output for each of
them one by one.)

Synopsis:

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


This Java program models a credit card company's cash back
calculation system for its clients. It defines a class named 'Credit'
that takes the client's name and the amount they spent as input.
The program then calculates the cash back amount for each
client based on predefined criteria and displays the client's
name, amount spent, and cash back amount.

The program uses conditional statements to determine the cash


back based on different spending ranges and percentages. It
provides a structured and efficient way to calculate and display
cash back amounts for multiple clients, making it suitable for
managing the cash back system of the credit card company.

Solution Code:
import java.util.Scanner;

public class assg6


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
String names[] = new String[20];
double amounts[] = new double[20];

for (int i = 0; i < 20; i++) {


System.out.print("Enter client " + (i+1) + " name: ");
names[i] = in.nextLine();
System.out.print("Enter amount: ");
amounts[i] = in.nextInt();
in.nextLine(); //To empty input buffer
}

for (int i = 0; i < 20; i++) {

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


double cb = 0;
double amt = amounts[i];
System.out.println("Name: " + names[i]);
System.out.println("Amount: " + amounts[i]);
if (amt <= 1000)
cb = 100;
else if (amt <= 3000)
cb = 200 + (2 * (amt - 1000) / 100);
else if (amt <= 7000)
cb = 400 + (4 * (amt - 3000) / 100);
else if (amt <= 15000)
cb = 800 + (8 * (amt - 8000) / 100);
else
cb = -1;

if (cb == -1) {
System.out.println("Amount exceeds credit limit of 15000");
}
else {
System.out.println("Cash Back: " + cb);
}
}

}
}

Variable description table-

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Output Screen –

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Assignment VII
An electronic shop has announced the following seasonal
discount on purchase of certain items.
Purchase Amount in Rs Discount on Laptop Discount on
Desktop PC
0-25000 0.0% 5.0%
25001 – 50000 5.0% 7.5%
50001 – 100000 7.5% 10.0%
More than 100000 10.0% 15.0%
Write a program based on the above criteria to input name,
address, amount of purchase, and type of purchase (L or 1 for
Laptop and D or 2 for Desktop) by a customer. Compute and print
the net amount to be paid the customer along with name and
address. [Hint : discount= (discount rate /100) * amount of
purchase Net amount= amount of purchase – discount]

Synopsis-

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


The program takes the name and address of the user as his
details. Then the program takes the amount of purchase that user
did. Then it asks the type of purchase from the user , that
whether
it is for laptop or for desktop pc. Then it calculates the rate of
discount allotted according to the amount of purchase. Then
finally it calculates the net amount that user has to pay.

Solution Code:

import java.util.*;
class assg7
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String name = " ";
String add = " ";
System.out.print("Enter your name :");
name = in.nextLine();
System.out.print("Enter your address :");
add = in.nextLine();
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File
System.out.print("Enter Amount of Purchase: ");
double amt = in.nextDouble();
System.out.println("Enter Type of Purchase");
System.out.print("'L'- Laptop or 'D'- Desktop: ");
char type = in.next().charAt(0);
double disc = 0.0;
if (amt <= 25000)
disc = (type == 'L' )? 0.0 : 5.0; //using ternary operator
else if (amt>25000 && amt<= 50000)
disc = (type == 'L' )? 5.0 : 7.0;
else if (amt>50000 && amt <= 100000)
disc = (type == 'L' )? 7.5 : 10.0;
else
disc = (type == 'L' )? 10.0 : 15.0;
double netAmt = amt - ((disc/100) * amt);
System.out.println("Name : "+name);
System.out.println("Address : "+add);
System.out.println("Net Amount: " + netAmt);
}
}

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Variable Description table –

Output screen-

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Assignment VIII
Mr. A. P. Singh is a software engineer. He pays annual income tax
as per the given table:
Annual Salary Rate at Income Tax
Up to Rs.1 ,00,000 No Tax
Rs.1 ,00,001 to Rs.1 ,50,000 10% of the amount
exceeding
Rs.1,00,000
Rs.1,50,001 to Rs.2,50,000 Rs.5000 + 20% of
the amount
exceeding Rs.1,50,000
Above Rs.2,50,000 Rs.25,000 + 30% of
the amount
exceeding Rs.2,50,000
Write a program in Java to compute the income tax to be
paid by him.

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Synopsis-
Firstly, the program takes the annual salary of A.P.Singh as
input.
Then it calculates the income tax to be paid by A.P.Singh. It then
finally displays the amount of income tax to be paid.

Solution Code:
import java.util.*;
class assg8
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Mr.A.P.Singh's annual salary : ");
double as = sc.nextDouble();
double it = 0.0;
if(as<=100000)
it = 0;
else if(as>100000 && as<=150000)
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File
it = ((10/100)*(as-100000));
else if(as>150000 && as<=250000)
it = 5000+((20/100)*(as-150000));
else
it = 25000+((30/100)*(as-250000));
System.out.println("Income tax paid by A.P.Singh is : "+it);
}
}

Variable Description Table-

Output Screen-

Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File


Bibliography

Sites that were helpful:


> www.codingninjas.com

> www.cstudents .com

> www.wikipedia.com

Books that were helpful:


> ICSE Understanding Computer Applications

Thank You !
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File

You might also like