0% found this document useful (0 votes)
73 views56 pages

Class 10 Computer Solved 4-7

FRANK Computer Solved 4-7

Uploaded by

debjitdutta556
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
0% found this document useful (0 votes)
73 views56 pages

Class 10 Computer Solved 4-7

FRANK Computer Solved 4-7

Uploaded by

debjitdutta556
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
You are on page 1/ 56
Model Test Paper (Solved) SECTION A (40 Marks) Attempt all questions. QUESTION 1 Choose the correct answer and write the correct option. (20) (i) float type data occupies ____ bits. (a) 4 (b) 32 8 (d) 64 Ans: (b) 32 INote: float size in bytes=4 bytes= 4x 8 bits=32 bits] (ii) Statement encloses multiple lines within a pair of opening and closing curly brackets |). (a) Sequential (®) Iteration Statement (©) Compound Statement (d) Jump Statement (c) Compound Statement The correct if statement for the following ternary statement is: max=(a>b)?a:b (a) iffa>b) ‘System.out.printIn(“greater number:"+max) (©) iffa>d) System.out.printin(a); else System.out printin(®); (©) iffa>d) max=a; else max=b; (d) ifta>b)mi else max=a; Ans: (c) ifla>b) max=a; else max=b; (iv) Math.rint(6.5) results to. (@) 6 (b) 7.0 (©) 60 @7 Ans: (c) 6.0 (Note: returns double data type value to the nearest rounded integer.) (v) Functions having the same names but different signatures defined within the same class is termed as. (@) Encapsulation (b) Funetion Overriding (©) Function Overloading (@) Abstraction Ans: (c) Function Overloading (vi) Output of the following statement: System.out. printin(“Character.toUpperCase(T)); @ 1 @) 0 (o) true (d) false Ans: (c) true (vii) int n{J=(1,2,3,5,7,9,13,16] what is the value of x: x=Math.pow(n{2],nl1); (@ 5 () 6 9 @ 3 Ans: (c) 9 [Note: n[2j=3 and n[1]=2 hence, #°=9] (vili) Collection of same types of values: (@) Class (6) Object (o) Array (@) Package Ans: (c) Array(ix) Ans: (x) Ans: (xi) Ans: (xii) Ans: (xiv) double x=32.7; What is the data type of x? (@) Non Primitive (b) Class (0) Primitive (d) None of the above (©) Primitive What is the output of the following code: for(int a=2;a100¢suw) usmid-1; else if (wt{mid]=, 10000 && amountmarks(}+1]) J=marks [341]; marks {j+1}=temp; templ=name[ m.out.printin("The first 10 heighest scoring marks with their nding names are:”); sci0;it+) intln("Name:”+name[i]+”\tMarks:”+marks[i]); Variable Description Variable Name Data Type Description marks {] double ‘An array to store marks name [] String ‘An array to store names temp double To store marks temporarily templ String ‘To store name temporarily i int To run the loop j int To run the loop QUESTION 4: Using a switch statement, write a menu-driven program to convert a given temperature from Fahrenheit to Celsius and vice versa. For an incorrect choice, an appropriate error message should be displayed. (use the formulae C = 5/9 (F-32) and F = 18 * C + 32) 05)Public static void main(String args(J) { Scanner sc=new Scanner (System. in) double t,cts int ch; System. out.println ("Enter Your Choice”) system.out.printin("1.Convert Celsius to Fahrenheit”); system.out .printin(*2.Convert Fahrenheit to Celsius”); ch=sc-nextint (); switch (ch) { case 1: system.out .printIn ("Enter the temperature in celsius”); tesc.nextDouble(); -8*t+32; ct systen.out.printin ("The temperature in Fahrenheit: "+ct+”£"); break; case 2: systen.out.printla("Enter the temperature in Fahrenheit”); tesc.nextDouble() 7 et=5/9* (t-32)7 system.out .printin ("The temperature in Celsius:”#ctt"c"); break; default: system.out-printin ("Wrong choice”) + Variable Description Variable name Data type Description t double to accept the temperature ct double to store the converted temperature ch int to accept the choice any number from the user and check and display whether it not a Boring Number. eemedans rua number is called boring if all of the digits at even Define a class to input is a Boring Number or [Boring Number: A positive250 ICSE Computer Applications Papers positions in the number are even and all of the digits at odd positions are odd. For example, the number Input: 1478 Output: 1478 is boring number. [As the odd positions include the digits (1, 7/ which are odd and even positions include the digits (4, 8) which are even.] Ans: import java.util.*; Boring clas public static void main(String args[]) Scanner sc=new Scanner (System.in); int n,c=0,d, temp, f=1; System.out.println("Enter any number”); n=sc.nextint (); temp=n; while (temp!=0) { d=temps10; ct: temp/=10; i temp=n; wh, { 2 (temp!=0) d=temp$10; if ((c82: { LL (ct 1 66 a82 eads: £=0; break; if (t system.out-printIn("It is boring number”) ; e System.out.printin(*It is not a boring number”);Model Test Papers —_— nnn Variable Description Variable Name Data Type Description a int To store a number int To count digits in number ad int ‘To store digit from the number temp int To store the number temporarily f int To store program logic flow control (1-true,2-false] QUESTION 6——$ A salesman is paid commission on the following basis: Write a program Sales Commission Rate Up to & 10,000 2% % 10,001 to % 20,000 3% % 20,001 to % 50,000 5% % 50,001 to & 70,000 8% Above 70,000 10% amount, commission rate and commission. Ans: import java-util.*; class ( salesMan public static void main(String args[]) { Scanner sc=new Scanner (System. in); double samt, comm=0.0,r=0.07 system.out.printin ("Enter Your Sale samt=sc.nextDouble () if (samt=10001 && samt=20002 6& samtModel Test Papers 259 (ii) What is the value of i after the following code snippet executes? [2] int i=17; Ans: (iii) Ans: (iv) Ans. w) Ans: (wi) Ans: (vii) Ans: (viii) Ans: (ix) Ans: system.out.print(i#+ + +i); 19 What are methods? How are these related to an object? (2 ‘A method is an operation associated to an object. The behaviour of an object is represented through associated functions, which are called methods. State the difference between = and (2) (i) It is an assignment operator. (i) It is a relational operator. (ii) Ex: a=5; assigns the value (ii) Ex: compares variable a's 5 to the variable a. value with 5 and checks whether it equals 5 or not. Write the output of the following statements. [2] String s="one two three”; int p=s.indexOf('t’); int pl=s.indexOf(‘t’,7)i System.out.print (pos+” “+pos1); 48 Explain any two types of access specifier. (2] The two types of access specifiers are the following: Public: The data members with public access specifiers are accessible within the package as well outside the package to the subclass and non-subclass. Private: The data members with private access specifiers are accessible only within the class where they are declared. What are reusability features of Java and how does Java implement it? (2) Object-oriented programming languages have an important feature of reusability. ‘The term means that the already written code can be reused by other programs. In Java, it is implemented by using the concept of packages. Assign the value of pi (ie, 3.142) to a variable with requisite data type. (2) double pi=3.1427 What do you mean by a temporary instance of a class? (2) ‘A temporary instance of a class means an anonymous object (object having no name) of the class and which is shortlived. Its benefit is when an object is required only for a very short time.260 (x) Ans: QUESTION Ans: ICSE Computer Applications Papers Differentiate between call by value and call by reference. (2] L Call by value | Call by reference | i) It is the technique of calling a (i) It is the technique of calling a method passing primitive data type method passing object as arguments. value as arguments to the method. to the method. Any changes made Any changes made to the arguments to the arguments within the called within the called procedure have no procedure reflects back to the actual effect on the actual arguments. arguments. i) It is a pure function. (ii) Tt is an impure function. SECTION B (60 Marks) Attempt any four questions from this section. The answers in this section should consist of programs in either BlueJ environment or any program environment with Java as the base. Each program should be written using Variable Descriptions /Mnemonic Codes such that the logic of the program is clearly depicted. Flowcharts and Algorithms are not required. Define a class with the following specifications: 5) Class name : Number Member Variable int num : to store an integer value intr to store reverse of the number num Member Methods Number (int n) : parameterised constructor to assign num=n void sumdigit) : display number's digits sum void reverse() : reverse the number num boolean check() — : returns true if number is a palindromic number else returns false. import java.util.*; class Number { int num, rz Number (int n) ( num r=0}Model Test Papers i : : : void sumdigit () ( int copy=num,d,s=0; while (copy!=0) ( d=copy#10; s=std; copy=copy/10; } System.out.println("Digits Sum:”+s); ) void reverse() ( int d,copy; copy=num; while (copy!=0) { d=copy310; r=r*10+d; copy=copy/10; } boolean check () ( if (num==r) return true; else return false; ) public static void main(String args{]) { Scanner sc=new Scannex (System. in); int ni system.out.println ("Enter any number:”); nesc-nextInt (07 Number ob=new Number1234 (n) ; ob.sumdigit ()7 ob. reverse ()i if (ob. check ()==true) system.out-printin("It is Palindromic Number”); else262 ICSE Computer Applications Papers System.out.print1n("It is not a Palindromic Number”); Variable Description Variable Name Data Type Description | mum | int To store the number r int To store reverse of the number copy int To store the number temporarily a int To store digit of the number s int To store sum of digits Write a program to print the sum of negative numbers, sum of positive even numbers and sum of positive odd numbers from a list of numbers (n) entered by the user. (15) Ans: import java.util. class sumInteger public static void main(String args(]) ( Scanner sc=new Scanner (System. in); int n,sn=0,se=0,s0=0,num, i; System.out.print1n("Enter number of integers”); ne=sc.nextInt (); pisen;it+) for ( ‘ System.out.printin (“Enter any number”) num=sc.nextInt () 7 if (num0sanum’2!=0) i System.out-println ("Sum of negative numbers:”+sn); Sum of system. out.-print1n( positive even numbers:”+se) ; system.out-printin("Sum of positive odd numbers: ”+so) ;Test 4 (eee Perini ee ea ae Variable Description Variable name Data type Description 2 int to accept the integer i int to run the loop sn int to store the sum of negative numbers 80. int to store the sum of positive odd numbers se int to store the sum of positive even numbers Write a program to enter n students’ names and arrange the names in ascending order. [Using Bubble Sort] (15) Ans: import java.util.*; class nameSort { public static void main(String args{]) { Scanner sc=new Scanner (System.in); int n,i,d? System.out.println ("Enter the number of students: n=Integer.parseInt (in.readLine())i ew Stringin],t7 String nal for (i=0;icnsit+) ( system.out.println ("Enter your name”); na[i]=in.readbine () } system. out.printin( for (i=0;icnzit+) { “The unsorted name list”); system.out.printin(na[i]) 7 ) for (i=0;icn-Lsit+) { init) if (na(}] -compareTo(na[j+1]) >0) { tenalil a (jell s— } } System.out.println(*The sorted name list”); for (i=O;icn;i++) ystem.out .printIn(nalil); Variable Description Variable name Data type Description ~] 2 int to accept the number of students nal] String to accept name of the students t String to store the name temporarily ij int to run the loop Define a class to accept n number of words in an array and display each word swapping its first and last characters. (15) J.length()-1);Model Test Papers nti i ewL) y ubstring(1,w{il System.out.println("Original Word :”+w[i]+” )+ch Modified Word Variable Description Variable Name | Data Type Description wi) String ‘An array to store words wi String | To store modified word n int ‘To store size of the array i int To run the loop chi char ‘To store the first character ch2 char ‘To store the last character A library charges fine for late of days taken to return a book to the total fine charged. Fine is calculated based on the given conditions. submission of books. Write a program to input number the library after the due date and calculate and display (15) ‘Number of days Fine/Day (in?) First 2 Nil Next 5 2.50 Next 7 4.00 Next 10 7.50 Above 24 10.00 Ans: import java.util.*7 class Library ( public static void main(String args(1) Scanner sc=new Scanner (System.in); int d: double £=0.07 system.out .printin (“Enter c.nextInt (7 if (d=10;i/ 10) (b) fortint i=10;i=10;/10) The first option is not valid as i/10 is not declared correctly. The correct statement will be: for(int i=100;i>=10;i=i/10)] 7) (Note: (vi) Ans: (vii) Ans: (viii) What is the output of the following code: short x=32767; xtty System.out.print(x); (a) 32768 (b) 32767 (c) -32768 (d) -32767 (©) -82768 In java short data range is from -32768 to 32,767 and its cyclic in nature] Output of the following statement: String n="5"; System.out.print(1+20+n+1+20); (a) 47 (b) 1215120 (©) 215120 (@) 21521 (c) 215120 What is the final value stored in variable k? double s=Math.floor(Math.max(2.34,4.67)); ‘System.out.print(s); @ 6 (b) 5.0 () 40 @4 (c) 4.00 Give the output of the following: double x=2.5; xta10+ +44 + () 115a ee se Ans: (b) 9.5 [Note: x=2.5+(10 + 3.5 +3.5 -10) = 2.5+7.0=9.5) (ix) An array af)=(1,2,3,4,5,6) is given. What will be the result of a[2]+1+a[4-1]? (a) 6 7 8 ws Ans: (c) 8 [Note: a{2]+1+a[3}=3+1+4=8] (x) The library method equalslgnoreCase () returns (a) int (b) boolean (©) char (d) string Ans: (b) boolean (xi) Identify the keyword among the following that makes a variable belong to a class rather than being defined for each object of its class. (@) final (b) public (ce) static (d) private Ans: (c) static (xii) Find the value of num{1] after execution of the following code: int num{}=(0,2,4,1,3); fortint i=O;sicnum.length;i++) i numli}=num{(numfiJ+3) % num. length]; 1 fa) 1 (b) 2 fo 3 (d) 4 Ans: (a) 1 Working fal numi[i] 0 | num(0}=num[(num{0}+3)%5) =num({(0+3)%5]=num[3]=1 1] num{1J=num{(num[1)}+3)%5) 1 =num([(2+3)%5)=num|[0}=:NR RR apemmmnne ni ce a (xii) Ans: (xiv) Ans: (xv) (xvi) Ans: (xvii) Ans: [Not (xviii) Ans: _______ is not @ Wrapper class. (a) Byte (b) char (c) Long (d) Float (b) char Given array 1,4, 2, 5, 12, 3 what will be the array after 2 passes of bubble sort for ascending order. (a) 1,2, 45,3, 12 @) 1, 2, 4,3, 5, 2 () 1, 24, 5,12, 3 (d) None of the above (b) 1,2,4,3,5,12 ‘Any array allows you to store elements with data type only. (a) float () long (©) int (@) same (d) same Ist PASS 2nd PASS variables of a class may have different values for different objects. (@) Local (b) Instance () Class (d) Argument (b) Instance Number of primitive data types in java: (a) 6 () 7 () 8 @9 8 The eight primitives in java are intbyte,shortlong float,double,booleand and char] What does the following string do to given strl: String str1="Examination”.replace(‘a’,e); (a) Replaces all occurrence of ‘a’ with ‘e’ (b) Replaces first occurrence of ‘a’ with ‘e’ (c) Replaces all occurrence of @” with ‘a’ (a) Replaces first occurrence of @” with ‘a’ (b) Replaces first occurrence of ‘a’ with ‘e’ao imix: Pick the odd one out a) nextInt’ by nextDouble: fe) nextString! nat Ans ic) nextString: [Note: options a, 6 and d are valid input method where option b ie., nextString () is an invalid String input method.) ‘xx; A loop within a loop is termed as. ‘a; Infinite loop (by Null loop (c) Nested loop id) Delay loop Ans: ‘c) Nested loop “wy fii) System ‘ivy Ans: (i) omput i 4 (ai) Applicationster (iv) false (ii) What is the significance of default in a switch case? 2) ‘Ans: The default is 2 special case in a switch statement which is automatically followed if no case matches with the given switch value. ) What will be the result of the given expression, if p=10 initially. (2) (i) (sp) + (prt) 2104 fii) (pst) +4%p= ( AY &&Ch="a! G&Ch

You might also like