SPRINGFIELD SCHOOL
PROJECT FILE
SUBJECT – Computer Applications
SESSiOn: 2023-2024
Submitted By
NAME: Pragya Pandey
CLASS: X Science
Submitted To
Ms. Anita Chhattani
ACKNOWLEDGEMENT
I would like to express my special thanks
of gratitude to my teacher Ms.Anita
Chhattani for (her able guidance and
support in completing my project.
I would also like to extend my gratitude
to the Director Sir Mr. Ashley Rose
for( providing me all the facility that was
required.
INDEX
1. String programs
2. 1-D-Array programs
3. 2-D-Array programs
4. Method Overloading programs
5. Constructor/Encapsulation programs
String programs
Output
Write a program in Java to accept a word a String and
display the new string after removing all the vowels present
in it.
Sample input: Computer Applications
Sample Output: Cmptr pplctns
import java.util.Scanner;
public class KboatVowelRemoval
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a word or sentence:");
String str = in.nextLine();
int len = str.length();
String newStr = "";
for( (int i = 0; i < len; i++) {
char ch = Character.toUpperCase(str.charAt(i));
if (ch == 'A' ||
ch == 'E' ||
ch == 'i' ||
ch == 'O' ||
ch == 'U') {
continue;
}
newStr = newStr + ch;
}
System.out.println("String with vowels removed");
System.out.println(newStr);
}
}
Output
Write a program in Java to accept a name(Containing three words) and display only the initials
(i.e., first letter of each word).
Sample input: LAL KRiSHnA ADVAni
Sample Output: L K A
import java.util.Scanner;
public class Kboatnameinitials
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a name of 3 or more words:");
String str = in.nextLine();
int len = str.length();
System.out.print(str.charAt(0) + " ");
for( (int i = 1; i < len; i++) {
char ch = str.charAt(i);
if (ch == ' ') {
char ch2 = str.charAt(i + 1);
System.out.print(ch2 + " ");
}
}
}
}
Output
Write a program in Java to accept a name containing three words and display the
surname first, followed by the first and middle names.
Sample input: MOHAnDAS KARAMCHAnD GAnDHi
Sample Output: GAnDHi MOHAnDAS KARAMCHAnD
import java.util.Scanner;
public class KboatSurnameFirst
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a name of 3 words:");
String name = in.nextLine();
/*
* Get the last index
* of space in the string
*/
int lastSpaceidx = name.lastindexOf(' ');
String surname = name.substring(lastSpaceidx + 1);
String initialname = name.substring(0, lastSpaceidx);
System.out.println(surname + " " + initialname);
}
}
Output
Write a program in Java to enter a String/Sentence and display the longest word and
the length of the longest word present in the String.
Sample input: “TATA FOOTBALL ACADEMY WiLL pLAY AGAinST MOHAn BAGAn”
Sample Output: The longest word: FOOTBALL: The length of the word: 8
import java.util.Scanner;
public class KboatLongestWord
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a word or sentence:");
String str = in.nextLine();
str += " "; //Add space at end of string
String word = "", lWord = "";
int len = str.length();
for( (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (ch == ' ') {
if (word.length() > lWord.length())
lWord = word;
word = "";
}
else {
word += ch;
}
}
System.out.println("The longest word: " + lWord +
": The length of the word: " + lWord.length());
}
}
Output
Write a program in Java to enter a sentence. Frame a word by joining all the first
characters of each word of the sentence. Display the word.
Sample input: Vital infor(mation Resource Under Seize
Sample Output: ViRUS
import java.util.Scanner;
public class KboatFrameWord
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
String word = "" + str.charAt(0);
int len = str.length();
for( (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (ch == ' ')
word += str.charAt(i + 1);
}
System.out.println(word);
}
}
Output
Write a program in Java to enter a sentence. Display the words which are only
palindrome.
Sample input: MOM AnD DAD ARE nOT AT HOME
Sample Output: MOM
DAD
import java.util.Scanner;
public class KboatpalinWords
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
str = str + " ";
String word = "";
int len = str.length();
for( (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (ch == ' ') {
int wordLen = word.length();
boolean ispalin = true;
for( (int j = 0; j < wordLen / 2; j++) {
if (word.charAt(j) != word.charAt(wordLen - 1 - j)) {
ispalin = false;
break;
}
}
if (ispalin)
System.out.println(word);
word = "";
}
else {
word += ch;
}
}
}
}
Output
Write a program to input a sentence and display the word of the sentence that contains
maximum number of vowels.
Sample input: HAPPY NEW YEAR
Sample Output: The word with maximum number of vowels: YEAR
import java.util.Scanner;
public class KboatMaxVowelWord
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
str = str + " ";
String word = "", mWord = "";
int count = 0, maxCount = 0;
int len = str.length();
for( (int i = 0; i < len; i++) {
char ch = Character.toUpperCase(str.charAt(i));
if (ch == 'A' ||
ch == 'E' ||
ch == 'i' ||
ch == 'O' ||
ch == 'U') {
count++;
}
if (ch == ' ') {
if (count > maxCount) {
maxCount = count;
mWord = word;
}
word = "";
count = 0;
}
else {
word += ch;
}
}
System.out.println("The word with maximum number of vowels: "
+ mWord);
}
}
Output
A 'Happy Word' is defined as:
Take a word and calculate the word's value based on position of the letters in
English alphabet. On the basis of word’s value, find the sum of the squares of
its digits. Repeat the process with the resultant number until the number equals
1 (one). if the number ends with 1 then the word is called a 'Happy Word'.
Write a program to input a word and check whether it a ‘Happy Word’ or not.
The program displays a message accordingly.
Sample input: VAT
place value of V = 22, A= 1, T = 20
[Hint: A = 1, B = 2, ----------, Z = 26]
Solution:
22120 ⇒ 22 + 22 + 12 + 22 + 02 = 13
⇒ 12 + 32 = 10
⇒ 12 + 02 = 1
Sample Output: A Happy Word
import java.util.Scanner;
public class KboatHappyWord
{
private static boolean isHappynumber(long num) {
long sum = 0;
long n = num;
do {
sum = 0;
while (n != 0) {
int d = (int)(n % 10);
sum += d * d;
n /= 10;
}
n = sum;
} while (sum > 6);
return (sum == 1);
}
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a word: ");
String word = in.next();
word = word.toUpperCase();
String wordValueStr = "";
int len = word.length();
for( (int i = 0; i < len; i++) {
wordValueStr += String.valueOf(word.charAt(i) - 64);
}
long wordValue = Long.parseLong(wordValueStr);
boolean isHappy = isHappynumber(wordValue);
if (isHappy)
System.out.println("A Happy Word");
else
System.out.println("not a Happy Word");
}
}
Output
Write a program to input a sentence. Count and display the frequency of each
letter of the sentence in alphabetical order.
Sample input: COMpUTER AppLiCATiOnS
Sample Output:
Character Frequency Character Frequency
A 2 O 2
C 2 p 3
i 1 R 1
L 2 S 1
M 1 T 2
n 1 U 1
import java.util.Scanner;
public class KboatLetterFreq
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a sentence:");
String str = in.nextLine();
str = str.toUpperCase();
int freqMap[] = new int[26];
int len = str.length();
for( (int i = 0; i < len; i++) {
char ch = str.charAt(i);
if (Character.isLetter(ch)) {
int chidx = ch - 65;
freqMap[chidx]++;
}
}
System.out.println("Character\tFrequency");
for( (int i = 0; i < freqMap.length; i++) {
if (freqMap[i] > 0) {
System.out.println((char)(i + 65)
+ "\t\t" + freqMap[i]);
}
}
}
}
Write a program to accept a string. Convert the string into upper case letters. Count
and output the number of double letter sequences that exist in the string.
Sample input: "SHE WAS FEEDinG THE LiTTLE RABBiT WiTH An AppLE"
Sample Output: 4
import java.util.Scanner;
public class KboatLetterSeq
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
String s = in.nextLine();
String str = s.toUpperCase();
int count = 0;
int len = str.length();
for( (int i = 0; i < len - 1; i++) {
if (str.charAt(i) == str.charAt(i + 1))
count++;
}
System.out.println("double Letter Sequence Count = " + count);
}
}
Output
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.
import java.util.Scanner;
public class KboatSpecialpalindrome
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.next();
str = str.toUpperCase();
int len = str.length();
if (str.charAt(0) == str.charAt(len - 1)) {
boolean ispalin = true;
for( (int i = 1; i < len / 2; i++) {
if (str.charAt(i) != str.charAt(len - 1 -
i)) {
ispalin = false;
break;
}
}
if (ispalin) {
System.out.println("palindrome");
}
else {
System.out.println("Special");
}
}
else {
System.out.println("neither Special nor
palindrome");
}
}
}
Output
Write a program to input a sentence. Convert the sentence into upper case letters. Display the
words along with frequency of the words which have at least a pair of consecutive letters.
Sample input: MODEM iS An ELECTROniC DEViCE
Sample Output:
MODEM
DEViCE
number of words containing consecutive letters: 2
import java.util.Scanner;
public class KboatStringConsecutive
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the string: ");
String str = in.nextLine();
str = str.toUpperCase();
str += " ";
String word = "";
int count = 0;
int len = str.length();
for( (int i = 0; i < len; i++) {
if (str.charAt(i) == ' ') {
int wordLen = word.length();
for( (int j = 0; j < wordLen - 1; j++) {
if (word.charAt(j) + 1 == word.charAt(j + 1)) {
count++;
System.out.println(word);
break;
}
}
word = "";
}
else {
word += str.charAt(i);
}
System.out.println("number of words containing consecutive letters: " + count);
}
}
1-D-Array
programs
OUTPUT
Sample Input
Enter 20 numbers
12
34
66
78
69
88
59
96
58
48
93
57
63
29
79
68
59
53
48
86
Number of even numbers= 11
Number of odd numbers = 9
Number of multiple of 4= 6
import java.util.*;
public class Numbers
public static void main()
Scanner in = new Scanner(System.in);
int i,j,c1=0,c2=0,c3=0;
int a[] = new int[20];
System.out.println("Enter 20 numbers");
for(i=0;i<20;i++)
a[i] = in.nextInt();
}
for( i=0;i<20;i++)
if(a[i]%2 == 0)
c1++;
if(a[i]%2 !=0)
c2++;
if(a[i]%4 ==0)
c3++;
System.out.println("Number of even numbers\t "+c1);
System.out.println("Number of odd numbers\t "+c2);
System.out.println("Number of multiple of 4\t "+c3);
}}
OUTPUT
Enter integer numbers=
34
56
78
34
46
86
24
15
47
68
89
46
34
56
68
45
34
23
Menu items
import java.util.*;
public class number
public static void main()
Scanner in= new Scanner(System.in);
int a[]= new int[20];
int n,s,i,j;
System.out.println(“Enter integer numbers”);
a[i]= in.nextint();
System.out.println(“Menu items”);
System.out.println(“1. To display all perfect numbers”);
System.out.println(“2. To display all buzz numbers”);
System.out.println(“Enter your choice”);
n=in.nextint();
switch(n)
case 1:
for(i=0;i<20;i++)
s=0;
for(j=1;j<a[i];j++)
if(a[i]%j==0)
s = s+j;
1. To display all perfect numbers
2. To display all buzz numbers
Enter your choice
56
47
56
7
if(s==a[i])
System.out.println(a[i]);
break;
case 2:
for(i=0;i<20;i++)
if(a[i]%7==0||a[i]%10==7)
System.out.println(a[i]);
break;
default:
System.out.println(“invalid choice”);
}}}
2-D ARRAY
pROGRAMS
OUTPUT
Enter the number of rows:
Enter the number of column:
Enter the elements of the matrix:
43
45
56
76
78
23
23
34
45
56
76
56
43
23
21
The given matrix is:
import java.util.*;
public class Main
public static void main(String []args)
Scanner s = new Scanner(System.in);
int m,n;
System.out.println("Enter the number of rows: \n");
m=s.nextInt();
System.out.println("Enter the number of column: \n");
n=s.nextInt();
int a1[][]=new int[m][n];
System.out.println("Enter the elements of the matrix: ");
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a1[i][j]=s.nextInt();
//Print the given matrix
System.out.println("The given matrix is: ");
43 45 56 76
78 23 23 34
45 56 76 7
56 43 23 21
The transpose matrix is:
43 78 45 56
45 23 56 43
56 23 76 23
76 34 7 21
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
System.out.print(a1[i][j]+" ");
System.out.println("");
int a2[][]=new int[n][m];
// Find the transpose of the matrix
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
a2[j][i]=a1[i][j];
System.out.println("The transpose matrix is:");
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
System.out.print(a2[i][j]+" ");
}
System.out.println("");
}
OUTPUT
The numbers of the matrix are:
12
23
45
65
43
32
76
65
21
43
56
76
89
29
56
34
The numbers of the matrix are:
12 23 45 65
43 32 76 65
21 43 56 76
89 29 56 34
The sum of the left diagonal elements:134
import java.util.*;
public class ddiagonals
public static void main(String args[])
Scanner in=new Scanner(System.in);
int i,j,d1,rd,k;d1=0;rd=0;
int m[][]=new int[4][4];
System.out.println("The numbers of the matrix are: ");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
m[i][j]= in.nextInt();
System.out.println("The numbers of the matrix are:");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
System.out.print(m[i][j]+" ");
System.out.println();
for(i=0;i<4;i++)
d1=d1+m[i][i];
The sum of the right diagonal elements= 273
System.out.println("The sum of the left diagonal elements:"+d1);
k=3;
for(i=0;i<4;i++)
rd=rd+m[i][k];
k=k-1;
System.out.println("The sum of the right diagonal elements= "+rd);
}
OUTPUT
Enter numbers of the first matrix
4
3
5
6
7
8
9
2
3
4
5
6
7
8
9
1
Enter the numbers of the second matrix
2
3
4
5
6
7
8
9
9
8
7
6
5
4
3
2
Sum of the array elements is:
6 6 9 11
13 15 17 11
12 12 12 12
12 12 12 3
import java.io.*;
public class ddsum
public static void main(String args[])throws IOException
InputStreamReader read= new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
int i,j;
int m[][]= new int[4][4];
int n[][]= new int[4][4];
int p[][]= new int[4][4];
System.out.println("Enter numbers of the first matrix");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
m[i][j]= Integer.parseInt(in.readLine());
System.out.println("Enter the numbers of the second matrix");
for(i=0;i<4;i++)
for(j=0;j<4;j++)
n[i][j]=Integer.parseInt(in.readLine());
System.out.println("Sum of the array elements is: ");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
p[i][j]=m[i][j]+n[i][j];
System.out.print(p[i][j]+ " ");
System.out.println();
}
OUTPUT
Enter the numbers of the matrix
6
The numbers of the matrix are:
1 2 3 2 4 5 3 5 6
it is a symmetric matrix
import java.util.*;
public class ddsymmetric
public static void main(String args[])
Scanner in = new Scanner(System.in);
int i,j,k; k=0;
int m[][]= new int[3][3];
int n[][]= new int[3][3];
System.outprintln(“Enter the numbers of the matrix”);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
m[i][j]=in.nextint();
}
System.out.println(“The numbers of the matrix are:”);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
System.out.print(m[i][j]+ “ “);
System.out.println();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if m[i][j]!=m[j][i])
k=1;
if(k==0)
System.out.println(“it is a symmetric matrix”);
else
System.out.println(“it is not a symmetric matrix”);
}
METHOD
OVERLOADinG
pROGRAMS
OUTPUT
The strings are equal.
class Choice
void num_cal(int num, char ch)
if(ch=='s')
System.out.println("The square of a number="+(num*num));
else
System.out.println("The cube of a number="+(num*num*num));
void num_cal(int a , int b, char ch)
if(ch=='p')
System.out .println("The product of the number="+(a*b));
else
System.out.println("The sum of the numbers="+(a+b));
}
public void num_cal(String str1, String str2)
if(str1.equals(str2))
System.out.println("Two strings are equal");
else
System.out.println("The two strings are not equal.");
OUTPUT
class Overload
public double area(double a, double b, double c)
double s, ar;
s= (a+b+c)/2;
ar=Math.sqrt(s*(s-a)*(s-b)*(s-c));
return(ar);
public double area( int a, int b, int height)
double ar;
ar= 1.0/2.0*height*(a+b);
return(ar);
public double area(double diagonal1, double diagonal2)
double ar;
ar= 1.0/2.0*(diagonal1*diagonal2);
return (ar);
OUTPUT
Enter the last limit of the series
34
Enter the values of x
sum of first series=1.3573149356093497
sum of second series=268040729
import java.util.*;
class Over_loading
void sumSeries(int n, double x)
double sum= 0.0d;
int i;
for(i=1;i<=n;i++)
if(i%2==0)
sum=sum-(double)x/i;
else
sum=sum+(double)x/i;
}
System.out.println("sum of first series="+sum);
void sumSeries()
int i,p=1,sum1=0;
for(i=1;i<=20;i++)
p=p*i;
sum1=sum1+p;
System.out.println("sum of second series="+sum1);
}
public static void main(String args[])
Scanner in = new Scanner(System.in);
int n;
double x;
System.out.println("Enter the last limit of the series");
n=in.nextInt();
System.out.println("Enter the values of x");
x=in.nextDouble();
Over_loading ob = new Over_loading();
ob.sumSeries(n,x);
ob.sumSeries();
}
COnSTRUCTOR
pROGRAMS
OUTPUT
Enter employee’s name, Employee number, Basic Salary
"HARI NARAYAN"
9413974799
49999
name="HARI NARAYAN"
Employee number=9413974799
Gross Salary=Rs.72498.55
net Salary=Rs.66498.67
import java.util.*;
public class Employee_Sal
String name,empno;
int basic;
double da,hra,pf,gs,net;
Employee_Sal(String n, String en, int bs)
na,e = n;
empno=en;
basic=bs;
void compute()
da=basic*30.0/100.0;
hra=basic*15.0/100.0;
pf=basic*12.0/100.0;
gs=basic+da+hra;
net=gs-pf;
void display()
System.out.println(“name=“+name);
System.out.println(“Employee number=“+empno);
System.out.println(“Gross Salary=Rs.”+gs);
System.out.println(“net Salary=Rs.”+net);
}
public static void main(String args[])
Scanner in = new Scanner(System.in);
String nm,enm;
int bsal;
System.out.println(“Enter employee’s name, Employee number, Basic Salary”);
nm=in.nextLine();
Enm=in.next();
Bsal=in.nextint();
Employee_Sal ob = new Employee_Sal(nm, enm, bsal);
ob.compute();
ob.display();
}
OUTPUT
Enter student’s name, Age, Marks in three subjects one by one=
"Riya Agarwal"
16
78
89
97
name ="Riya Agarwal"
Age=16years
Marks in three subjects =78 89 97
Highest marks in three subjects = 97
The average marks=88.0
import java.util.*;
public class Marks
String name;
int age,m1,m2,m3,max;
double avg;
Marks(String n, int d, int a, int b, int c)
name = n;
Age = d;
M1= a;
M2=b;
M3=c;
void compute()
Avg=(m1+m2+m3)/3;
if(m1>m2 && m1>m3)
Max=m1;
if(m2>m1 && m2>m3)
Max=m2;
if(m3>m1 && m3>m2)
Max=m3;
void display()
{
System.out.println(“name =“+ name);
System.out.println(“Age=“+age+ “years”);
System.out.println(“Marks in three subjects =“+m1+ “ “+m2+ “ “+m3);
System.out.println(“Highest marks in three subjects =“+max);
System.out.println(“The average marks=“+ avg);
public static void main(String args [])
Scanner in = new Scanner(System.in);
String nm;
int ag,a1,b1,c1;
System.out.println(“Enter student’s name, Age, Marks in three subjects one by
one=“);
nm=in.nextLine();
Ag=in.nextLine();
A1=in.nextLine();
B1=in.nextLine();
C1=in.nextLine();
Marks ob= new Marks(nm, ag, a1, b1, c1);
ob.compute();
ob.display();