ICSE 2018 computer applicationsolved paper

ICSE Computer Application solved Paper





ICSE Question Paper – 2018 Computer Applications Class X

SECTION A (40 Marks)
Answer all questions from this Section
SECTION A (40 MARKS)
Attempt all questions




Question 1:

(a) Define abstraction. [2]

Ans. Abstraction refers to the act of representing essential features without including the background details or explanations.

(b) Differentiate between searching and sorting. [2]

Ans. In searching, an element is a search from an array, whereas in sorting the array arrange in descending or ascending order.
2. It basically return a particular position whereas sorting returns an array with the data arranged in ascending or descending order.

(c) Write a difference between the functions isUpperCase() and toUpperCase(). [2]
Ans. Both isUpperCase() and toUpperCase() are methods of the Character class. In
isUpperCase() accepts a character and returns true if the provided character is uppercase. Else, it returns false.
Ex:
boolean m = Character.isUpperCase('a');
boolean n = Character.isUpperCase('A');
System.out.println(m + " " + n);
false true

(d) How are private members of a class different from public members? [2]

Ans. Private members of a class are only accessible within the in which they are declared. While public members can be accessible to all and outside of the class.

(e) Classify the following as primitive or non-primitive data types: [2]
(i) char
(ii) arrays
(iii) int
(iv) classes
Ans. (i) char – Primitive, (ii) arrays – Non-primitive (iii) int – Primitive (iv) 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) The output of res will be ASCII value of ‘A’ which is 65.
(ii) Java.lang package contains the wrapper class in java programming.

(b) State the difference between while and do-while loop. [2]

Ans. The while is an entry controlled loop mean the condition of the loop will be checked before the loop is executed while do-while is an exit controlled loop and it is checked after the loop is executed.

(c) System.out.print(“BEST “);
System.out.println(“OF LUCK”);
Choose the correct option for the output of the above statements: [2]
(i) BEST OF LUCK
(ii) BEST
OF LUCK
Ans. (i) is the correct output. It is because System.out.print() will not print with a new line but System.out.println(“OF LUCK”) will print with a new line so the output is
BEST OF LUCK


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

Ans. char check(int x)
           
(e) Write the return data type of the following functions: [2]
(i) endsWith()
(ii) log()
Ans. i) boolean ii) double

Question 3

(a) Write a Java expression for the following: [2]√(3x + x2) / (a + b)

Ans. Math.sqrt(3 * x + x*x ) / (a + b)

(b) What is the value of y after evaluating the expression given below? [2]
y += ++y + y– + –y; when int y = 8.
Ans. 33
y += ++y + y-- + --y
y = 8 + ++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 must be the same name as that of class
ii) It has no return type not even void.

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

Ans.
Incredible
World

(f) Convert the following code if to switch..case.

            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) “DEDICATE”.compareTo(“DEVOTE”)

Ans. i) ACHIAVAMANT ii) Starting first two characters are same, so the output will be -18, It takes the ASCII values of the third characters and subtract to get the result.
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. false and JAI
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. Here I start with 5 and condition is i>10 so it is false and the loop will not execute
And for second print option 20 will be print as i=5, so 5*4 is 20


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 descriptions/Mneumonic codes so that the logic of the program is clearly depicted.
Flow-charts and algorithms are not required.


Question 4

Design a class RailwayTicket with the following description:

Instance variables/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 a customer’s mobile number.
int amt: to store the 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 a name, coach, total the amount and mobile number.
Write a main() method to create an object of the class and call the above methods.
Answer
import java.util.*;

public class RailwayTicket
{
    String name;    // to store the name of the customer
    String coach;   // to take coach type
    long mobno;     // to store mobile number
    int amt;        // amount to be taken
    int totalamt;   // total amount with extra
    // object of scanner class
    Scanner sc = new Scanner(System.in);
    // input the detail of the passenger
    void accept()
    {      
        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();
    }

    // update the extra amount
    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;
        }
    }
    // display the detail of the passenger
    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);
    }
    // main method
    public static void main(String args[])
    {
        // object of RailwayTicket class
        RailwayTicket ob = new RailwayTicket();
        ob.accept();
        ob.update();
        ob.display();
    }
}
Output:
Enter name: Khurshid
Enter coach: First_AC
Enter mobno: 9199988888
Enter amt: 1567
Name            : Khurshid
Coach           : First_AC
Mobile Number   : 9199988888
Amount          : 1567
Total Amount    : 2267
Sr. No
Variable / Method
Type
Describe
1
name
String
to store the name of the customer
2
coach
String
to take coach type
3
mobno
long
store customer’s mobile number
4
amt
int
to store basic amount of ticket
5
totalamt
int
to store the amount to be paid after updating the original amount
6
accept()
void
To accept the detail of the passenger
7
update()
void
Update the extra charge for the coach
8
display()
void
Display all the detail of the passenger
9
main()
Static void
To call the above methods

Question 5

Write a program to input a number and check and print whether it is a Pronic number or not. The pronic number is the number which is the product of two consecutive integers.

Examples:
12 = 3 × 4
20 = 4 × 5
42 = 6 × 7
Answer: Click Pronic number

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.
Sample INPUT: we are in cyber world
Sample OUTPUT: We Are In Cyber World
Answer
import java.util.*;
public class CapitalizeFirstChar
{
    public static void main(String[] args)
    {
        int I;
        char ch;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a sentence: ");
        String st = sc.nextLine();
        String capSt = "";
        for (i = 0; i < st.length(); i++) {
               ch = st.charAt(i);
            if (i == 0 || st.charAt(i - 1) == ' ') {
                capSt = capSt + Character.toUpperCase(ch);
            } else {
                capSt = capSt + ch;
            }
        }
        System.out.println("Capitalize each word of the sentence : " + capSt);
    }
}
Output:
Enter a sentence: the quick brown dog jumps over a lazy hungary fox
Capitalize each word of the sentence: The Quick Brown Dog Jumps Over A Lazy Hungary Fox
Sr. No
Variable / Method
Type
Describe
1
st
String
to store the sentence in small characters
2
capSt
String
to convert the first character of each word
3
sc
Scanner object
Object of scanner
4
i
int
to iterate the loop

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:
v = 4 / 3 × 22 / 7 × r3
(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:
v = 22 / 7 × r2 × h
(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
Answer
// Volume overloded class
public class VolumeOverload
{
    double vol;
    double radius;
    double height, length, breadth;
    double volume(double r)
    {
        radius = r;
        vol = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
        return vol;
    }

    double volume(double h, double r)
    {
        radius = r;
        double vol = (22.0 / 7) * Math.pow(radius, 2) * h;
        return vol;
    }

    double volume(double l, double b, double h)
    {
        length = l;
        breadth = b;
        height = h;
        double vol = length * breadth * height;
        return vol;
    }
    // main method
    public static void main(String args[])
    {
        double vol;
        VolumeOverload ob =new VolumeOverload();
        vol = ob.volume(5.0, 6.0);
        System.out.println("Volume = " + vol);
    }
}

Question 8

Write a menu-driven program to display the pattern as per user’s choice:

Pattern 1 Pattern 2

ABCDE
ABCD
ABC
AB
A
B
LL
UUU
EEEE
J J J J J

Answer
import java.util.*;
public class PatternMenuProgram
{
    public static void main(String[] args)
    {
        int choice, num, i, j;
        String st;
        char ch;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter pattern number: ");
        choice = sc.nextInt();
        switch(choice)
        {
            // option 1 start
            case 1:
            System.out.print("Enter number of lines: ");
            num = sc.nextInt();
            for (i = num; i >= 1; i--)
            {
                for ( j = 0; j < i; j++)
                {
                    System.out.print((char) ('A' + j));
                }
                System.out.println();
            }
            break; // option 1 end
            // option 2 start
            case 2:
            System.out.print("Enter string: ");
            st = sc.next();
            for ( i = 0; i < st.length(); i++)
            {
                ch = st.charAt(i);
                for ( j = 1; j <= (i + 1); j++)
                {
                    System.out.print(ch);
                }
                System.out.println();
            }
            break;  // // option 2 end
            default:
            System.out.println("Wrong choice");
        }
    }
}
Output
Enter pattern number: 1
Enter number of lines: 5
ABCDE
ABCD
ABC
AB
A
Enter pattern number: 2
Enter string: BLUEJ
B
LL
UUU
EEEE
JJJJJ


Question 9

Write a program to accept name and total marks of N number of students in two single subscripts array name[] and totalmarks[].


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]
Answer
import java.util.*;
public class StudentDeviationProgram
{
    public static void main(String[] args)
    {
        int number;     // number of student
        int i;          // for loop
        int sum;        // for summation of the numbers obtained by student
        double average; // for avearage calculation
        double deviation;// deviation calculation
        sum = 0;        // initialize with 0
        Scanner sc = new Scanner(System.in);
        // Number of students
        System.out.print("Enter number of students: ");
        number = sc.nextInt();
        // Name array
        String[] name = new String[number];
        // totalMarks array
        int[] totalMarks = new int[number];
        // Input name and total matks of students
        for (i = 0; i < number; i++)
        {
            System.out.println("Student " + (i + 1));
            System.out.print("Input name: ");
            name[i] = sc.next();
            System.out.print("Input marks: ");
            totalMarks[i] = sc.nextInt();
        }
       // Calculation of sum
        for (i = 0; i < number; i++)
        {
            sum = sum + totalMarks[i];
        }
        // Calculation of average
        average = (double) sum / number;
        System.out.println("Average is " + average);
        for (i = 0; i < number; i++)
        {
            deviation = totalMarks[i] - average;
            System.out.println("Deviation of " + name[i] + " is " + deviation);
        }
    }
}
Output
Enter number of students: 2
Student 1
Input name: Kamal
Input marks: 87
Student 2
Input name: Umesh
Input marks: 80
Average is 83.5
Deviation of Kamal is 3.5
Deviation of Umesh is -3.5



SHARE THIS
Previous Post
Next Post