0 ratings0% found this document useful (0 votes) 218 views45 pagesClass 10 Computer Solved 1-3
FRANK Computer Solved 1-3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Model Test Paper
(Solved)
SECTION A (40 Marks)
Attempt all questions.
QUESTION 1.
Choose the correct answer and write the correct option. (20)
(i) The small individual unit used in java program having some meaning to its language
compiler is termed as.
(a) Operators
(6) Keywords
(©) Identifiers
(d) All the above
Ans: (d) All the above
[Note: Smallest individual unit used in java program is known as token. Ex: Operators,
Keywords, Identifiers etc.]
(ii) Java Interpreter which converts java byte code to Machine code is known as:
(@ Library Class
() JVL
(c) JVM
(d) API
Ans: (c) JVM
(iii) ______ is an assignment operator.
(a) =
)
(o) I=
(d) All the above
Ans: (b)
INote: are the relational operators.)
(iv) Math.cbrt(64.00) results to.
(@) 8
() 2
() 32Model Test Papers 185
(a4
Ans: (d) 4
fo) Number of bytes occupied by char chl] with size 10.
fa) 20
(b) 30
(co) 40
(d) 50
Ans: (a) 20
[Note: char occupies 2 bytes in memory hence, 2 *10 = 20)
(vi) A method with same name as of its class name is termed as
(a) Method overloading
(6) Parameterised method
(©) Constructor
(d) Package
Ans: (b) Constructor
(vii) When a primitive data type is converted to the corresponding object of its class, it is
termed as:
(a) Boxing
(b) Explicit type conversion
(©) Unboxing
(d) Implicit type conversion
Ans: (a) Boxing
[Note: Explicit Type Conversion: Converting a higher data type into lower type forcefully by
the user is known as Explicit conversion or type casting.
Unboxing: Converting an object of a Wrapper class (Integer) to its corresponding primitive
typelint) is known as Unboxing]
Implicit Type Conversion: The conversion in which the lower data type gets converted to
higher data type. Data type without any intervention by the user is known as Implicit Type
Conversion.]
(viii) To find length of the array.
(a) size
(b) concate
fo) length
(d) length
Ans: (d) length
(ix) Parameters used at function definition:
(a) Actual Parameters
(6) Formal Parameters
(c) Default parameters
(d) None the above
Ans: (b) Formal Parameters186 ICSE Computer Applications Papers
[Note: Actual Parameters - Parameters used at function call side.
Deafault parameters - No parameters used within the function
(x) If a=10,
result of a*= a++ - +4b 4a;
ja) 18
(b) 0
ic) 180
(d) 12
Ans: ‘c) 180
[Working: a=10*(10 - 3 + 11), a= 10*18, a=180]
xi) Method to convert String to lowercase is
‘a) TolowerCase()
(b) toLowerCase()
(ec) tolowert)
(d) tolowercase()
Ans: (b) toLowerCase()
(xii) The element in a[3+1] of the array (1,3,5,7,9,11,13) is:
@ 7
(b)
i}
(dd)
Ans: (c) 9
(ziti) The output of the method “COMPUTER APPLICATION" substring(0,11) is:
(a) COMPUTER APPL
(») COMPUTER AP
(c) COMPUTER APP
(d) COMPUTER A
Ans: (b) COMPUTER AP
(xiv) The corresponding wrapper class of the int data type is:
Koos
(a) Integer
(b) INTEGER
(c) Int
d) int
Ans: (2) Integer
(av) Number of bits occupied by double type variable
(a) 8
(b) 16
(e) 32
(d) 64
Ans: (4) 64
INote: 1 byte = 8 bits hence, double data type holds 8 bytes=8 x & bits=64 bits)Model Test Papers 187
ee
(xvi) class A
f
int a=5;
public void disp()
t
!
}
Identify the scope of the variable a.
(a) Instance variable
(b) Class Variable
(c) Local Variable
(d) None of the above
Ans: (a) Instance variable
(xvii) The return type of the library function compareTo() is:
(a) boolean
(6) int
(c) char
(d) string
Ans: (b) int
(xviii) for(; i<=10;i+4)
which expression is missing in the given loop?
(@) Test expression
(b) Update expression
(©) Initialisation expression
(d) None of the above.
Ans: (c) Initialisation expression
(xix) The loop with no end is known as:
(a) Delay loop
(b) Empty loop
(©) Infinite loop
(d) None the above
Ans: (c) Infinite loop
(xx) The default initial value of a boolean data type:
(@) true
() false
(© 0
@i
Ans: (b) false—_ az
= ICSE Computer Applications Papers
eee
QUESTION 2—__
(Name any tw
0 OOP principles. i
Ans. Encapsulation and Inheritance. Some other OOP principles are classes, objects,
polymorphism, abstraction,
, ete
(ii) State the difference between constructor and method. @
Ans.
Constructor Method
(© A constructor will be automatically
invoked when an object is created.
(i) A constructor needs to have the
same name as that of the class.
(i) Methods have to be invoked
explicitly.
(ii) Methods can have any user-defined
name other than the class name.
Gil) State one similarity between while and do-while loops.
[2]
Ans. Similarity: Both are conditional iterative structures.
Difference: In the while loop, the condition is checked at the top of the loop and
the body of the loop is executed only if the condition is true. It is called an entry-
controlled loop.
In the do-while loop, the body of the loop is executed at least once even if the
condition is not satisfied because the condition is checked at the bottom of the loop.
It is called an exit-controlled loop.
(iv) Write one-word answers for the following: (2)
(i) A method that converts a string to a primitive integer data type.
(ii) The default initial value of a Boolean variable data type.
Ans. (i) Integer.parseint( ) (ii) false
(v) Write the Java statements to print the evaluated results of the following arithmetic
expressions. (2)
1 .) (a+b)"
@ ut + get (ti) x Wee
Ans. (i) utttstartrt (ii) x-Math.pow( (a+b) ,n) /Math. sqrt (3) +b
(vi) Name two types of Java programs. 12)
‘Ans. Two types of Java programs are Internet Applets and Stand-Alone Applications.
(vii) Explain the term ‘type casting’. 2)
Ans, It is the conversion in which the higher type data gets converted forcefully by the
user to its lower type.
Example: double y-5.0/int x7
x= (int) ys
System.out.println (x) 7
Output: 5
ere the higher-type data double got converted forcefully by the user to lower type,
ie. int)Model Test Papers io
(viii) Name the following: a
(i) A package that is invoked by default.
(ii) A keyword to use the classes defined in a package.
Ans. (i) java.lang (ii) import
(ix) Differentiate between pure and impure functions. (2)
Ans. Pure Function Impure Function
(i) It does not change the value of the | (i) It changes the value of the
arguments that are passed to it. arguments that are passed to it.
(i) It always returns a value. (ii) It may or may not return a value.
(x) Differentiate between primitive data type and user-defined data type. [2]
Ans. Primitive Type User-defined Type
(i) It is a fundamental data type. (i) A reference data type is a user-
defined data type constructed
from primitive data types.
(ii) The size of these data types is fixed| (ii) The size of these data types is
Ex: int, float, char, ete... variable as their size depends
upon their constituent member,
Ex: class, object, array, ete
SECTION B (60 Marks)
Attempt any four questions from this section,
The answers in this section should consist of the programs in either Blue
environment or any program environment with Java as the base. Each program
should be written using Variable Description / Mnemonic Codes such that the logic
of the program is clearly depicted. Flowcharts and Algorithms are not required.
QUESTION 3 —————————————
Write a program to enter 10 different numbers in ascending order in a single dimensional
array (SDA) and search whether a number given by the user is present or not, using
binary-search technique. If the number is present then display the message
Successful”, otherwise “Number is not present”. (151
earch190
Static void main(String args{])
new Scanner (System. in);
mew int [10],i,1=0,u=9,m, item, £=|
out-printin(™
Enter any 10 numbers in ascending order”);
Fisl0; i++)
nlil=sc.nextint ();
System.out.printin ("Enter an item to search");
item=se.nextint ()7
while (1<=u)
m= (1+u) /
(n[m] >item)
usm-1;
£(f
System.out
rint1n (“Search Successful");
out.printin ("Number is not present”);
tem.out. rModel Test Papers
Variable Description
Variable Name | Data Type | Description
nf) int to store 10 integers
item int to store the value to search
i int to run the loop
1 int to store the lowest index position
u int to store the upper index position
m int to store middle index position
f int to store the flag value, i.e. 0 for false
and 1 for true
Write a program to input a sentence and display the toggled sentence.
Input: WelCome to School
Output: wELcOME TO sCHOOL (15)
Ans, import java.util.*
class toggleSentence
{
public static void main(String args[])
Scanner sc=new Scanner (System. in) i
String s,sl=""7
char chi
int i;
System.out.println ("Enter any sentence”);
s=sc.nextLine();
for (i=0;i5éed<=15)
£=5*0.50+(d-5)*1.50;
else if(d>154sd<=20)
£=5*0.50+10*1.50+(d-15) *2.00;
else
£=5*0.50+10*1.50+5*2. 00+ (d-20) *2.507
System.out.printin (“The Fine Amount:"+f);
Variable Description
Variable Name | Data Type | Description
a int to store the number of days
f double to store the fine amount
Define a class overload a function series () as follows to display the sum of the series:
i. void series (int x,int n) 15)
ala? + oat ia
ii. void series (int n)
235813.
iii. void series ()
1/2 + 2/3 + 3/4 44/5 ...00000
Write main method to invoke the above methods,
import til.*7
class overload
void series(int x, int n)
{
int i,s=0;196 ICSE Computer Applications Papers
ob.series(x,n);
M.out.printin(*Series ii-Enter the value of n");
n=sc.nextint ();
ob. series (
ystem.out.printin("\nSeries iii”);
series();
)
Variable Description
Variable Name | Data Type | Description
int To store value of x in the series
n int To store value of n in the series
i int To run the loop
s double To store sum of the series
QUESTION 8
Define a class to input integer elements into an array of size 20 and perform the
following operations. (15)
i. Display the largest number from the array.
ii. Display the smallest number from the array.
iii, Display the sum of all the elements of the array.
ort java.util.
class Number
void main(String args[])
Scanner sc=new Scanner (System. in);
int ar[]=new int(20],i,max,min, sum=0;
System.out.printin ("Enter 20 integers in an array”);
ar[i]=sc-nextint ();
)
max=ar(0)i
min=ar(0]i
for(i
{
i<20;i++)
if (ar (il>max)Model Test Papers —
_—_c rre_er'seorerereeeeeerr
max=ar (i);
if (ar[i]80000)
allow(i]=basic[i]*0.30;
else if(basic[i]>50000 && basic[i]<=80000)
allow(i]=basic(i]*0.25;
else if(basic[i}>30000 4% basic{i]<=50000)
allow[i]=basic[i]*0.18;
else
allow[i]=basic{i]*0.1
picn-1;i++)
for (}=07 j1800?500:300;
System. out.printin(s)+
Ans. (i) 300
(i) 500
(vii) What is the function of the new operator? 2)
‘Ans. The new operator is used to create an object of a class and associate the object
with a reference variable that names it, eg.,
ew Kps(); //a new object of class Kps is created and
the reference variable ob is associated with it.
(viii) What is a Wrapper class? Give an example. 7
‘Ans. Java's primitive data types are data values and not class objects. Wrapper classes
convert primitive data types as objects. We can create an object of byte type from its
wrapper class as follows:
(5);//a Byte object created having value 5.Model Test Papers 29
tix) Differentiate between equala() and compareTo () methods. fa)
equala) compare Tot)
() It checks the equality between 7) It also checks the other relations
two strings. between two strings.
(2)_Tt returns boolean type of value, (ii) It returns integer type of value.
(x) What is a default constructor? fay
Ans, A default constructor is a constructor which does not have any parameters but
initialises the instance variables with default values. It is automatically executed at
run time.
SECTION B (60 Marks)
Attempt any four questions from this section.
The answers in this section should consist of the programs in either BlueJ
environment or any program environment with Java as the base. Each program
should be written using Variable Description /Mnemonic Codes such that the
logic of the program is clearly depicted. Flowcharts and Algorithms are not
required.
Write a program to enter any sentence and display the frequency of each character.
U5)
Ans. import java.util.
class charFreq
{
public static void main(String args(])
{
Scanner sc=new Scanner (System. in);
string si
int 1,i,c=1/37
system.out printIn("Enter any sentence :");
s=sc.nextLine()i
slengthQ)s
char ch [J=new char[1],t7
pislsitt)
ch[i]=s-charAt (1)ive)
if(ch{j}>ch{541])
{
tech{jle
eh(3)=ch(5+11
chij+1]=te
}
)
for (i=0;i<1-1; i++)
if (ch[i]==ch[i+1])
cH:
else
System.out.println (“Frequency of\t"+ch[i] +”\t"+c);
1
9
)
System.out .print1n(*Frequency of\t"tch[i]+"\t"+e)
Variable Description
Variable Name | Data Type Deseription |
2 String to accept the sentence
1 int to store the length of the sentence
cht) char to store the characters of the sentence
t char to store the characters temporarily
; int to run the loop
int to run the loop
_ int to count the frequency of each character
QUESTION 4:
Write a program to enter any number and check whether it is a unique number or not.
(Note: If the number does not contain any duplicate digit, it is called @ unique
number.) (15)Model Test Papers
‘Ans. import java.util.*
class UniqueNo
(
public static void main(String args{])
{
Scanner sc=new Scanner (System. in);
int n,num,k,i,c, f=1,d,d1;
system.out.print1n (“Enter any number:”);
n=sc.nextInt ();
ken;
while (n!=0)
{
d=n810;
c=;
num=k;
while (num!
a
di=nums10;
if (d==d1)
ott:
num=num/10;
}
if(e
(
n=n/10;
continue;
}
else
{
£20;
break;
}
if (f==1)
System.out.println("Unique number");
else
System.out.printIn ("Not a unique number”);2 ICSE Computer Applications Papers
ee ee
Variable Description
Variable Name | Data Type | Description
n int to accept the number
num int to store the number
c int to count the frequency of digits
int to store the true or false state, i.e 1 or 0
int to store the digits of the number
al int to store the digits of the number
k int to store the number temporarily
Write a menu-driven program to find the area using function overloading passing the
required parameter to each method. U5)
1, Area of Square
2. Area of Rectangle
3. Area of Circle
4. Area of Triangle
Ans. import java.util.*;
class Shape
public void Area(int s)
‘
int a;
a=s*s;
System.out.println("Area of Square:”+a);
}
public void Area(int 1,int b)
System.out.println("Area of Rectangle:”+a);
}
Public void Area (double r)
(
double a;
a=3.14trer;
System.out.printin ("Area of Circle:”+a);Model Test Papers
public void Area(double ba,double h)
(
,
public static void main(String args{])
(
double a;
a=0.5*bath;
System.out.print1n (“Area of Triangle:"+a);
Scanner sc=new Scanner (System. in);
Shape ob:
ew Shape ();
int ch;
System.out.printin("Enter Your Choice”);
System.out.print1n("l. Area of Square”);
System. out.printin("2. Area
System.out.printin("3. Area
System.out.printin("4. Area
ch=se.nextInt ();
switch (ch)
{
case 1:
int s;
of Rectangle”
of Circle”);
of Triangle”);
System.out.println(" Enter the side of the Square”);
s=sc.nextInt ();
ob-Area(s)7
break;
case 2:
int 1,b;
System.out.printin ("Enter length and breadth of the
rectangle”)
l=sc.nextInt ();
=sc.nextInt ();
ob.Area (1,b)i
break;
case 3:
double r;
System.out.println("Enter the
r=sc.nextDouble (};
ob.Area(r);
break;
case 4:
double h,ba;
radius of Circle :");ICSE Computer Applications Papers
System.out .println ("Enter the height and base of the Triangle”);
h=sc.nextDouble();
ba=sc.nextDouble ();
ob.Area (ba, h);
break;
default:
System. out.print1n ("Wrong Choice");
Variable Description
Variable Name | Data Type | Description
ch int to accept the user's choice
s int to accept the side of the square
1 int to accept the length of the rectangle
b int to accept the breadth of the rectangle
r double to accept the radius of the circle
ba double to accept the base of triangle
h double to accept the height of triangle
(a) Write a program to find the sum of the given series:
S=10-1+9-2+8-3+..41
(b) Write a program to display the first six terms of the given series.
0.5 0.55 0.555 0.5555 0.55555 ... (05)
Ans. (a) class Series
(
public static void main(String args[])
{
int i,k=10,p=1,s=0;
for (isl; i<=10;it+)
(
if(i8
‘
0)
S=s-pi
ptt;
)
elseSystem.out .printin(*Sum:"+s);
Variable Description
Variable Name | Data Type | Description
i int to run the loop
k int to store the integer value
P int to store the integer value
s int to store the sum of the series
Ans. (b) class Seriesi
{
public static void main(String args(})
{
int i;
double s,p=07
for (i=1;1<=6;i++)
{
pep*l0+s;
s=p/Math .pow(10,i)7
System.out.print (st” “)i
Variable Description
Variable Name | Data Type | Description
i int to run the loop
double to store the fractional value
8 double to store the sum
Define a class to accept n number of integers in an array and display largest prime
number present in the array. If no Prime number is found then display the lowest
number present in the list. 05)226
ICSE Computer Applications Papers
EEE
Ans: import java.util.*
class numberArray
{
public static void main(String args{])
{
Scanner sc=new Scanner (System. in);
int ar(],n,i,f
min, j,c,max=07
system.out.println("Enter size of the array”);
c.nextInt () 7
ar=new int(n];
for (i=0;imax)
max=ar lil;
system.out
ntin ("The largest
ime number: ”+max) 7
ntln("The lowest number: ”+min);Model Test Papers
Variable Description
Variable Name
Data Type Description
Bebe
ar{} int An array to store integers
n ‘To store size of the array
max ‘To store maximum element in the array
min ‘To store minimum element in the array
c ‘To count the factors
‘To know the logic state(1-true,0-false]
Write a program to input marked price of a product from the user and calculate and
display the discount amount and the amount after discount paid by the user, where
discount is calculated based on the given conditions.
(15)
Marked Price (in @) Discount %
Up to 5000 4%
5001-10000 8%
10001-20000 10%
Above 20000 12%
Ans: import java.util.*;
class markedPrice
{
public static void main(String args{])
‘
Scanner sc=new Scanner (System.in);
double mp, d=0.0;
system.out .printIn(“Enter marked price of a product");
mp=sc.nextDouble ()
if (mp<=5000)
d=mp*0.04;
else if (mp<
demp* 0.087
else if (mp<=20000)
0000)
demp*0.107
else
d=mp*0.12;
System.out-print1n("The discount amount: +d);
system.out.print1n ("Amount with discount:”+(mp-d))7ICSE Computer Applications Papers
oo a as49311«=__
}
Variable Description
Variable Name i)
le Name | Data Type Description _|
mp double to store marked price |
a double to store discount amount |