Ads

ICSE Solved Paper, 2018

ICSE Examination 2018 – 19 (Solution) 

COMPUTER APPLICATION 
Class – X 
SECTION – A (40 MARKS)
Attempt all questions


Question 1: 

(a) Define Abstraction. [2] 
Ans: - Abstraction refers to specifying the behavior of a class without going into the details of the implementation. 

(b) Differentiate between searching and sorting. [2] 
Ans: - In searching, we are provided with an array which contains multiple elements and asked to find the index of a specific element. In sorting, an array is provided and we are asked to order the elements in either ascending or descending order. 

(c) Write a difference between the functions isUpperCase() and toUpperCase(). [2] 
Ans: - isUpperCase() returns the boolean value whereas, toUpperCase returns character value. 

(d) How are private members of a class different from public members? [2] 
Ans: - Private members of a class can be accessed only by the methods of the class in which they are declared. While public members can be accessed outside of the class also. 

(e) Classify the following as primitive or non-primitive data types: [2] 
Ans: - char – Primitive 
arrays – Non-primitive 
int – Primitive 
classes – Non-primitive


Question 2: 

(a) (i) int res = 'A'; 
What is the value of res? 
(ii) Name the package that contains wrapper classes. [2] 
Ans: - (i) res = 65 
(ii) java.lang package contains wrapper classes.

(b) State the difference between while and do-while loop. [2] 
Ans: - A while is an entry controlled loop i.e. the loop condition is checked before the loop is executed while, do-while is an exit controlled loop i.e. the loop condition is checked after the loop is executed. 

(c) System.out.print(“BEST ”); 
System.out.print(“OF LUCK ”); 
Choose the correct option for the output of the above statements: [2] 
(i) BEST OF LUCK 
(ii) BEST 
      OF LUCK 
Ans: - (i) BEST OF LUCK is the correct answer. 

(d) Write the prototype of a function check which takes an integer as an argument and returns a character. [2] 
Ans: - char function(int a) 

(e) Write the return data type of the following functions: [2] 
(i) endsWith() 
(ii) log() 
Ans: - (i) endsWith – boolean 
(ii) log() – double 


Question 3: 
(a) Write a Java expression for the following: [2]

Ans: Math•sqrt(3 * x + Math•pow(x, 2)) / (a + b);

(b) What is the value of y after evaluating the expressing given below? [2] 
y+= ++y + y– + – –y; when int y=8. 
Ans: - y+= ++y + y– – + – –y 
8 + 9 + 9 + 7 
y=33 

(c) Give the output of the following: [2] 
(i) Math.floor(–4.7) 
(ii) Math.ceil(3.4) + Math.pow(2,3) 
Ans: - i) – 5.0 
ii) 4.0 + 8.0 
= 12.0

(d) Write two characteristics of a constructor. [2] 
Ans: - i) A constructor has the same name as that of the class. 
ii) A constructor does not have a return type. 

(e) Write the output of the following: [2] 
System.out.println(“Incredible” + “\n” + “world”); 
Ans: - Incredible 
           world 

(f) Convert the following if else if constructor into switch case: [2] 
if(var = = 1) 
   System.out.println("good"); 
else if(var = = 2) 
    System.out.println("better"); 
else if(var = = 3) 
    System.out.println("best"); 
else 
     System.out.println("invalid"); 
Ans: - switch(var) 
     case 1: 
     System.out.println("good"); 
     break; 
     case 2: 
     System.out.println("better"); 
     break; 
     case 3: 
     System.out.println("best"); 
     break; 
     default: 
     System.out.println("invalid"); 

(g) Give the output of the following String functions: [2] 
(i) “ACHIEVEMENT”.replace(„E‟, „A‟) 
(ii) “DEDICATED”.compareTo(“DEVOTE”) 
Ans: - i) ACHIAVAMANT 
ii) D – V = 68 – 86 = – 18

(h) Consider the following String array and give the output: [2] 
String arr[] = {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};
System.out.println(arr[0].length() > arr[3].length()); 
System.out.print(arr[4].substring(0, 3)); 
Ans: - arr[0].length() > arr[3].length() 
= “DELHI”.length() > “LUCKNOW”.length() 
= 5 > 7 
So, output is false 

arr[4].substring(0, 3) 
JAIPUR.substring(0, 3) 
So, output is JAI 

(i) Rewrite the following using ternary operator: [2] 
if(bill > 10000) 
     discount = bill * 10.0 / 100; 
else 
     discount = bill * 5.0 / 100; 
Ans: discount = bill > 10000 ? (bill * 10.0 / 100) : (bill * 5.0 / 100); 

(j) Give the output of the following program segment and also mention how many times the loop is executed: [2] 
int i; 
for(i = 5; i > 10; i++) 
     System.out.println(i); 
System.out.println(i * 4); 
Ans: Loop condition i>10 i.e. 5>10 which is false. So, loop is not executed even once. 
Output will be 5 * 4 =20



SECTION – B (60 MARKS) 
Attempt any four questions

Question 4:

Design a class RailwayTicket with following description: 
    Instance Variable / Data members
String name : to store the name of the customer 
String coach : to store the type of coach customer wants to travel 
long mobno : to store customer‟s mobile number 
int amt : to store basic amount of ticket 
int totalamt : to store the amount to be paid after updating the original amount 
    Methods: 
void accept() : to take input for name, coach, mobile number and amount 
void update() : to update the amount as per the coach selected. 
Extra amount to be added in the amount as follows: 
Type of coaches        Amount 
First_AC                    700 
Second_AC                500 
Third_AC                    250 
sleeper                        None 
void display() : To display all details of a customer such as name, coach, total amount and mobile number. 
Write a main() method to create an object of the class and call the above methods. [15]
Ans: 
import java.util.*; 
class RailwayTicket 
    String name; 
    String coach;
    long mobno;
    int amt;
    int totalamt;
    void accept() 
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter name: "); 
        name = sc.nextLine();
        System.out.print("Enter coach: ");
        coach = sc.nextLine();
        System.out.print("Enter mobno: ");
        mobno = sc.nextLong();
        System.out.print("Enter amt: ");
        amt = sc.nextInt();
    }
    void update()
    {
        if (coach.equals("First_AC")) 
            totalamt = amt + 700; 
        else if (coach.equals("Second_AC")) 
            totalamt = amt + 500; 
        else if (coach.equals("Third_AC")) 
            totalamt = amt + 250; 
        else if (coach.equals("sleeper"))
            totalamt = amt; 
    }
    void display() 
    {
        System.out.println("Name: " + name); 
        System.out.println("Coach: " + coach);
        System.out.println("Mobile Number: " + mobno); 
        System.out.println("Amount: " + amt);
        System.out.println("Total Amount: " + totalamt);
    }
    public static void main() 
    {
        RailwayTicket ob= new RailwayTicket();
        ob.accept(); 
        ob.update();
        ob.display(); 
    
}


Question 5: 

Write a program to input a number and check and print whether it is a Pronic number or not. Pronic number is the number which is the product of two consecutive integers. [15]
Examples: 
12 = 3 × 4 
20 = 4 × 5 
42 = 6 × 7
Ans: - 
class PronicNumber 
    public static void main(int n) 
    
        boolean pronic = false; 
        for (int i = 1; i < n; i++) 
        {
            int product = i * (i + 1);
            if (product = = n) 
            {
                pronic = true;
                break;
            }
        
        System.out.println("Pronic number = " + pronic);
    }
}


Question 6:

Write a program in Java to accept a string in lowercase and change the first letter of every word to uppercase. Display the new string. [15]
Sample INPUT :         we are in cyber world 
Sample OUTPUT :     We Are In Cyber World
Ans:
class SentenceCase
{
    public static void main(String s) 
    {
        String output = "";
        for (int i = 0; i < s.length(); i++) 
        {
            char ch = s.charAt(i); 
            if (i = = 0 || s.charAt(i - 1) = = ' ') 
                output = output + Character.toUpperCase(ch); 
            else 
                output = output + ch; 
        }
    System.out.println("Output: " + output); 
    }


Question 7:

Design a class to overload a function volume() as follows: 
(i) double volume(double r) – with radius 'r' as an argument, returns the volume of sphere using the formula:
(ii) double volume(double h, double r) – with height 'h' and radius 'r' as the arguments. returns the volume of a cylinder using the formula: 
(iii) double volume(double l, double b, double h) – with length 'l', breadth 'b' and height 'h' as the arguments, returns the volume of a cuboid using the formula: 
v = l × b × h
Ans:
class Overload 
{
    double volume(double r)
    {
        double vol = 4.0 / 3 * 22 / 7 * Math.pow(r, 3);
        return vol; 
    }
    double volume(double h, double r)
    {
        double v = 22.0 / 7 * Math.pow(r, 2) * h;
        return v;
    }
    double volume(double l, double b, double h)
    {
        double v = l * b * h;
        return v;
    }
}


Question 8:

Write a menu driven program to display the pattern as per user's choice: [15]
Pattern 1                    Pattern 2
ABCDE                        B
ABCD                          LL 
ABC                             UUU 
AB                                EEEE 
For an incorrect option, an appropriate error message should be displayed.
Ans:
import java.util.Scanner;
class Pattern 
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("1. Pattern 1");
        System.out.print("2. Pattern 2");
        System.out.print("Enter your choice: ");
        int ch = sc.nextInt(); 
        switch(ch) 
        {
            case 1:
            System.out.print("Enter number of lines: ");
            int n = sc.nextInt();
            for (int i = n; i >= 1; i--) 
            {
                for (int j = 0; j < i; j++) 
                    System.out.print((char) ('A' + j));
                System.out.println(); 
            }
            break;
            case 2:
            System.out.print("Enter string: ");
            String s = sc.next();
            char ch;
            for (int i = 0; i < s.length(); i++)
            {
                ch = s.charAt(i);
                for (int j = 1; j <= (i + 1); j++) 
                    System.out.print(ch);
                System.out.println();
            
            break;
            default:
            System.out.println("Invalid choice");
        }
    }
}


Question 9:

Write a program to accept name and total marks of N number of students in two single subscripts array name[] and totalmarks[]. [15]
Calculate and print:
(i) The average of the total marks obtained by N number of students. [average = (sum of total marks of all the students) / N]
(ii) Deviation of each student‟s total marks with the average. [deviation = total marks of a student – average]
Ans:
import java.util.*;
class Student 
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter number of students: ");
        int n = sc.nextInt();
        String[] name = new String[n];
        int[] totalmarks = new int[n];
        for (int i = 0; i < n; i++)
        {
            System.out.println("Student " + (i + 1));
            System.out.print("Enter name: ");
            name[i] = sc.next();
            System.out.print("Enter marks: ");
            totalmarks[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0; i < n; i++) 
            sum = sum + totalmarks[i];
        double average = (double) sum / n;
        System.out.println("Average is " + average);
        for (int i = 0; i < n; i++) 
        {
            double deviation = totalmarks[i] - average;
            System.out.println("Deviation of " + name[i] + " is " + deviation);
        }
    }
}
SHARE

Author

Hi, Its me Hafeez. A webdesigner, blogspot developer and UI/UX Designer. I am a certified Themeforest top Author and Front-End Developer. I'am business speaker, marketer, Blogger and Javascript Programmer.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment