0% found this document useful (0 votes)
2 views

Https App.oswaalbooks.com Download Sample-qp Subsolution 763Self Assessment Paper-5 (1)

The document contains answers to a self-assessment paper on programming concepts, primarily focusing on object-oriented programming, string manipulation, and basic Java syntax. Each question is followed by the correct option and an explanation of the reasoning behind the answer. The content covers various topics including data types, inheritance, functions, and control structures in Java.

Uploaded by

Atharv Chaudhary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Https App.oswaalbooks.com Download Sample-qp Subsolution 763Self Assessment Paper-5 (1)

The document contains answers to a self-assessment paper on programming concepts, primarily focusing on object-oriented programming, string manipulation, and basic Java syntax. Each question is followed by the correct option and an explanation of the reasoning behind the answer. The content covers various topics including data types, inheritance, functions, and control structures in Java.

Uploaded by

Atharv Chaudhary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ANSWERS

Self Assessment Paper - 5


Section-A (xiii) Option (c) is correct.
Explanation: Boxing converts the primitive data
1. types into its corresponding wrapper class object.
For example, from int to Integer.
(i) Option (b) is correct.
(xiv) Option (a) is correct.
Explanation: Inheritance is an OOPs concept that
refers to the deriving of things of a child class from Explanation: The ternary operator?: checks the
its parent. condition and returns the first expression if the
condition is true else returns the second expression.
(ii) Option (c) is correct.
As shown in the if..else expression if (c>(d) x carries c
Explanation: Duplicacy or Redundancy of data is a else it carries d. The same is shown by the expression
feature that is dependent on the programmers. So, it using the ternary operator.
cannot be created by the OOPS.
(xv) Option (d) is correct.
(iii) Option (d) is correct.
Explanation: The substring(string,start,(end) extracts
Explanation: A wrapper converts a primitive data characters from start index to end-1 index from a
type to a corresponding wrapper class object. string.
(iv) Option (c) is correct. (xvi) Option (c) is correct.
Explanation: 1>0 is true and 1<0 is false so the Explanation: Multiple functions in the same class
condition becomes true && false. As && return can be overloaded, by differentiating them on the
true only when both of its operands are true so the number or type of parameters.
answer is false.
Constructor functions may also be overloaded by
(v) Option (b) is correct. both number or type of parameters.
Explanation: The terms object and instance are often (xvii) Option (b) is correct.
interchangeable.
Explanation: The replace() function replaces all
(vi) Option (d) is correct. occurrences of a character in a string by another.
Explanation: The ceil() function returns the next (xviii) Option (a) is correct.
higher whole value for the argument specified.
Explanation: length() returns the number of
Hence, Math.ceil(–46.6) returns –46.0
characters present in the given string. The array
(vii) Option (b) is correct. index has been accessed from 0. Hence, color [2]
Explanation: A string is non-mutable, that is, it indicates Violet. The total number of characters
cannot be changed. present in the Violet is 6 Red is 3.
(viii) Option (c) is correct. (xix) Option (d) is correct.
Explanation: The replace() function replaces all Explanation: First the character needs to be extracted
occurrences of a character in a string by another. using charAt(). Next the character needs to be added
(ix) Option (b) is correct. to the blank word in reverse way. Then the word
needs to be displayed and then finally the word has
Explanation: s.lastIndexOf(i) returns the index of the
to be cleared.
last index of a‘ which is 12 here.
(xx) Option (a) is correct.
(x) Option (a) is correct.
Explanation: The charAt() function returns the
Explanation: In the statement - ch=st.charAt(st.
character at the specified index in a string.
length()-2);
st.length() returns the index position after the last 2.
character. Therefore (st.length()-2 ) returns the (i) class changecode
position of the 2nd last character. charAt() extracts
{
the character at the position.
public static void main(String
(xi) Option (d) is correct.
args[])
Explanation: In the array p={90,100,110,56,72} the
{
last index is 4 so p[5] is not accessible.
for(p=20,r=65;p<=r;r=r-10)
(xii) Option (a) is correct.
{
Explanation: The function takes a string and returns
a boolean. if (p%2==0)
2 |  OSWAAL ICSE Sample Question Papers, COMPUTER APPLICATIONS, Class-10

p++; (x) (a) size of the array is 8


else (b) position of 7 is 2 as array starts with index 0
p+=10; 3. import java.util.Scanner; [115]
} public class Employee
} {
} private int pan;
(ii) 26 private String name;
Explanation: q+= ++p + p+(q) %5 + - -q; private double taxincome;
q=10 + 6 + (6+10)%5 + 9 private double tax;
q=16 + 1+9 public void input() {
q=26 Scanner in = new Scanner(System.in);
(iii) Syntax error System.out.print(“Enter pan number: “);
Correct code, pan = in.nextInt();
char ch; System.out.print(“Enter Name: “);
String word; name = in.nextLine();
System.out.print(“Enter taxable income: “);
word=sc.nextLine();
taxincome = in.nextDouble();
ch=word.charAt(word.length()-2);
}
if ch==’a’
public void cal() {
System.out.println(“True”);
if (taxincome <= 250000) tax = 0;
(iv) z = x * x * x + y * y * y - x * y / 3
else if (taxincome <= 500000)
(v) 18 times
tax = (taxincome - 250000) * 0.1;
Explanation: Since the loop executes the continue
else if (taxincome <= 1000000)
statement for i%7==0, the loop will print values of
x for 18 times.  tax = 30000 + ((taxincome - 500000) *
(vi) str1 = manners 0.2);
else
str2 = good manners
 tax = 50000 + ((taxincome - 1000000) *
Explanation: s2.substring(5) returns values from
index 5 to end. The replace function replaces all 0.3);
occurrences of ‘t’ with ‘n’. }
The s1.concat(str1) concatenates str1 with s1 and public void display() {
stores it in str2. System.out.println(“Pan Number\tName\tTax-
(vii) false Income\tTax”);
true System.out.println(pan + “\t” + name + “\t”
Explanation: The substring() function checks + taxincome + “\t” + tax);
whether a string starts with another string or not. }
The == operator compares two characters for public static void main(String args[]) {
equality. Employee obj = new Employee();
(viii) Correct code, obj.input();
import java.util.Scanner; obj.cal();
int num=0,d=0,rev=0,t=0; obj.display();
Scanner sc=new Scanner(System.in) ; }
 System.out.println (“Enter a number,”); }
num=sc.nextInt(); 4. import java.util.Scanner;
t=num; public class ProgCityName
while (num>0) {
{ public static boolean isVowel(char ch) {
char letter = Character.toUpperCase(ch);
d=n%10;
if (letter == ‘A’ ||
rev=rev*10 +d;
letter == ‘E’ ||
num=num/10;
letter == ‘I’ ||
} letter == ‘O’ ||
if (rev==t) letter == ‘U’)
System.out.println(“Palindrome”); return true;
(ix) Parameterised constructor return false;
Product obj=new Product(); }
Answers | 3
public static void main(String args[]) { 6. import java.util.Scanner;
String cities[] = new String[10]; public class CopyArray {
Scanner in = new Scanner(System.in); public static void main(String[] args) {
System.out.println(“Enter 10 city names”); int src1[] = {10,20,30,40,50};
int src2[] = {9,18,27,36,45};
for (int i = 0; i < cities.length; i++) {
int newArray[] = new int[src1.length + src2.
cities[i] = in.nextLine(); length];
}  for(int i=0; i<src1.length; i++) {
 System.out.println(“\nCities starting with newArray[i] = src1[i];
consonant & ending with vowel:”); }
for (int i = 0; i < cities.length; i++) {  for(int i=0, j=src1.length; j<(src1.length +
if (!isVowel(cities[i].charAt(0)) && src2.length); j++, i++) {
newArray[j] = src2[i];
isVowel(cities[i].charAt(cities[i].
}
length()-1)))
System.out.println(“Array1”);
System.out.println(cities[i]);
for (int i-0;i<src1.length;i++)
} System.out.print(src1[i]);
} System.out.print(“Array2”);
} for (int i-0;i<src2.length;i++)
5. import java.util.Scanner; System.out.print(src2[i]);
public class Prog20LetterSet System.out.print(“Merged Array”);
{ for (int i-0;i< newArray.length;i++)
public static void main(String args[]) { System.out.print newArray[i] + “ “;
Scanner in = new Scanner(System.in); }
System.out.println(“Enter any 20 letters”); }
int vc = 0, cc = 0; 7. import java.util.Scanner;
for (int i = 0; i< 20; i++) { public class UniqueNumber
char ch = in.next().charAt(0); {
ch = Character.toUpperCase(ch); public static void main(String args[])
if (ch == ‘A’ || {
ch == ‘E’ || int r1, r2, number, num1, num2, count = 0;
ch == ‘I’ || Scanner sc = new Scanner(System.in);
ch == ‘O’ || System.out.print(“Enter the number you want to
ch == ‘U’) check: “);
vc++; number = sc.nextInt();
else if (ch>= ‘A’ &&ch<= ‘Z’) num1 = number;
cc++; num2 = number;
} while (num1 > 0)
 System.out.println(“Number of Vowels = “ + {
vc); r1 = num1 % 10;
 System.out.println(“Number of Consonants = while (num2 > 0)
“ + cc); 15 {
} r2 = num2 % 10;
} if (r1 == r2)
{
Examiner's Comments count++;
}
Most of the candidates answered this question num2 = num2 / 10;
correctly. Some candidates get confused with }
taking care of the index of string correctly. num1 = num1 / 10;
}
if (count == 1)
Answering Tip {
 System.out.println(“The number is
Students should learn all the concepts to write unique.”);
index properly. }
else
4 |  OSWAAL ICSE Sample Question Papers, COMPUTER APPLICATIONS, Class-10

{ }
 System.out.println(“The number is not public double discount(int price, int d1, int d2)
unique.”); {
}  double priceAfterDisc1 = price - price * d1 /
} 100.0;
}  double priceAfterDisc2 = priceAfterDisc1 -
8. import java.util.Scanner; priceAfterDisc1 * d2 / 100.0;
public class ProgSuccessiveDiscount return priceAfterDisc2;
{ }
public void discount(int price) { public static void main(String args[]) {
 System.out.println(“Amount after single Scanner in = new Scanner(System.in);
discount = “ + discount(price, 10)); System.out.print(“Enter price: “);
 System.out.println(“Amount after successive int price = in.nextInt();
discount = “ + discount(price,10, 8)); ProgSuccessiveDiscount obj = new
} ProgSuccessiveDiscount();
public double discount(int price, int d) { obj.discount(price);
 double priceAfterDisc = price - price * d / }
100.0; return priceAfterDisc; }
qq

You might also like