ICSE Paper 2018
Computer Applications
General Instructions:
• Answers to this Paper must be written on the paper provided separately.
• You will not be allowed to write during the first 15 minutes.
• This time is to be spent in reading the Question Paper.
• The time given at the head of this Paper is the time allowed for writing the
answers.
• This Paper is divided into two Sections.
• Attempt all questions from Section A and any four questions from Section B.
• The intended marks for questions or parts of questions are given in brackets [ ].
Section-A [40 MARKS]
(Attempt ALL Questions)
Question 1.
(a) Define abstraction.
(b) Differentiate between searching and sorting.
(c) Write a difference between the functions isUpperCase( ) and toUpperCase( ).
(d) How are private members of a class different from public members ?
(e) Classify the following as primitive or non-primitive data types :
(i) char
(ii) arrays
(iii) int
(iv) classes
Solution:
(a) Abstraction is a process of hiding the implementation details and showing only
functionality to the user.
(b) Searching is a technique which is used to search a particular element in an array or
string. Sorting is a technique which is used to rearrange the elements of an array or
string in a particular order either ascending or descending.
(c) The isUpperCase( ) method is used to check whether the given character is in upper
case or not. It returns Boolean data type.
The toUpperCase( ) method is used to convert a character or string into upper case. It
returns char or String type. •
(d) Scope of the private members is within the class whereas scope of the public
members is global.
(e) (i) char is primitive data type.
(ii) arrays are non-primitive data type.
(iii) int is primitive data type.
(iv) classes are non-primitive data type.
Question 2.
(a) (i) int res = ‘A’; [2]
What is the value of res ?
(ii) Name the package that contains wrapper classes.
(b) State the difference between while and do while loop. [2]
(r) [Link](“BEST”); |2]
[Link](“OF LUCK”);
Choose the correct option for the output of the above statements
(i) BEST OF LUCK
(ii) BEST
OF LUCK
(d) Write the prototype of a function check which takes an integer as an argument and
returns a character. [2]
(e) Write the return data type of the following function. [2]
(i) endsWith( )
(ii) log( )
Solution:
(a) (i) Value of res is 65.
(ii) [Link]
(b)
(c) (i) BEST OF LUCK is the correct option.
(c) char check(int x)
(e) (i) Boolean
(ii) double
Question 3.
(a) Write a Java expression for the following :
(b) What is the value of y after evaluating the expression given below ?
y + = + +y+y–l –y; when int y=8
(c) Give the output of the following : [2]
(i) [Link] (- 4.7)
(ii) [Link](3.4) + [Link](2,3)
(d) Write two characteristics of a constructor. [2]
(e) Write the output for the following : [2]
[Link](“Incredible” + “\n” + “world”);
(f) Convert the following if else if construct into switch case [2]
if (var= = 1)
[Link] .println(“good”);
else if(var= =2)
[Link](“better”);
else if(var= =3)
[Link]( “best”);
else
[Link](“invalid”);
(g) Give the output of the following string functions : [2]
(i) “ACHIEVEMENT” .replaceCE’, ‘A’)
(ii) “DEDICATE”. compareTo(“DEVOTE”)
(h) Consider the following String array and give the output [2]
String arr[]= {“DELHI”, “CHENNAI”, “MUMBAI”, “LUCKNOW”, “JAIPUR”};
[Link](arr[0] .length( )> arr[3] .length( );
[Link](arr[4] ,substring(0,3));
(i) Rewrite the following using ternary operator : [2]
if(bill > 10000)
discount = bill * 10.0/100;
else
discount = bill * 5.0/100;
(i) 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 + +)
[Link](i);
[Link](i*4);
Solution:
(a) [Link] * (3 * x + [Link](x, 2)) / (a + b);
(b) 8 + (9 + 9 + 7) = 8 + 25 =33
(c) (0 – 5.0 (it) 12.0
(d) (i) Constructor has the same name as of class.
(ii) Constructor gets invoked when an object is created.
(e) Incredible
world
(f) switch ( ) {
case 1:
[Link] .println( “good”);
break; .
case 2:
[Link] .println( “better”);
break;
case 3:
[Link]( “invalid”);
break;
}
(g) (i) ACHIAVAMANT
(ii) – 18
(h) false (at index 0, DELHI consists of 5 characters, at index 3, LUCKNOW consists of 7
characters. Therefore 5 > 7 is false)
JAI (at index 4, JAIPUR exists and extract its three characters)
(i) discount = bill > 100 ? bill * 10.0 /100 : bill * 5.0 /100;
(j) 20. Loop will be executed for 0 times.
Section-B [60 Marks]
Attempt any four questions from this Section
The answers in this Section should consist of the Programs in either Blue J environment
or any
program environment with Java as the base.
Each program should be written using Variable descriptions/Mnemonic Codes so that
the logic of
the program is clearly depicted.
Flow-Charts and Algorithms are not required.
Question 4.
Design a class Railway Ticket with following description : [15]
Instance variables/s 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
Member methods
void accept ( ) — To take input for name, coach, mobile number and amount
void update ( ) — To update the amount as per the coach selected
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 member
methods.
Solution:
import [Link].*;
import [Link]; class RailwayTicket {
String name, coach;
long mobno;
int amt, totalamt;
void accept( ) throws IOException {
Scanner sc = new Scanner([Link]);
[Link](“Enter Passenger’s Name: “);
name = [Link]( );
[Link](“Enter Mobile Number:”);
mobno = [Link]( );
[Link](“Enter Coach (FirstAC/SecondAC/ThirdAC/sleeper):”);
coach = [Link]( );
[Link](“Enter basic amount of ticket:”);
amt = [Link]( );
}
void update!) {
if ([Link](“First_AC”))
totalamt = amt + 700;
else
if ([Link](“Second_AC”))
totalamt = amt + 500; .
else
if ([Link]!”Third_AC”))
totalamt = amt + 250;
else
totalamt = amt;
}
void display() {
[Link](“\n\n Name :” +name);
[Link](“Coach :” +coach);
[Link](”Total Amount:” +totalaint);
[Link](“Mobile No.:” +name);
}
public static void main (String args[ ]) throws IOException {
RailwayTicket t = new RailwayTicket!);
[Link]();
[Link]();
[Link]();
}
}
Question 5.
Write a program to input a number and check and print whether it is a Pronic number
[15] 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
Solution:
import [Link].*;
import [Link]. Scanner;
class Pronic]
public static void main(String argsQ) throws IOException {
Scanner sc = new Scanner([Link]);
[Link](“Enter the number: “);
int n = [Link]();
int i = 0;
while(i * (i + 1) < n) {
i++;
}
if(i *(i + 1) = = n){
[Link](n + ” is a Pronic Number.”);
}
else {
[Link](n + ” is not a Pronic Number.”);
}
}
}
Question 6.
Write a program in Java to accept a string in lower case and change the first letter of
every word to upper case. Display the new string. [15]
Sample input: we are in cyber world
Sample output : We Are In Cyber World
Solution:
import [Link].*;
import [Link];
class ChangeLetter {
public static void main(String args[ ]) throws IOException {
Scanner sc = new Scanner([Link]);
[Link](“Enter String in lowercase:”);
String str 1 = [Link]( );
strl = “” +strl;
String str2 = ” “:
for (int i = 0; i<[Link]( ); i+ +) {
if(strl ,charAt(i) = = “) {
str2 = str2 + ” +Character. toUpperCase([Link](i+l));
i+ + ;
}.
else
str2= str2 + [Link](i);
}
[Link]([Link]( ));
}
}
Question 7.
Design a class to overload a function volume() as follows : [15]
(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.
Solution:
class ShapesVolume {
public static double volume (double R) {
double V = 4.0 / 3, * 22.0 / 7 * [Link](R, 3);
return V;
}
public static double volume(double H, double R) {
double V = 22.0 / 7 * R * R * H ;
return V;
}
public static 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]
For an incorrect option, an appropriate error message should be displayed.
Solution:
import [Link].*;
import [Link];
class Pattern {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner([Link]);
[Link](“::::MENU::::”)
[Link](” 1. To display ABCD Pattern”);
[Link](” 2. To display Word Pattern”);
[Link](“Enter your choice:”);
int ch= [Link]();
switch(ch) {
case 1:
for (char i = ‘E’; i > = ‘A’; i- -){
for(char j = ‘A’;j <=i;j + +){
[Link](j);
}
[Link]( );
}
break;
case 2:
String S = “BLUE”;
for (int i = 0; i < [Link](); i+ +) {
for(int j = 0; j < =i; j + +) {
[Link]([Link](i));
}
[Link]();
}
break;
default:
[Link](“Invalid Input”);
break;
}
}
}
Question 9.
Write a program to accept name and total marks of N number of students in two single
subscript array name[] and total marks[ ]. [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] ‘
Solution:
import [Link].*;
import java. util. Scanner;
class NameMarks {
public static void main(String argsO) throws IOException {
Scanner sc = new Scanner([Link]);
[Link](“Enter number of students:”);
int N = [Link]( );
String named = new String[N];
int totalmarksG = new int[N];
double deviation[ ] = new double[N];
double sum = 0;
for (int i = 0; i < N; i+ +) {
[Link](“Enter Name of the Student:”);
name[i] = [Link]( );
[Link](“Enter Marks:”);
totalmarks[i] = [Link];
sum = sum + totalmarks [i];
}
double average = sum / N;
[Link](“The average of the total marks of ” +N+” number of students:”
+average);
for (int i = 0; i < N; i+ +) {
deviadon[i] = total marks (i] – average;
[Link](“Deviation of” + name[i] + “s marks with the average:” +deviation[i]);
}
}
}