0% found this document useful (0 votes)
9 views30 pages

Biodata

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 30

BIODATA

Name : Prakhar Verma


Class : X Sec :‘A’
Roll No. : 31
Subject : Computer Applications
Class Teacher : Mr. Saurav Daruka
Subject Teacher : Mr. Pradeep Rastogi
INDEX
Sr. Date Topic Pg. Signature
No. No.
1 10/06/23 Acknowledgement 3
2 10/06/23 Program 1 4-5
3 10/06/23 Program 2 6-7
4 10/06/23 Program 3 8-9
5 10/06/23 Program 4 10-11
6 10/06/23 Program 5 12-13
7 18/08/23 Program 6 14-15
8 18/08/23 Program 7 16-17
9 18/08/23 Program 8 18-19
10 18/08/23 Program 9 20-21
11 18/08/23 Program 10 22-23
12 18/08/23 Program 11 24-25
13 22/10/23 Program 12 26-27
14 22/10/23 Program 13 28-29
15 /11/23 Program 14 30-31
16 /11/23 Program 15 32-33
17 /11/23 Bibliography 34
I, Prakhar Verma wish to extend my profound gratitude to a group of
individuals whose unwavering support and guidance have played a pivotal role
in my academic journey as I navigate the challenges of class 10. My heartfelt
appreciation goes to my dedicated teachers, whose expertise and tireless
efforts have not only imparted knowledge but also instilled in me a passion for
learning. Their mentorship has been invaluable.

To my dear friends, your camaraderie and support have been a constant


source of motivation. We've embarked on this academic endeavor together,
and your encouragement and shared experiences have made this journey
more meaningful.

Lastly, to my parents, your unwavering belief in my potential and your


sacrifices to provide me with the best opportunities has been the bedrock of
my success. Your love and guidance have shaped not only my academic
achievements but also my character.

I am profoundly grateful for the collective wisdom, encouragement, and love


of these remarkable individuals. With their support, I have reached this
significant milestone in my education, and I look forward to continuing this
journey with the invaluable lessons they have imparted.
Question 1
A bank announces new rates for Term Deposit Schemes for their customers
and Senior Citizens as given below:
Term Rate of Interest (General) Rate of Interest (Senior Citizen)
Up to 1 year 7.5% 8.0%
Up to 2 years 8.5% 9.0%
Up to 3 years 9.5% 10.0%
More than 3 years 10.0% 11.0%
The 'senior citizen' rates are applicable to the customers whose age is 60
years or more. Write a program to accept the sum (p) in term deposit scheme,
age of the customer and the term. The program displays the information in
the following format:
Amount Deposited Term Age Interest earned Amount Paid
XXX XXX XXX XXX XXX

import java.util.Scanner;

public class TermDepositInterestCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the deposit amount: ");


double depositAmount = scanner.nextDouble();

System.out.print("Enter the customer's age: ");


int age = scanner.nextInt();

System.out.print("Enter the term (in years): ");


int term = scanner.nextInt();

double generalInterestRate = 0.0;


double seniorCitizenInterestRate = 0.0;

if (term <= 1) {
generalInterestRate = 7.5;
seniorCitizenInterestRate = 8.0;
} else if (term <= 2) {
generalInterestRate = 8.5;
seniorCitizenInterestRate = 9.0;
} else if (term <= 3) {
generalInterestRate = 9.5;
seniorCitizenInterestRate = 10.0;
} else {
generalInterestRate = 10.0;
seniorCitizenInterestRate = 11.0;
}

double interestEarned, amountPaid;


if (age < 60) {
interestEarned = depositAmount *generalInterestRate / 100;
} else {
interestEarned = depositAmount * seniorCitizenInterestRate/ 100;
}
amountPaid = depositAmount + interestEarned;

System.out.println("Amount Deposited: \t Term \t Age \t Interest


Earned \t Amount Paid ");
System.out.println(depositAmount + "\t" + term + "\t" + age + "\t" +
interestEarned + "\t" + amountPaid);
}
}

Variable Description Table


Variable Data Type Description
depositAmount double Stores the deposit amount.
age int Stores the age of the customer.
term int Stores the term in years.
generalInterestRate double Stores the interest rate for general customers.
seniorCitizenInterestRate double Stores the interest rate for senior citizens.
interestEarned double Stores the calculated interest earned.
amountPaid double Stores the total amount paid.
Question 2
A courier company charges differently for 'Ordinary' booking and 'Express'
booking based on the weight of the parcel as per the tariff given below:
Weight of parcel Ordinary booking Express booking
Up to 100 gm 80 100
101 to 500 gm 150 250
501 gm to 1000 gm 210 300
More than 1000 gm 250 200
Write a program to input weight of a parcel and type of booking ('O' for
ordinary and 'E' for express). Calculate and print the charges accordingly.

import java.util.Scanner;

public class CourierChargesCalculator {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the weight of the parcel (in grams): ");


int weight = scanner.nextInt();
System.out.println("Enter the type of booking ('O' for ordinary, 'E'
for express): ");
char bookingType = scanner.next().charAt(0);

int charges = 0;

if (bookingType == 'O'){
// calculate charges for ordinary booking
if (weight <= 100) {
charges = 80;
} else if (weight <= 500) {
charges = 150;
} else if (weight <= 1000) {
charges = 210;
} else {
charges = 250;
}
}else if(bookingType == 'E'){
// Calculate charges for express booking
if (weight <= 100) {
charges = 100;
} else if (weight <= 500) {
charges = 250;
} else if (weight <= 1000) {
charges = 300;
} else {
charges = 200;
}
} else {
System.out.println("Invalid type");
System.exit(0);
}

System.out.println("Charges: " + charges);


}
}

Variable Description Table


Variable Data Type Description
weight int Stores the weight of the parcel in grams.
bookingType char Stores the type of booking ('O' for ordinary, 'E' for express).
charges int Stores the calculated courier charges.
Question 3
Write a menu driven program to calculate:
(a)Area of a circle = p*r², where p = 22/7
(b) Area of a square = side*side
(c) Area of a rectangle = length* breadth
Enter 'c' to calculate area of circle, 's' to calculate area of square and 'r’ to
calculate area of rectangle.

import java.util.Scanner;

public class MenuDrivenProgram {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Menu:");
System.out.println("'c' to calculate Area of a Circle");
System.out.println("'s' to calculate Area of a Square");
System.out.println("'r' to calculate Area of a Rectangle");
System.out.print("Enter your choice (c/s/r): ");
char choice = scanner.next().charAt(0);

switch (choice) {
case 'c':
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = Math.PI * radius * radius;
System.out.println("Area of the circle: " + area);
break;
case 's':
System.out.print("Enter the side length of the square: ");
double side = scanner.nextDouble();
double area = side * side;
System.out.println("Area of the square: " + area);
break;
case 'r':
System.out.print("Enter the length of the rectangle: ");
double length = scanner.nextDouble();
System.out.print("Enter the breadth of the rectangle: ");
double breadth = scanner.nextDouble();
double area = length * breadth;
System.out.println("Area of the rectangle: " + area);
break;
default:
System.out.println("Invalid choice");
}
}
}

Variable Description Table


Variable Data Type Description
choice char Stores the user's menu choice (a, b, or c).
radius double Stores the radius of the circle.
side double Stores the side length of the square.
length double Stores the length of the rectangle.
breadth double Stores the breadth of the rectangle.
area double Stores the calculated area.
Question 4
A prime number is said to be 'Twisted Prime', if the new number obtained
after reversing the digits is also a prime number. Write a program to accept a
number and check whether the number is "Twisted Prime' or not.
42 = 6*7
Sample Input: 167
Sample Output: 761
167 is a 'Twisted Prime'.

import java.util.Scanner;

public class TwistedPrimeChecker {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter a number: ");


int number = scanner.nextInt();

// Check if the number is prime


boolean isPrime = true;
if (number <= 1) {
isPrime = false;
} else {
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0) {
isPrime = false;
break;
}
}
}

// Check if the reversed number is prime


int reversed = 0;
int temp = number;
while (temp != 0) {
int digit = temp % 10;
reversed = reversed * 10 + digit;
temp /= 10;
}
boolean isReversedPrime = true;
if (reversed <= 1) {
isReversedPrime = false;
} else {
for (int i = 2; i <= Math.sqrt(reversed); i++) {
if (reversed % i == 0) {
isReversedPrime = false;
break;
}
}
}

// Check if it's a Twisted Prime


if (isPrime && isReversedPrime) {
System.out.println(number + " is a Twisted Prime.");
} else {
System.out.println(number + " is not a Twisted Prime.");
}
}
}

Variable Description Table


Variable Data Type Description
number int Stores the user-input number to be checked.
isPrime Boolean Indicates whether the number is a prime.
reversed int Stores the reversed number of the input.
temp int Temporary variable to calculate the reversed number.
digit int Stores each digit when reversing the number.
isReversedPrime Boolean Indicates whether the reversed number is prime.
Question 5
Using a switch statement, write a menu driven program to:
(a) Generate and display the first 10 terms of the Fibonacci series
0, 1, 1, 2, 3, 5………
The first two Fibonacci numbers are 0 and 1, and each subsequent number
is the sum of the previous two.
(b) Find the sum of the digits of an integer that is input by the user.
Sample Input: 15390
Sample Output: Sum of the digits = 18
For an incorrect choice, an appropriate error message should be displayed.

import java.util.Scanner;

public class MenuDrivenFibonacciAndSumOfDigits {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice;
System.out.println("Menu:");
System.out.println("1. Generate and display the first 10 terms of
the Fibonacci series");
System.out.println("2. Find the sum of the digits of an
integer");
System.out.print("Enter your choice (1/2): ");
choice = scanner.nextInt();

switch (choice) {
case 1:
int n = 10;
int firstTerm = 0, secondTerm = 1;

System.out.print("Fibonacci Series (First 10 terms): ");


for (int i = 0; i < n; i++) {
System.out.print(firstTerm + " ");
int nextTerm = firstTerm + secondTerm;
firstTerm = secondTerm;
secondTerm = nextTerm;
}
System.out.println();
break;
case 2:
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
int sum = 0;
int originalNumber = number;

while (number != 0) {
int digit = number % 10;
sum += digit;
number /= 10;
}

System.out.println("Sum of the digits of " +


originalNumber + " = " + sum);
break;
case 3:
System.out.println("Exiting the program.");
break;
default:
System.out.println("Invalid choice. Please select 1, 2,
or 3.");
break;
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for user input.
choice int Stores the user's menu choice (1, 2, or 3).
n int Number of terms in the Fibonacci series (10).
firstTerm int First term of the Fibonacci series.
secondTerm int Second term of the Fibonacci series.
number int Stores the integer for which we find the sum of digits.
sum int Stores the sum of the digits of number.
originalNumber int Stores the original value of number for display.
Question 6
Write a program to implement the selection sort algorithm.

import java.util.Scanner;

public class BinarySearch {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the number of elements in the array: ");


int n = scanner.nextInt();

int[] arr = new int[n];

System.out.println("Enter the sorted array elements:");

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


arr[i] = scanner.nextInt();
}

System.out.println("Enter the element to search for: ");


int target = scanner.nextInt();

int left = 0;
int right = n - 1;
boolean found = false;

while (left <= right) {


int mid = (left + right) / 2;

if (arr[mid] == target) {
System.out.println("Element found at index " + mid);
found = true;
break;
}

if (arr[mid] < target) {


left = mid + 1;
} else {
right = mid - 1;
}
}
if (!found) {
System.out.println("Element not found in the array.");
}
}
}

Variable Description Table


Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Array of integers in which the search is performed.
i int Loop variable for iterating through the array.
target int Element to search for within the array.
found boolean Flag to indicate if the target element is found.
Question 7
Write a program to perform a sequential search on an array of integers and
find a specific target element. If the element is found, print "Element found at
index [index].", otherwise, print "Element not found."

import java.util.Scanner;

public class LinearSearch {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of elements in the array: ");


int n = scanner.nextInt();

int[] arr = new int[n];

System.out.println("Enter the array elements:");

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


arr[i] = scanner.nextInt();
}

System.out.print("Enter the element to search for: ");


int target = scanner.nextInt();

boolean found = false;

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


if (arr[i] == target) {
System.out.println("Element found at index " + i);
found = true;
break;
}
}

if (!found) {
System.out.println("Element not found in the array.");
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Sorted array of integers in which the search is performed.
left int Left index of the search range.
right int Right index of the search range.
target int Element to search for within the array.
mid int Middle index of the search range.
found boolean Flag to indicate if the target element is found.
Question 8
Write a program to implement the selection sort algorithm to sort an array in
ascending order.

import java.util.Scanner;

public class SelectionSort {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of elements in the array: ");


int n = scanner.nextInt();

int[] arr = new int[n];

System.out.println("Enter the array elements:");

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


arr[i] = scanner.nextInt();
}

// Perform selection sort


for (int i = 0; i < n - 1; i++) {
int minIndex = i;

for (int j = i + 1; j < n; j++) {


if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}

// Swap arr[i] and arr[minIndex]


int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}

System.out.println("Sorted array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Array of integers to be sorted.
i int Loop variable for outer loop (selection sort).
j int Loop variable for inner loop (selection sort).
minIndex int Index of the minimum element in the unsorted part.
temp int Temporary variable for swapping elements.
Question 9
Write a program to implement the bubble sort algorithm to sort an array in
ascending order.

import java.util.Scanner;

public class BubbleSort {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of elements in the array: ");


int n = scanner.nextInt();

int[] arr = new int[n];

System.out.println("Enter the array elements:");

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


arr[i] = scanner.nextInt();
}

// Perform bubble sort


for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j + 1]
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}

System.out.println("Sorted array:");
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
}
}
Variable Description Table
Variable Data Type Description
scanner Scanner Scanner object for input.
n int Number of elements in the array.
arr int[] Array of integers to be sorted.
i int Loop variable for the outer loop (bubble sort).
j int Loop variable for the inner loop (bubble sort).
temp int Temporary variable for swapping elements.
Question 10
Write a program to print the sum of diagonals of double dimensional array.

import java.util.Scanner;

public class DiagonalSum {


public static void main(String[] args) {
Scanner s = new Scanner(System.in);

System.out.print("Enter the size of the square matrix: ");


int n = s.nextInt();

int[][] m = new int[n][n];

System.out.println("Enter the elements of the matrix:");

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


for (int j = 0; j < n; j++) {
m[i][j] = s.nextInt();
}
}

int leftSum = 0;
int rightSum = 0;

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


leftSum += m[i][i];
rightSum += m[i][n - 1 - i];
}

System.out.println("Sum of left diagonal: " + leftSum);


System.out.println("Sum of right diagonal: " + rightSum);
}
}
Variable Description Table
Variable Data Type Description
s Scanner Scanner object for input.
n int Size of the square matrix.
m int[][] Square matrix of integers.
i int Loop variable for row iteration.
j int Loop variable for column iteration.
leftSum int Sum of elements in the left diagonal.
rightSum int Sum of elements in the right diagonal.
Question 11
Write a program to to print the sum of rows and columns of double dimension
array.

import java.util.Scanner;

public class MatrixSum {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of rows: ");


int rows = scanner.nextInt();

System.out.print("Enter the number of columns: ");


int columns = scanner.nextInt();

int[][] matrix = new int[rows][columns];

System.out.println("Enter the elements of the matrix:");

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


for (int j = 0; j < columns; j++) {
matrix[i][j] = scanner.nextInt();
}
}

// Calculate the sum of each row


for (int i = 0; i < rows; i++) {
int rowSum = 0;
for (int j = 0; j < columns; j++) {
rowSum += matrix[i][j];
}
System.out.println("Sum of Row " + (i + 1) + ": " + rowSum);
}

// Calculate the sum of each column


for (int j = 0; j < columns; j++) {
int columnSum = 0;
for (int i = 0; i < rows; i++) {
columnSum += matrix[i][j];
}
System.out.println("Sum of Column " + (j + 1) + ": " +
columnSum);
}
}
}

Variable Description Table


Variable Data Type Description
rows int Number of rows in the matrix.
columns int Number of columns in the matrix.
matrix int[][] 2D matrix of integers.
i int Loop variable for row iteration.
j int Loop variable for column iteration.
rowSum int Sum of elements in the current row.
columnSum int Sum of elements in the current column.
Question 12
Write a program in Java to accept the name of an employee and his/her
annual income Pass the name and the annual income to a function Tax(String
name, int income) which displays the name of the employee and the income
tax as per the given tariff :-
Annual Income Income Tax

Up to ₹2,50,000 No tax

₹2,50,001 to ₹5,00,000 10% of the income exceeding ₹2,50,000

₹5,00,001 to ₹10,00,000 ₹30,000+20% of the amount exceeding ₹5,00,000

₹10,00,001 and above ₹750,000 + 30% of the amount exceeding ₹10,00,000

import java.util.Scanner;

public class IncomeTaxCalculator {

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
System.out.print("Enter the name of the employee: ");
String name = scanner.nextLine();
System.out.print("Enter the annual income: ");
double income = scanner.nextDouble();
Tax(name, income);
}

public static void Tax(String name, double income) {


double tax = 0;
if (income <= 250000) {
tax = 0;
} else if (income <= 500000) {
tax = ((income - 250000) * 10 )/ 100.0;
} else if (income <= 1000000) {
tax = 30000 + (income - 500000) * 20 / 100.0;
} else {
tax = 50000 + (income - 1000000) * 30 / 100.0;
}
System.out.println("Name: " + name);
System.out.println("Income Tax: " + tax);
}
}

Variable Description Table


Variable Data Type Description
name String variable to store the employee's name.
income double to store the annual income.
tax double to store the calculated income tax.
Question 13
Write a class with the name Perimeter using function overloading that
computes the perimeter of a square, a rectangle and a circle
Formula:
Perimeter of a square = 4*s
Perimeter of a rectangle =2*(l+b)
Perimeter of a circle = 2πr.

import java.util.Scanner;

public class Perimeter {


public static double calculatePerimeter(double side) {
return 4 * side;
}

public static double calculatePerimeter(double length, double breadth) {


return 2 * (length + breadth);
}

public static float calculatePerimeter(float radius) {


return 2 * (float)Math.PI * radius;

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.print("Enter the side length of the square: ");


double side = scanner.nextDouble();

System.out.print("Enter the length of the rectangle: ");


double length = scanner.nextDouble();
System.out.print("Enter the breadth of the rectangle: ");
double breadth = scanner.nextDouble();

System.out.print("Enter the radius of the circle: ");


float radius = scanner.nextFloat();

double squarePerimeter = calculatePerimeter(side);


double rectanglePerimeter = calculatePerimeter(length, breadth);
float circlePerimeter = calculatePerimeter(radius);

System.out.println("Perimeter of Square: " + squarePerimeter);


System.out.println("Perimeter of Rectangle: " + rectanglePerimeter);
System.out.println("Circumference of Circle: " + circlePerimeter);
}
}

Variable Description Table


Variable Data Type Description
side double Stores the side length of a square.
length double Stores the length of a rectangle.
breadth double Stores the breadth of a rectangle.
radius float Stores the radius of a circle.
squarePerimeter double Stores the calculated perimeter of a square.
rectanglePerimeter double Stores the calculated perimeter of a rectangle.
circlePerimeter float Stores the calculated perimeter of a circle.
Question 14

You might also like