Computer Applications
Computer Applications
APPLICATIONS
BOARD PROJECT 2024-
2025
if (x2 - x1 != 0)
{
double slope = (y2 - y1) / (x2 - x1);
System.out.println("The slope (m) of the line is: " + slope);
}
else {
System.out.println("The slope is undefined (vertical line).");
}
}
}
Variable description table:
variable datatype description
x1 double x-coordinate of point A
x2 Double x-coordinate of point B
y1 Double y-coordinate of point A
y2 double y-coordinate of point B
slope double The calculated slope (m)
of the line
Output:
Q2.write a program to input the sum. Calculate and display the compound
interest in 3 years , when the rates for the successive years are r1%,r2% and
r3% respectively.
Solution:
import java.util.*;
public class CompoundInterestCalculator
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the principal amount (sum): ");
double principal = in.nextDouble();
System.out.print("Enter the interest rate for year 1 (r1%): ");
double rate1 = in.nextDouble();
System.out.print("Enter the interest rate for year 2 (r2%): ");
double rate2 = in.nextDouble();
System.out.print("Enter the interest rate for year 3 (r3%): ");
double rate3 =in.nextDouble();
double amountAfterYear1 = principal + (principal * rate1 / 100);
double amountAfterYear2 = amountAfterYear1 + (amountAfterYear1 *
rate2 / 100);
double amountAfterYear3 = amountAfterYear2 + (amountAfterYear2 *
rate3 / 100);
double compoundInterest = amountAfterYear3 - principal;
System.out.printf("The compound interest after 3 years is: %.2f\n",
compoundInterest);
}
}
Variable description table:
variable datatype description
principal doubl The initial amount of
.
e money (sum) to invest
rate1 The interest rate for the
double
first year (in percent).
The interest rate for the
rate2 double second year (in
percent).
double
The interest rate for the
rate
third year (in percent).
3
Total amount after the
amountAfterYear1 double
first year.
Total amount after the
amountAfterYear2 double
second year.
Total amount after the
amountAfterYear3 double
third year.
double The total compound
compoundInter interest earned after
est three years.
Output:
Q3. A bank announces new rates for Term Deposit Schemes for their
customers and Senior Citizens as given below:
solution:
import java.util.Scanner;
double si = 0.0;
Output:
Solution
import java.util.*;
Output:
Q5. Using the switch statement, write a menu driven program for the
following:
Solution
import java.util.*;
switch (ch) {
case 1:
int a = 1;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(a++ + "\t");
}
System.out.println();
}
break;
case 2:
String s = "ICSE";
for (int i = 0; i < s.length(); i++) {
for (int j = 0; j <= i; j++) {
System.out.print(s.charAt(j) + " ");
}
System.out.println();
}
break;
default:
System.out.println("Incorrect Choice");
}
}
}
Output:
Q6. Write a program to input two characters from the keyboard. Find the
difference (d) between their ASCII codes. Display the following messages:
If d = 0 : both the characters are same.
If d \< 0 : first character is smaller.
If d > 0 : second character is smaller.
Sample Input :
D
P
Sample Output :
d = (68 - 80) = -12
First character is smaller
Solution:
import java.util.*;
Output:
Q7. Using switch case statement, write a menu driven program to perform
the following tasks:
(a) To generate and print the letters from A to Z along with their Unicode.
Letters Unicode
A 65
B 66
….. ……..
….. ……..
Z 90
(b) To generate and print the letters from z to a along with their Unicode.
Letters Unicode
z 122
y 121
….. ……..
….. ……..
a 97
Solution:
import java.util.*;
switch (ch) {
case 1:
System.out.println("Letters" + "\t" + "Unicode");
for(int i = 65; i <= 90; i++)
System.out.println((char)i + "\t" + i);
break;
case 2:
System.out.println("Letters" + "\t" + "Unicode");
for (int i = 122; i >= 97; i--)
System.out.println((char)i + "\t" + i);
break;
default:
System.out.println("Incorrect Choice");
}
}
}
System.out.println("\nSorted Array:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
Output:
n[0] n[1] n[2] n[3] n[4] n[5] n[6] n[7] n[8] n[9]
1982 1987 1993 1996 1999 2003 2006 2007 2009 2010
Solution:
import java.util.*;
if (idx == -1)
System.out.println("Record does not exist");
else
System.out.println("Record exists");
}
}
Solution:
public class SubtractDDA
{
public static void main(String args[]) {
int arrM[][] = {
{-1, 0, 2},
{-3, -1, 6},
{4, 3, -1}
};
int arrSum[][] = {
{-6, 9, 4},
{4, 5, 0},
{1, -2, -3}
};
System.out.println("Array N:");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(arrN[i][j]);
System.out.print(' ');
}
System.out.println();
}
}
}
Output:
Q11. Write a program in Java to accept a word and display the ASCII code of
each character of the word.
Sample Input: BLUEJ
Sample Output:
ASCII of B = 66
ASCII of L = 76
ASCII of U = 85
ASCII of E = 69
ASCII of J = 74
Solution:
import java.util.*;
Output:
Q12. Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and
vice-versa.
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.
Write a program to accept a word. Check and display whether the word is a
palindrome or only a special word or none of them.
Solution:
import java.util.*;
str = str.toUpperCase();
isPalin = false;
break;
if (isPalin) {
System.out.println("Palindrome");
else {
System.out.println("Special");
else {
}
}
Output:
Q13. Write a class with the name Perimeter using method 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 * (22/7) * r
Solution:
import java.util.*;
Output:
Q15. Bank charges interest for the vehicle loan as given below:
Rate of
Number of years
interest
Up to 5 years 15%
years
Data
Purpose
Members
double
Amount sanctioned
principal
double
To store the interest
interest
Solution:
import java.util.*;
Output:
Q16. Define a class called Student to check whether a student is eligible for
taking admission in class XI with the following specifications:
Solution:
import java.util.*;
return course;
}
Output:
public Matrix() {
m = new int[ARR_SIZE][ARR_SIZE];
}