ICSE Computer Applications Year 2018

Section A (40 Marks)

Attempt all questions

Question 1

(a) Define abstraction.

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

(b) Differentiate between searching and sorting.

Searching allows us to find an element in an array.
Sorting allows us to arrange the array elements in a particular order.

(c) Write a difference between the functions isUpperCase() and toUpperCase().

The isUpperCase() method checks if a given character is in uppercase or not. The toUpperCase() method converts a given character to uppercase.

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

The public members can be accessed by anyone.
The private members allow only the methods of the same class to access them.

(e) Classify the following as primitive or non-primitive data types:
(i) char – primitive data type.
(ii) arrays – non-primitive data type.
(iii) int – primitive data type.
(iv) classes – non-primitive data type.

Question 2

(a)
(i) int res = 'A';
What is the value of res?

65

(ii) Name the package that contains wrapper classes.

java.lang

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

The while loop is entry-controlled.
The do-while loop is exit-controlled.

(c) System.out.print("BEST ");
System.out.println("OF LUCK");

Choose the correct option for the output of the above statements:
(i) BEST OF LUCK
(ii) BEST
OF LUCK

BEST OF LUCK

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

char check(int n)

(e) Write the return data type of the following functions:
(i) endsWith()boolean
(ii) log()double

Question 3

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

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

(b) What is the value of y after evaluating the expression given below?
y += ++y + y-- + --y; when int y = 8.

y = y + ++y + y– + –y
= 8 + 9 + 9 + 7
= 17 + 9 + 7
= 26 + 7
= 33.

(c) Give the output of the following:
(i) Math.floor(-4.7)

-4.0
(ii) Math.ceil(3.4) + Math.pow(2, 3)

4.0 + 8.0
= 12.0

(d) Write two characteristics of a constructor.

They have the same name as their class name.
They have no return type. Not even void.

(e) Write the output for the following:
System.out.println("Incredible" + "\n" + "world");

Incredible
world

(f) Convert the following if else if construct into 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");
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:
(i) "ACHIEVEMENT".replace('E', 'A')

ACHIAVAMANT

(ii) "DEDICATE".compareTo("DEVOTE")

18

(h) Consider the following String array and give the output:
String arr[] = {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};
System.out.println(arr[0].length() > arr[3].length());
System.out.print(arr[4].substring(0, 3));

false
JAI

(i) Rewrite the following using ternary operator:

if(bill > 10000)
    discount = bill * 10.0 / 100;
else
    discount = bill * 5.0 / 100;

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:

int i;
for(i = 5; i > 10; i++)
    System.out.println(i);
System.out.println(i * 4);

Output is 20.
The loop executes zero times.

Section B (60 Marks)

Attempt any four questions from this section.

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 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.

import java.io.*;
class RailwayTicket{
    String name;
    String coach;
    long mobno;
    int amt;
    int totalamt;
    public void accept()throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Name: ");
        name = br.readLine();
        System.out.print("Coach: ");
        coach = br.readLine();
        System.out.print("Mobile number: ");
        mobno = Long.parseLong(br.readLine());
        System.out.print("Amount: ");
        amt = Integer.parseInt(br.readLine());
    }
    public void update(){
        if(coach.equalsIgnoreCase("First_AC"))
            totalamt = amt + 700;
        else if(coach.equalsIgnoreCase("Second_AC"))
            totalamt = amt + 500;
        else if(coach.equalsIgnoreCase("Third_AC"))
            totalamt = amt + 250;
    }
    public void display(){
        System.out.println("Name: " + name);
        System.out.println("Coach: " + coach);
        System.out.println("Total Amount: " + totalamt);
        System.out.println("Mobile number: " + mobno);
    }
    public static void main(String args[])
    throws IOException{
        RailwayTicket obj = new RailwayTicket();
        obj.accept();
        obj.update();
        obj.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.
Examples:
12 = 3 × 4
20 = 4 × 5
42 = 6 × 7

import java.io.*;
class Pronic{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Enter the number: ");
        int n = Integer.parseInt(br.readLine());
        int i = 1;
        while(i * (i + 1) < n)
            i++;
        if(i * (i + 1) == n)
            System.out.println(n + " is a Pronic Number.");
        else
            System.out.println(n + " is not a 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

import java.io.*;
class TitleCase{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Enter the string: ");
        String s = br.readLine();
        s = s.toLowerCase();
        String t = new String();
        for(int i = 0; i < s.length(); i++){
            if(i == 0 || s.charAt(i - 1) == ' ')
                t += Character.toUpperCase(s.charAt(i));
            else
                t += s.charAt(i);
        }
        System.out.println(t);
    }
}

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

class Overload{
    public static double volume(double r){
        return 4.0 / 3 * 22.0 / 7 * r * r * r;
    }
    public static double volume(double h, double r){
        return 22.0 / 7 * r * r * h;
    }
    public static double volume(double l, double b, double h){
        return l * b * h;
    }
}

Question 8

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

Pattern 1     Pattern 2
ABCDE         B
ABCD          LL
ABC           UUU
AB            EEEE
A

For an incorrect option, an appropriate error message should be displayed.

import java.io.*;
class Menu{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.println("1. Pattern 1");
        System.out.println("2. Pattern 2");
        System.out.print("Enter your choice: ");
        int choice = Integer.parseInt(br.readLine());
        switch(choice){
            case 1:
            String s = "ABCDE";
            for(int i = s.length(); i >= 0; i--)
                System.out.println(s.substring(0, i));
            break;
            case 2:
            s = "BLUE";
            for(int i = 0; i < s.length(); i++){
                char ch = s.charAt(i);
                for(int j = 0; j <= i; 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[].

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]

import java.io.*;
class Deviation{
    public static void main(String args[])
    throws IOException{
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(in);
        System.out.print("Number of students: ");
        int n = Integer.parseInt(br.readLine());
        String name[] = new String[n];
        int totalmarks[] = new int[n];
        double avg = 0.0;
        double d = 0.0;
        for(int i = 0; i < name.length; i++){
            System.out.print("Name: ");
            name[i] = br.readLine();
            System.out.print("Marks: ");
            totalmarks[i] = Integer.parseInt(br.readLine());
            avg += totalmarks[i];
        }
        avg /= n;
        for(int i = 0; i < name.length; i++){
            d = totalmarks[i] - avg;
            System.out.println("Deviation " + (i + 1) + ": " + d);
        }
        System.out.println("Average score: " + avg);
    }
}

1 thought on “ICSE Computer Applications Year 2018

Leave a Reply