Grade 10 Journal Questions
1. Do not write the dates for the Assignment.
2. Each Assignment must start from a new page.
3. Use only Black ball pen.
4. Question and coding to be written on the right hand side.
5. Output and Variable Description table to be written on the left hand side with pencil.
(Format of variable description as given in the scope of syllabus).
Assignment 1
User defined methods
Create a function void PrintHCF(int x, int y) to find and print HCF/GCD of x and y using
Eucild’s method (or remainder method). Also, write a main function to input the two integers
and print their HCF.
Hint :
1. Decide the greater from two numbers.
2. Divide the greater number by smaller number, if remainder is zero, print divisor
(smaller number) as HCF, otherwise
3. Take divisor as number and remainder as divisor, and repeat steps 2 and 3.
Assignment 2
User defined methods
Design a class sample for the following functions to print cash memo for a product
purchased from a shop:
(i) void product() : create this function with product code (integer), unit price of
product (float) and quantity of product (float) as parameters or arguments.
Calculate total cost of the product, discount as 12% on total cost and net price to be
paid for the product. And print all the data members including total, discount and
net price of product with suitable messages.
(ii) void main() : to invoke function product() by passing required values to this
function.
Assignment 3
User defined methods : Call by value (or Pass by value) program
Design a class Distance along with a function double distance() with three parameters u, time
and acc of double types to find and return the value of d from the following relation :
1 2
d=ut+ a t
2
Also, write a main() function to input velocity (v), time (t) and acceleration (a) and by
invoking function distance(), print the value of d including v, t and a.
Assignment 4
User defined methods : Programs based on overloaded methods
Design a class to overload a function series() as follows:
(i) double series(double n) with one double argument and returns the sum of the series.
sum = 1/1 + 1/2 + 1/3 + ….. 1/n
(ii) double series(double a, double n) with two double arguments and returns the sum of the
series. sum = 1/a2 + 4/a5 + 7/a8 + 10/a11 ….. to n terms
Assignment 5
User defined methods : Programs based on overloaded methods
Design a class to overload a function area() as follows :
(i) double area(double a, double b, double c) with three double arguments, returns the
area of a scalene triangle using the formula:
a+ b+c
area=√ s ( s−a ) ( s−b ) ( s−c ) where s= 2
(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a
trapezium using the formula:
1
area= height ( a+b )
2
(iii) double area(double diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:
1
area= ( diagonal 1× diagonal 2 )
2
Assignment 6
User defined methods : Programs involving data members, member methods involving
the methods with respect to the object created.
Define a class called BookFair with the following description :
Instance variables/data members :
String Bname : stores the name of the book
double price : stores the price of the book
Member methods :
(i) void input() : to input and store the name and price of the book
(ii) void calculate() : to calculate the price after discount. Discount is calculated
based on the following criteria.
Price Discount
Less than or equal to ₹ 1000 2% of price
More than ₹ 1000 and less than or equal to ₹ 3000 10% of price
More than ₹ 3000 15% of price
(iii) void display() : to display the name and price of the book after discount
Write a main method to create an object of the class and call the above member methods.
Assignment 7
User defined methods : Programs involving data members, member methods involving
the methods with respect to the object created.
Sponge Iron Company announces an increment for their employees on seniority basis as per
the given conditions:
Age Increment
56 year and above 20% of basic
Above 45 and below 56 years 15% of basic
Upto 45 10% of basic
Write a program to find new basic by using the following class specifications:
Class : Increment
Data members/Instance variables :
String name : Name of the employee
double basic : Basic pay of the employee
int age : Age of the employee
Member methods:
void getdata(String n, double b, int a) : To accept name, basic and age of the employee
void calculate() : To find increment and update basic.
void display() : To display age and updated basic in the format given below:
Name Age Updated Basic
xxxxx xxxxx xxxxx
Assignment 8
Constructors : Programs based on default constructor
Define a class named BookFair with the following description:
Instance variables/Data members:
String Bname – stores the name of the book.
double price – stores the price of the book.
Member Methods:
(i) BookFair() – Default constructor to initialize data members.
(ii) void Input() – To input and store the name and the price of the book.
(iii) void calculate() – To calculate the price after discount. Discount is calculated based on
the following criteria.
PRICE DISCOUNT
Less than or equal to Rs.1000 2% of price
More than Rs.1000 and less than or equal to Rs.3000 10% of price
More than Rs.3000 15% of price
(iv) void display() – To display the name and price of the book after discount.
Write a main method to create an object of the class and call the above member methods.
Assignment 9
Constructors : Programs based on parameterized constructor
Define a class ‘Student’ described as below:
Data members/instance variables : name,age,m1,m2,m3 (marks in 3 subjects), maximum,
average
Member methods :
(i) A parameterized constructor to initialize the data members.
(ii) To accept the details of a student.
(iii) To compute the average and the maximum out of three marks.
(iv) To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.
Assignment 10
Constructors : Programs / outputs based on constructor overloading
Create a class circle to find the area of a circle using : area=π radius 2
The instance variables of class are radius and PI. Its member functions are as follows :
(i) circle() : default constructor to assign 3.141 to PI.
(ii) circle(float R) : to store value of R to variable radius.
(iii) float FindArea() : to calculate the area of circle and return.
Write a main function to input radius of circle, create object and call the methods to print
output.
Assignment 11
Library classes : Outputs based on all the methods
Find the output of the following program snippets:
1. char ch1 = '*';
boolean b = Character.isLetter(ch1); false
boolean p = Character.isWhitespace(ch1); false
System.out.println(b);
System.out.println(p);
2. String s = "7";
int t = Integer.parseInt(s); 1007
t = t + 1000;
System.out.println(t);
3. int f = 97;
AGreat Victory
char ch2 = Character.toUpperCase((char)f);
System.out.println(ch2 +"Great Victory");
4. char ch3 = 'A';
char chr = Character.toLowerCase(ch3); A a
int n = (int)chr-32;
System.out.println((char)n+ "\t"+chr);
5. char ch4 = '9';
boolean c = Character.isDigit(ch4); true
System.out.println(c);
Assignment 12
Library classes : Outputs based on all the methods
Find the output of the following program snippets:
1. char ch5 = '*';
false
boolean d = Character.isLetterOrDigit(ch5);
System.out.println(d);
2. char ch6 = 'a';
boolean e = Character.isLowerCase(ch6); true
System.out.println(e);
3. char ch7 = 'A';
true
boolean g = Character.isUpperCase(ch7);
System.out.println(g);
4. String s1 = "25", s2 = "47235";
int x = Integer.parseInt(s1); 25
long h = Long.parseLong(s2); 47235
System.out.println(x);
System.out.println(h);
5. String a = "23.3f", j = "675.123";
float i = Float.parseFloat(a); 23.3
double db=Double.parseDouble(j); 675.123
System.out.println(i);
System.out.println(db);
Assignment 13
Library classes : Programs to check whether a given character is an
uppercase/lowercase/digit etc
Write a program to define a function void Show(char ch) to print whether the character
argument ch is an uppercase letter or a small letter or a letter/digit or space character.
Assignment 14
String handling : Outputs based on all the string methods
Predict the output of the following:
1. boolean p;
false
p = ("BLUEJ".length() > "bluej".length()) ? true : false;
System.out.println(p);
2. String x = "Vision", y="2020";
System.out.println(x + y); Vision2020
System.out.println(x.length()); 6
System.out.println(x.charAt(3)); i
System.out.println(x.equals(y)); false
3. String n= "Computer Knowledge", m = "Computer Applications";
System.out.println(n.substring(0,8).concat(m.substring(9))); ComputerApplications
System.out.println(n.endsWith("e")); true
4. System.out.println("MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')); 12
5. System.out.println("CABLE".compareTo("CADET")); -2
6. String a = "Smartphone", b = "Graphic Art";
String h = a.substring(2,5);
String k = b.substring(8).toUpperCase(); art
ART
System.out.println(h);
true
System.out.println(k);
System.out.println(k.equalsIgnoreCase(h));
7. System.out.println("ACHIEVEMENT".replace('E','A')); ACHIAVAMANT
System.out.println("DEDICATE".compareTo("DEVOTE")); -18
8. String s = "Examination";
int n = s.length();
System.out.println(s.startsWith(s.substring(5,n))); false
System.out.println(s.charAt(2)==s.charAt(6)); true
9. String s1 = "1001", s2 = "13.45";
int x = Integer.valueOf(s1);
x=1001
double y = Double.valueOf(s1);
y=1001.0
float z = Float.valueOf(s2);
z=13.45
System.out.println("x="+x);
System.out.println("y="+y);
System.out.println("z="+z);
10.String s3 = "COMPUTER", s4 = "computer";
int a = s3.compareToIgnoreCase(s4); 0
System.out.println(a);
11.String st = " COMPUTER ";
String p = st.trim(); Original string: COMPUTER
System.out.println("Original string: " +st); String after truncation: COMPUTER
System.out.println("String after truncation: " +p);
12.String str = "COMPUTER";
computer
String p1 = str.toLowerCase();
System.out.println(p1);
Assignment 15
String handling : Programs based on extracting the characters from a given string and
manipulating the same.
1. Write a program to accept the name of a person’s first, middle and last names and
print its short form.
Sample Input : Subhash Chandra Bose
Sample Output : S.C.Bose
2. Write a program to accept a String in lower case and replace ‘e’ with ‘*’ in the given
String. Display the new string.
Sample Input : computer science
Sample Output : comput*r sci*nc*
Assignment 16
String handling
1. Write a program to input a word and check whether the word is a Palindrome or not.
Sample Input : madam
Sample Output : madam
(A word is said to be Palindrome, if it reads same after reversing the characters).
2. Write a program to input a word and display the same in Pig Latin format.
Sample Input : print TROUBLE
Sample Output : intpray OUBLETRAY
A word is converted into its Pig Latin form by suing the following steps:
Find the index of the first vowel.
Obtain two substrings ; one (say, s1) by using the characters from beginning till index
of first vowel -1 and other (say, s2) by suing the characters from index of vowel till
end of the string.
Find s3 = s2 + s1 + “AY”
The resulting string s3 will be in Pig Latin form of the given string.
3. Write a program to create a class ArrangeLetters and a method Arrange() with a string
parameter. Convert the word into capitals. Arrange each letter of the word in
alphabetical order. Print the word before and after arranging letters in A-Z order.
Example : Input : BaSIca Input word : BaSIca
Word in capitals : BASICA
Word after sorting : AABCIS
Assignment 17
Arrays : Programs based on accessing the elements of an array.
1. Write a program to accept n numbers into an array and then calculate the sum of even
numbers present in odd positions.
2. Write a program to initialize the given data in an array and find the minimum and
maximum values along with the sum of the given elements.
Numbers : 2 5 4 1 3
Output : Minimum value : 1
Maximum value : 5
Sum of the elements : 15
Assignment 18
Arrays : Programs based on sort and search techniques
1. Write a program to accept a set of 10 integers in a Single Dimensional Array (SDA).
Sort the numbers in ascending order by using the ‘Bubble Sort’ technique. Display the
sorted array.
2. Write a program to accept 10 different numbers in a Single Dimensional Array (SDA).
Arrange the numbers in ascending order by using the ‘Selection Sort’ technique and
display them.
3. Write a program to input 10 integers in an array and a number to search and print
whether the number is present in the array or not using ‘Linear Search’ technique.
4. Write a program to input a number and search it from the given elements using
‘Binary Search’ technique. If it is found display the element along with its position,
otherwise display the message “Search element not found”.
Assignment 19
String handling with array
1. Write a program to accept 10 states and their capitals in two different Single
Dimensional Arrays. Now, enter the name of a state and search it in the given list of
state names. If it is present then display its capital, otherwise display “State name is
not enlisted”.
2. Write a program to accept 10 different city names in a Single Dimensional Array
(SDA). Arrange the names in ascending order by using the ‘Bubble Sort’ technique
and display them.
Assignment 20
Double Dimensional array
Write a program to input a double dimensional array of N rows and N columns. Perform the
following tasks:
(a) To accept elements into an array.
(b) Print the array in the form of matrix of N x N.
(c) Print sum of left diagonal and sum of right diagonal of the matrix.
*****
import java.util.*;
public class circle
{
static double PI;
float radius;
circle()
{
PI=3.141;
}
circle(float R)
{
radius=R;
}
public float FindArea()
{
float ar;
ar=(float)PI*(radius*radius);
return ar;
}
public static void main(String args[])
{
float r,area;
Scanner sc = new Scanner(System.in);
System.out.println("Input value of the radius: ");
r=sc.nextFloat();
circle obj=new circle();
obj=new circle(r);
area=obj.FindArea();
System.out.println("Area of circle is =" +area+ "whose radius is" +r);
}
}