You are on page 1of 43

COMPUTER APPLICATIONS

[BLUE J]

NAME: REETABRATA ROY


CLASS: X SECTION: B
ROLL NUMBER: 34
SCHOOL: M.H.M.S
UNIQUE ID:
INDEX NUMBER:
ACADEMIC YEAR: 2023-24
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude to my computer
teacher Mr. Arghya Basu who allowed me to work on this project. It helped me a
lot to learn about programming and I learned about many new things. I am really
thankful to you.

Secondly, I would also thank my parents and friends who helped me in finalizing
this project within the limited time frame.

Once again, I would like to thank you sir for allowing me to do this wonderful
project. Do have a really great day sir!

Signature of the Candidate:


Reetabrata Roy

1
INDEX
SERIAL NO CONTENT PAGE NO

1 PROGRAm 1 3-11

2 PROGRAm 2 12-16

3 PROGRAm 3 17-20

4 PROGRAm 4 21-25

5 TOuR 26-30

6 BENEfIT 31-35

7 REPORT 36-40

8 CONCLuSION 41

9 BIBLIOGRAPHY 42

2
QUESTION 1
Write a program in Java which would accept a sentence and would

perform the following tasks:

i. To find out total number of letters in the sentence. ii. To find out

the count of words in the sentence. iii. To find out the shortest and

largest words in the sentence. iv. To arrange all words

alphabetically.

3
ALGORITHM
STEP 1: Start

STEP 2: Import java.utility package.

STEP 3: Create Class Program _1.

STEP 4: Create a method public static void main(String []args).

STEP 5: Create an object sc of Scanner Class

STEP 6: Create a String variable ‘a’.

STEP 7: Create Integer variable alpha and wrd .

STEP 8: Print a Sentence “Enter a sentence ”.

STEP 9: Input the user given sentence in variable ‘a’.

STEP 10: Call function letter(a) to alpha .

STEP 11: Print a sentence “Number of letters in the sentence are :” and the print alpha.

STEP 12: Call function word_Count(a) to wrd .

STEP 13: Print a sentence “Number of words in the sentence are :” and the print wrd.

STEP 13: Call function short long(a).

STEP 14: Call function sort Word(a).

STEP 15: Close main method and make new method public static int letter(String b).

STEP 16: Make a integer variable count=0, l and i.

STEP 17: Initialize l to length().

STEP 18: Initialize b to b+” ”.

STEP 19: Make a character variable x which is equals to b.charAt(i).

STEP 20: If x would not be ‘ ’,then increase value of count by 1.


4
STEP 21: Initialize I to 0 and keep increasing value of i by 1 everytime and repeat STEP 18 and

STEP19 till i<l .

STEP 22: Return value of count to main method.

STEP 23: Close the method and make new method public static int word_Count(String b).

STEP 24: Make integer variable count =0, l,i.

STEP 25: Initialize l to b.length().

STEP 26: Initialize b to b+” ”.

STEP 27: Initialize k to “ ”.

STEP 28: Initialize i to 0 and keep adding 1 to it everytime until i<l and keep repeating STEP 28 to 30

STEP 29: Make a character variable x containing value of b.charAt(i)s=b.length(),l and i.

STEP 30: If x is not equals to ‘ ’,then add k with x and store it in k.

STEP 31: If x is equals to to ‘ ’ then increase value of count by 1.

STEP 32: Return value of count to the main method .

STEP 33 : Close the method and make new method public static void short long(String b).

STEP 34 : Make integer variable h =0,

STEP 35: Make String variable lw,sw,k and initialize them to “”.

STEP 36: Initialize value of l to value of s.

STEP 37: Initialize b to b+” ”.

STEP 38: Initialize i to 0 and keep adding 1 to it everytime until i<l and keep repeating STEP 38 to 44.

STEP 39: Make a character variable x containing value of b.charAt(i).

STEP 40: If x is not equals to ‘ ’,then add k with x and store it in k.

STEP 41: If x is equals to to ‘ ’ then Check whether k.length()>h.


5
STEP 42: If true the change value of lw to k and h to k.length().

STEP 43: Check whether k.length()<s.


STEP 44: If true the change value of sw to k and s to k.length().

STEP 45: Initialize value of k to””.

STEP 46: Print a sentence “Longest word in the sentence is :” and print lw.

STEP 47: Print a sentence “Longest word in the sentence is :” and print sw.

STEP 48 : Close the method. and open a new method sort Word(String b)

STEP 49: Initialize integer variable c and p to 0 & make I and j.

STEP 50: Initialize String variable wrd to null and b to b+” .

STEP 51: Check if b.charAt(i)==’ ’. If yes then increase the value of c by 1.

STEP 52: Initialize value of i to 0 and increase value of i by 1 each time while returning to STEP 51 until
i<b.lenth().

STEP 53: Make a String array arr[] of size c.

STEP 54: Take value of a character variable x to b.charAt(i).

STEP 55: Check if x!=’ ’ . If so , then assign value of wrd to wrd+x.

STEP 56: If not so , then assign value of arr[p]to wrd , wrd to null and increase value of p by
1.

STEP 57: Initialize value of i to 0and increase value of I by 1 , each time going back to STEP 51 until
i<b.length().

STEP 58: Make two loops and check whether value of arr[i] is equal to arr[j].If so ,then change value of
wrd to arr[i], arr[i] to arr[j] and arr[j] to wrd until I<c and j<c.

STEP 59: Use a loop to Print the Sentence in alphabetical order.

STEP 60: Stop.

6
SOURCE CODE

7
8
OUTPUT

9
VARIABLE LISTING

Member Methods Data type Variable type Use

String A To store the input sentence


public static void main ()

Int Alpha To store no. of letters

wrd To store no. of words

public static int Int Count To return no.of letters and


letter(String b) words

public static
word_Count
(String b)

public static int letter Int i,j Loop variables


(String b)

public static
word_Count
(Stringb)
public static void
shortlong (Stringb)

public static void sort


Word (Stringb)

10
public static Char X To store each
word_Count(String b) character of the
sentence

public static void


shortlong(Stringb)

public static void


sortWord(String b)

public static void Int h,s To store value of


shortlong(Stringb) longest and shortest word

public static void String lw,sw,k To store longest and


shortlong(Stringb) shortest word and each
word of the
Sentence

public static void String arr[] Array to store the


sortWord(String b) sentence in alphabetical
order.

public static void Int c,p To store length of array


sortWord(String b) and to add the word to
array.

11
QUESTION 2
Write a program in Java which would accept a word and two characters. Then it would
find the first character in the word and replaces it with every time with the second
character. Your program should display the new word after replacement on the screen.

12
Algorithm
STEP 1: Start
STEP 2: Import java.utility package .
STEP 3: Make a class named Program 2.
STEP 3: Make a main method named public static void main.
STEP 4: Make an object of scanner class named sc.
STEP 5: Make a integer variable named i&len.
STEP 6: Make String variable a,b and initialize b to null.
STEP 7: Make character variable ch1 & ch2.

STEP 8: Print a sentence “Enter a word”.


STEP 9: Initialize value of a to user given input.
STEP 10: Print a sentence to ask for the first and the second character where position of first number is to
be swapped with second number.
STEP 11: Initialize value of first character to ch1 , second character to ch2 & len to a.length().
STEP 12: Initialize a character variable x to a.charAt(i).
STEP 13: Check if value of x is equals to ch1.If so, then assign b to b+ch2.Else assign b to b+x.
STEP 14: Initialize value of I to 0 & till i<len , and keep increasing value of i by 1 , then go to STEP 12.
STEP 15: Print the new word with new value of b.
STEP 16: Close main method and class
STEP 17: Stop.

13
SOURCE CODE

14
OUTPUT

15
Variable Listing

Member Methods Data Type Variable name Use

public static void Int I Loop variable


main()

Len To store length of word

String A To accept the


word from the
user

B To store the new word

Char c1 To accept two


character from the
user

c2

16
QUESTION 3
Write a program in Java to accept a word to display the inverted right triangle with its
letters in such a manner that it would begin with all the letters in the first row and then
with every passing row, it would remove one character from the left.

17
ALGORITHM
STEP 1: Start.
STEP 2: Import a package of java.utility.
STEP 3: Make a class named Program_3.
STEP 4: Make a main method of public static void main().

STEP 5: Make an object of scanner class named sc.

STEP 6: Print a sentence “Enter a word”.


STEP 7: Make a String variable named a and assign its value to user given input.
STEP 8: Make Integer variable named i & len.
STEP 9: Print a.substring(i).
STEP 10: Assign value of I to 0 & until i<len , Keep increasing value of i by 1 and go to STEP 10.
STEP 11: Close main method and class.
STEP 12: Stop.

18
SOURCE CODE

19
OUTPUT

VARIABLE LISTING
Member methods Variable Types Variable Name Use

Void main () Int I Loop Variable

Len To store the length of


the string

String A To accept the word from


the user

20
QUESTION 4
Using the switch statement, write a menu driven program in Java to:
I. 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
II. Find the sum of the digits of an integer that is input

21
ALGORITHM
STEP 1: Start.
STEP 2: Import a package of java.utility.
STEP 3: Make a class named Program_4.
STEP 4: Make a main method of public static void main().
STEP 5: Make an object of scanner class named sc.
STEP 6: Make Integer Variable ch,a,b,c, sum which is initialized to 0 & n which is initialized to 3
STEP 7: Print a sentence for the user to pick two choices of either printing Fibonacci series or Sum of digits of number .
STEP 8: Read the value of option chosen by the user to ch.
STEP 9: Use a switch statement to read value of ch.
STEP 10: Make Case1 where assign a to 0 , b to 1.
STEP 11: Print Value of a & b in a single line.
STEP 12: Assign c to a+b
STEP 13: Print c in the same line.
STEP 14: Then reassign the value of a to b and b to c and increase value of n by 1.
STEP 15: While value of n<= 10 , go to STEP 12. And then use a break statement.
STEP 16: Make Case 2 where Print a sentence to get the number whose Digts are to be added.

STEP 17: Make a integer variable ‘a’ & read the user input and assign it to a.
STEP 18: Assign value of sum to sum+x%10.
STEP 19: Assign value of x to x/10;
STEP 20: Print the sum.
STEP 21: Use break statement to get out of the switch statement .
STEP 22: If no case match show Wrong choice.
STEP 23: Close the main method and class.
STEP 24:Stop.

22
SOURCE CODE

23
OUTPUT

24
VARIABLE LISTING

Member Data type Variable Name Use

Methods

Public static Int ch To check the


void main ()
user option

a To store value of first


number of
Fibonacci Series

b To store value of
Second number of

Fibonacci series

c To store value of third


number of
fibonacci Series

sum To store sum of


digits

n Loop variable

x To store the number

25
QUESTION 5
Design a class Tour with the following descriptions:
Class Name: Tour Data
Members:
I. int pass_num -Stores the number of passenger
II. String name -Stores the name of passenger
III. int age- Stores the age of passenger
IV. double ticket_amt -Stores the ticket price double disc Stores the discount, if any Member Methods:
I. void Accept( ) --To input the passenger number, name, age and ticket price
II. void Discount() -To calculate the discount and modify the ticket_amt as per the rule: if age>=60, discount=50%
of the ticket amount.
III. void Display()- To display the member data with output statements. Also print
“Discount given” if applicable.
IV. void main()- To create an object of the class and call the member methods.

26
ALGORITHM
STEP 1: Start.
STEP 2: Import java utility package.
STEP 3: Make a java class named Tour.
STEP 4: Make data members pass_num and age of Integer type, Name of String type and ticket_amt and disc of double
type.
STEP 5: Make a method void Accept().
STEP 6: Make an object of Scanner class named sc.
STEP 7: Ask the user for Name, Ticket Number, Age and Ticket Price.
STEP 8: Assign the values to name ,pass_num , age and ticket_amt.
STEP 9: Close the method.
STEP 10: Make a method void Discount().

STEP 11: Check whether Passenger’s age is above or equal to 60 or below 13 years or not.
STEP 12: If above 60,then discount would 50%,if below 13,then discount would be 40% or else no discount. Ticket price
would be Ticket price-discount.
STEP 13: Close the method.
STEP 14: Make a method Display().
STEP 15: Print all the Passenger details like Name, Age ,Passenger number, Discount and Ticket price
STEP 16: Close the method .
STEP 17: Make an object of class Tour named obj and use it to call other methods.
STEP 18: Close the method and class.
STEP 19: Stop

27
SOURCE CODE

28
OUTPUT

29
VARIABLE LISTING
Class Data type Data member Use

Tour Int pass_num To store ticket number

age To store age

Double disc To store discount

ticket_amt To store ticket amount

String name To store name of


passenger

30
QUESTION 6
Define a class Benefit as described below:
Data Members:
i. Salary(double),
ii. Bonus,(double)
iii. Amount(double)
Member Methods:
i. Benefit(double,double) - Parameterized constructor to initialize salary and bonus
ii. Evaluate() - To evaluate the value of Amount using Amount=Salary +
Bonus
iii. Display() - To display the data members Write a main method to create an object of the class
Benefit and call the above member methods.

31
ALGORITHM
STEP 1: Start.
STEP 2: Import java Utilitiy package .
STEP 3: Make a class Benefit.
STEP 4: Make data member named Salary, Bonus and Amount of double type.
STEP 5: Make a parameterized constructor named Benefit(double s, double b).
STEP 6: Accept Salary to s and Bonus to b.
STEP 7: Close the constructor.
STEP 8: Make a method Void Evaluate () to calculate Amount that is Salary + Bonus.
STEP 9: Make a method void display to Print Amount, Salary and Bonus.
STEP 10: Make a main method .
STEP 11: Make an object of class Scanner named sc.
STEP 12: Ask the user for Salary and Bonus .
STEP 13: Store the values in the double type variables sal and bon.
STEP 14: Make an object of Class Benefit and Call the constructor and method.
STEP 15: Close the method and class.
STEP 16: Stop.

32
SOURCE CODE

33
OUTPUT

34
VARIABLE LISTING
Class Data type Data member Use

Benefit Double Salary To store salary

Bonus To store Bonus

Amount To store total


amount given to
employee

35
QUESTION 7
Define a class Report, described as below:

Data Members:

i. MarkSub1 (double),
ii. MarkSub2 (double),
iii.MarkSub3(double),

iv. Average (double)

Member Methods:

i. Report (double, double, double) Parameterized constructor to initialize marks in three subjects
ii. Calculate () To calculate the average of the three subjects
iii. Display() To display all the member data

Write a main() method to create an object of class Report and call the above member methods.

36
ALGORITHM
STEP 1: Start.
STEP 2: Import java utility package.
STEP 3: Make Data members MarkSub1,MarkSub2 & MarkSub3 of Double type.
STEP 4: Accept value of MarkSub1,MarkSub2 & MarkSub3 to ms1,ms2 & ms3.
STEP 5: Make a method void Calculate() to calculate average marks of three subjects .
STEP 6: Make method Display() to Print marks of three subjects and average.
STEP 7: Make a main method .
STEP 8: Make an object of scanner class named sc.
STEP 9: Ask the user for the marks of three subjects and Assign the marks to MS1,MS2 &MS3.
STEP 10: Create an object of class Report named obj and use it to call the constructor and the member methods
STEP 11: Close method and class.
STEP 12: Stop.

37
SOURCE CODE

38
OUTPUT

39
VARIABLE LISTING
Class Data type Data members Use

Report Double MarkSub1 To store Marks of


Subject 1

MarkSub2 To store Marks of


Subject 2

MarkSub3 To store Marks of


Subject 3

Average
To store an average of
the three subjects

40
CONCLUSION
By doing this amazing project on arrays and String values of java, I was able to
develop a deep sense of these types of programs thus now I am a better
Programmer than before by doing and learning these types of programs by this
Project. Now I am much more confident than before in doing such programs. This
project has literally helped me a lot in understanding tha java language properly
and to be more precis quickly.

41
BIBLIOGRAPHY
I would like to express my sense of gratitude and appreciation to my respected
teacher as well as to my beloved friends and family.
Some of the given websites from whom I have taken help are following:
i) www.codecademy.com
ii) www.leetcode.com
iii) www.programiz.com
iv)www.codechef.com

42

You might also like