Computer
Computer
Computer
Section – B
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
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
Solution code :-
import java.util.*;
public class assg1
{
public static void main(String args[])
{
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:
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
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);
Output Screen-
Assignment IV
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++)
Output screen-
Assignment V
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);
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:
Solution Code:
import java.util.Scanner;
if (cb == -1) {
System.out.println("Amount exceeds credit limit of 15000");
}
else {
System.out.println("Cash Back: " + cb);
}
}
}
}
Synopsis-
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);
}
}
Output screen-
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);
}
}
Output Screen-
> www.wikipedia.com
Thank You !
Ayush Gupta/ 10 /ICSE 2023/Computer Application/Practical File