Professional Documents
Culture Documents
Reetabrata 1st Term Com Cls X
Reetabrata 1st Term Com Cls X
[BLUE J]
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!
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
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
alphabetically.
3
ALGORITHM
STEP 1: Start
STEP 11: Print a sentence “Number of letters in the sentence are :” and the print alpha.
STEP 13: Print a sentence “Number of words in the sentence are :” and the print wrd.
STEP 15: Close main method and make new method public static int letter(String b).
STEP 23: Close the method and make new method public static int word_Count(String b).
STEP 28: Initialize i to 0 and keep adding 1 to it everytime until i<l and keep repeating STEP 28 to 30
STEP 33 : Close the method and make new method public static void short long(String b).
STEP 35: Make String variable lw,sw,k and initialize them to “”.
STEP 38: Initialize i to 0 and keep adding 1 to it everytime until i<l and keep repeating STEP 38 to 44.
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 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 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.
6
SOURCE CODE
7
8
OUTPUT
9
VARIABLE LISTING
public static
word_Count
(String b)
public static
word_Count
(Stringb)
public static void
shortlong (Stringb)
10
public static Char X To store each
word_Count(String b) character of the
sentence
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.
13
SOURCE CODE
14
OUTPUT
15
Variable Listing
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().
18
SOURCE CODE
19
OUTPUT
VARIABLE LISTING
Member methods Variable Types Variable Name Use
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
Methods
b To store value of
Second number of
Fibonacci series
n Loop variable
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
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
35
QUESTION 7
Define a class Report, described as below:
Data Members:
i. MarkSub1 (double),
ii. MarkSub2 (double),
iii.MarkSub3(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
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