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 double . The initial amount of money
(sum) to invest
rate1 The interest rate for the first
double
year (in percent).
The interest rate for the
rate2 double
second year (in percent).
double The interest rate for the third
rate3 year (in percent).
Total amount after the first
amountAfterYear1 double
year.
Total amount after the second
amountAfterYear2 double
year.
Total amount after the third
amountAfterYear3 double
year.
double The total compound interest
compoundInterest
earned after 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:
Q4. A number is said to be Multiple Harshad number, when divided by the sum of its digits,
produces another 'Harshad Number'. Write a program to input a number and check whether it
is a Multiple Harshad Number or not.
(When a number is divisible by the sum of its digit, it is called 'Harshad Number').
Sample Input: 6804
Hint: 6804 ⇒ 6+8+0+4 = 18 ⇒ 6804/18 = 378
378 ⇒ 3+7+8= 18 ⇒ 378/18 = 21
21 ⇒ 2+1 = 3 ⇒ 21/3 = 7
Sample Output: Multiple Harshad Number
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");
}
}
}
Solution:
import java.util.*;
System.out.println("\nSorted Array:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
Output:
Q9. Write a program to accept the year of graduation from school as an integer value from the
user. Using the binary search technique on the sorted array of integers given below, output the
message "Record exists" if the value input is located in the array. If not, output the message
"Record does not exist".
Sample Input:
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.*;
Output:
Q10. If arrays M and M + N are as shown below, write a program in Java to find the array N.
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();
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:
Up to 5 years 15%
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:
Q17. Write a class program with the following specifications:
Class name — Matrix
Data members — int array m[][] with 3 rows and 3 columns
Member functions:
void getdata() — to accept the numbers in the array
void rowsum() — to find and print the sum of the numbers of each row
void colsum() — to find and print the sum of numbers of each column
Use a main function to create an object and call member methods of the class.
Solution:
import java.util.*;
public Matrix() {
m = new int[ARR_SIZE][ARR_SIZE];
}