Share this:
ISC Computer Practical Paper – 2011

Question  1.

Write a program to input a natural number less than 1000 and display it in words.
Test your program for the given sample data and some random data.
Sample Data:
Input: 29
Output: TWENTY NINE
Input: 17001
Output: OUT OF RANGE
Input: 119
Output: ONE HUNDRED AND NINETEEN
Input:500
Output: FIVE HUNDRED

SOLUTION:

import java.io.*;
public class num
{
//Declaring Instance variables
int n;
//Method to take input
void inputNumber() throws IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“\nINPUT:\t”);
n=Integer.parseInt(inp.readLine());
}
//Method to Extract digits , call other methods and display output
public void extract()
{
String str=””,str1=””,str2=””;
int hund=0,tens=0,units=0,i=0;
if(n999)
System.out.println(“\nOUT OF RANGE “);
else
{
while(n!=0)
{
if(i==0)
units=n%10;
else if(i==1)
tens=n%10;
else if(i==2)
hund=n%10;
i++;
n=n/10;
}
if(hund>0)
str=word1(hund)+ ” HUNDRED “;
if(tens>1)
str1= word2(tens);
if(tens==1)
str2= word3(units);
else
str2=word1(units);
if((!str.equals(“”))&&(!str1.equals(“”) || !str2.equals(“”)))
str=str+ “AND “;
if(!str1.equals(“”))
str=str+ str1+ ” “;
if(!str2.equals(“”))
str=str+ str2;
System.out.println(“OUTPUT:\t”+str);
}//EndElse
}
//Method to convert digits 0-9
String word1(int x)
{
String s=””;
switch(x)
{
case 1:
s=”ONE”;
break;
case 2:
s=”TWO”;
break;
case 3:
s=”THREE”;
break;
case 4:
s=”FOUR”;
break;
case 5:
s=”FIVE”;
break;
case 6:
s=”SIX”;
break;
case 7:
s=”SEVEN”;
break;
case 8:
s=”EIGHT”;
break;
case 9:
s=”NINE”;
break;
}
return s;
}
//Method to convert numbers 20, 30,40,…..90
String word2(int x)
{
String s=””;
switch(x)
{
case 2:
s=”TWENTY”;
break;
case 3:
s=”THIRTY”;
break;
case 4:
s=”FOURTY”;
break;
case 5:
s=”FIFTY”;
break;
case 6:
s=”SIXTY”;
break;
case 7:
s=”SEVENTY”;
break;
case 8:
s=”EIGHTY”;
break;
case 9:
s=”NINETY”;
break;
}
return s;
}
//Method to convert numbers 10 – 19
String word3(int x)
{
String s=””;
switch(x)
{
case 0:
s=”TEN”;
break;
case 1:
s=”ELEVEN”;
break;
case 2:
s=”TWELVE”;
break;
case 3:
s=”THIRTEEN”;
break;
case 4:
s=”FOURTEEN”;
break;
case 5:
s=”FIFTEEN”;
break;
case 6:
s=”SIXTEEN”;
break;
case 7:
s=”SEVENTEEN”;
break;
case 8:
s=”EIGHTEN”;
break;
case 9:
s=”NINETEEN”;
break;
}
return s;
}
//    Main method to call other methods
public static void main(String args[]) throws IOException
{
num obj=new num
obj.inputNumber();
obj.extract();
}
}
—————–END——————–

Question 2.

Encryption is a technique of coding messages to maintain their secrecy. A String array of size ‘n’ where ‘n’ is greater than 1 and less than 10, stores single sentences (each sentence ends with a full stop) in each row of the array.
Write a program to accept the size of the array. Display an appropriate message if the size is not satisfying the given condition. Define a string array of the inputted size and fill it with sentences row-wise. Change the sentence of the odd rows with an encryption of two characters ahead of the original character. Also change the sentence of the even rows by storing the sentence in reverse order. Display the encrypted sentences as per the sample data given below.
Test your program on the sample data and some random data.
Sample Data:
Input: n=4
IT IS CLOUDY.
IT MAY RAIN.
THE WEATHER IS FINE.
IT IS COOL.
Output:
KV KU ENQWFA.
RAIN MAY IT.
VJG YGCVJGT KU HKPG.
COOL IS IT.
Input: n=13
Output: INVALID ENTRY

SOLUTION:

import java.io.*;
public class Sentence
{
//Declare Instance variables
String str[]; //to store original strings
String encryp[];//to store encrypted strings
int n;//to store number of strings
int count;//to be used in the methods encrypt and reverse
//Method to input data
void takeInput() throws IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
String s;
count=0;
System.out.print(“n =\t”);
n=Integer.parseInt(inp.readLine());
if(n9)
System.out.println(“\nINVALID ENTRY:”);
else
{
str=new String[n];
encryp=new String[n];
System.out.println(“\nEnter sentences terminated with full stop”);
for(int x=0;x
{            s=inp.readLine().trim();
if(s.charAt(s.length()-1)!=’.’)
{
System.out.println(“\nSentence must terminate with a Full stop. Enter again.”);
x–;
continue;
}
else
str[x]=s;
}//EndFor
callEncryption();
}//EndElse
}//End Method
//Method to extract strings and encrypt
void callEncryption()
{
for(int x=0;x
{
if(x%2==0)
encrypt(str[x]);
else
reverse(str[x]);
}//EndFor
}//EndMethod
//Method to encrypt string
void encrypt(String s)
{
char ch;
String temp=””;
int len=s.length();
for(int x=0;x
{
ch=s.charAt(x);
if((ch>=65 && ch=97 && ch
{
ch=(char)(ch+2);
if(ch>90 && ch
{
ch=(char)((64+ch-90));
}
else if(ch>122)
{
ch=(char)((96+ch-122));
}
}//Endif
temp=temp+ch;
}//EndFor
encryp[count]=temp;
count++;
}//EndMethod
//Method to Reverse String
void reverse(String s)
{
int x;
String s1, word=””;
s=s.substring(0,s.length()-1);
while(true)
{
x=s.lastIndexOf(” “);
if(x
break;
s1=s.substring(x).trim();
word+=s1+”  “;
s=s.substring(0,x).trim();
}//EndWhile
word+=s;
encryp[count]=word;
count++;
}//EndMethod
//Method to print encrypted strings
void showOutput()
{
System.out.println(“\nOutput:”);
for(int x=0;x
System.out.println(encryp[x]);
}//EndMethod
//Main method to call other methods
public static void main(String args[]) throws IOException
{
Sentence obj=new Sentence();
obj.takeInput();
obj.showOutput();
}//EndMain
}//EndClass
——————end—————

Question 3.

Design a program which accepts your date of birth in dd mm yyyy format. Check whether the date entered is valid or not. If it is valid, display “VALID DATE”, also compute and display the day number of the year for the date of birth. If it is invalid, display “INVALID DATE” and then terminate the program.
Test your program  for the given sample data and some random data.
Input:
Enter your date of birth in dd mm yyyy format
05
01
2010
Output:
VALID DATE
5
Input:
Enter your date of birth in dd mm yyyy format
03
04
2010
Output:
VALID DATE
93
Input:
Enter your date of birth in dd mm yyyy format
34
06
2010
Output:
INVALID DATE

SOLUTION:

import java.io.*;
public class ISC
{
//Declare Instance variable
int d,m,y;
//Method to input date
void takeInput() throws IOException
{
BufferedReader inp=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter your date of birth in dd mm yyyy format:”);
d=Integer.parseInt(inp.readLine());
m=Integer.parseInt(inp.readLine());
y=Integer.parseInt(inp.readLine());
}//EndMethod
//Method to check validity of date
void checkValidity()
{
int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
int dateToDays=0;
//Check year is leap or not
int l=checkLeap(y);
days[1]+=l;//to add 1 to feb if year is leap
if(m12  || ddays[m-1] || y
System.out.println(“INVALID DATE”);
else
{
for(int x=0;x
{
dateToDays+=days[x];
}//EndFor
dateToDays+=d;//to add days of the current month
System.out.println(“\nVALID DATE\n”+ dateToDays);
}//ENDELSE
}//ENDMETHOD
//Method to find and return year is leap or not
int checkLeap(int year)
{
if (year% 4 == 0)
{
if (year % 100 != 0)
return 1;
else if (year % 400 == 0)
return 1;
else
return 0;
}
else
return 0;
}//EndMethod
//Main method to call other methods
public static void main(String args[]) throws IOException
{
ISC obj=new ISC
obj.takeInput();
obj.checkValidity();
}//EndMain
}//EndMethod

——————end——————-




Share this:


EcoleBooks | ISC COMPUTER PRACTICAL PAPER 2011 SOLVED

subscriber

Leave a Reply

Your email address will not be published. Required fields are marked *

Accept Our Privacy Terms.*