ICSE 2012 Programs

For any queries related to the programs you can either leave a comment below 
or SMS me at 9934183218 of mail me at nilabja.sarkar@gmail.com

Question 4

( FUNCTION TYPE )

import java.io.*;
class Library
{
int acc_num;
String title;
String author;

void input() throws IOException
{
InputStreamReader x = new InputStreamReader(System.in);
BufferedReader y = new BufferedReader(x);

System.out.println(“Enter accession number”);
acc_num=Integer.parseInt(y.readLine());

System.out.println(“Enter Book Title”);
title=y.readLine();

System.out.println(“Enter author”);
author=y.readLine();
}

void compute() throws IOException
{
InputStreamReader x = new InputStreamReader(System.in);
BufferedReader y = new BufferedReader(x);
int d;

System.out.println(“Enter no. of days delayed”);
d=Integer.parseInt(y.readLine());
System.out.println(“Fine = Rs.”+(d*2));
}

void display()
{
System.out.println(“Accession Number “+”\tTitle”+”\t\tAuthor”);
System.out.println(acc_num+”\t\t\t”+title+”\t\t”+author);
}

public static void main() throws IOException
{
Library obj = new Library();
obj.input();
obj.compute();
obj.display();
}
}

Question 5

( IF…ELSE TYPE )

import java.io.*;
class Tax
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);

double TI,tax;
int age,gender;

System.out.println(“Enter age”);
age=Integer.parseInt(y.readLine());
System.out.println(“Enter 1 for Male and 2 for Female”);
gender=Integer.parseInt(y.readLine());
if(age>65 || gender==2)
{
System.out.println(“Wrong category”);
System.exit(0);
}

System.out.println(“Enter taxable annual income”);
TI=Double.parseDouble(y.readLine());
if(TI<=160000)
tax=0.0;

else if(TI>160000 && TI<=500000)
tax=0.10*(TI-160000);
else if(TI>500000 && TI<=800000)
tax=34000 + (0.20*(TI-500000));
else
tax=94000 + (0.30*(TI-800000));

System.out.println(“Tax Payable = Rs.”+tax);
}
}

Question 6

( STRING TYPE )

import java.io.*;
class DoubleLetter
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);
String s;
System.out.println(“Enter a sentence”);
s=y.readLine();
s=s.toUpperCase();
int i,n=0;
char ch1,ch2;
int l=s.length();
System.out.println(s);
for(i=0;i<l-1;i++)
{
ch1=s.charAt(i);
ch2=s.charAt(i+1);
if(ch1==ch2)
{
n++;
}
}
System.out.println(“No. of double letter sequences = “+n);
}
}

Question 7

( FUNCTION TYPE )

class PolygonOverload
{
void polygon(int n, char ch)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
System.out.print(ch);
}
System.out.println();
}
}

void polygon(int x, int y)
{
for(int i=1;i<=x;i++)
{
for(int j=1;j<=y;j++)
{
System.out.print(“@”);
}
System.out.println();
}
}

void polygon()
{
for(int i=1;i<=3;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(“*”);
}
System.out.println();
}
}

public static void main()
{
PolygonOverload obj = new PolygonOverload();
obj.polygon(2,’o’);
obj.polygon(2,5);
obj.polygon();
}
}

Question 8

( SWITCH…CASE MENU DRIVEN TYPE )

import java.io.*;
class MenuDriven2012
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);
int i,n,ch,r,sum=0;
int f=0,s=1,t;
System.out.println(“1. Fibonacci Series: 0,1,1,2,3 … 10 terms”);
System.out.println(“2. Sum of digits”);
System.out.println(“Enter choice”);
ch=Integer.parseInt(y.readLine());

switch(ch)
{
case 1:
for(i=1;i<=10;i++)
{
System.out.print(f+”,”);
t=f+s;
f=s;
s=t;
}
break;

case 2:
System.out.println(“Enter a number”);
n=Integer.parseInt(y.readLine());
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
System.out.println(“Sum of digits = “+sum);
break;

default:
System.out.println(“Wrong choice…”);
}
}
}

Question 9

( STRING ARRAY TYPE )

import java.io.*;
class CityCodeSearch
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);

String city[]=new String[10];
String std[]=new String[10];
int i,pos=-1;
int low=0,up=9,mid;

System.out.println(“Enter 10 city  names of std codes in sorted order”);
for(i=0;i<10;i++)
{
System.out.println(“Enter city”);
city[i]=y.readLine();
System.out.println(“Enter std code”);
std[i]=y.readLine();
}

System.out.println(“Enter the search element”);
String src=y.readLine();

for(i=0;i<10;i++)
{
if(src.equalsIgnoreCase(city[i]))
{
pos=i;
break;
}
}

if(pos==-1)
System.out.println(“Search Unsuccessful”);
else
{
System.out.println(“Search Successful”);
System.out.println(“City : “+city[pos]);
System.out.println(“STD Code : “+std[pos]);
}
}
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s