ICSE 2011 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 Mobike
{
String name;
int bno, phno, days, charge;

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

System.out.println(“Enter name”);
name=y.readLine();
System.out.println(“Enter bike number”);
bno=Integer.parseInt(y.readLine());
System.out.println(“Enter phone number”);
phno=Integer.parseInt(y.readLine());
System.out.println(“Enter number of days for rent”);
days=Integer.parseInt(y.readLine());

}

void computer()
{
if(days<=5)
charge=500*days;
else if(days>5 && days<=10)
charge=(500*5)+(days-5)*400;
else if(days>10)
charge=(500*5)+(400*5)+(days-10)*200;
}

void display()
{
System.out.printf(“%s %6s %10s %15s %10s \n”,”Bike No.”,”Phone No.”,”Name”,”Days”,”Charge”);
System.out.printf(“%-5d %10d %15s %10d %10d \n”,bno,phno,name,days,charge);
}

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

Question 5

( ARRAY TYPE )

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

int ARR[]=new int[10];
int i,j,temp,sml,pos;

for(i=0;i<10;i++)
{
System.out.println(“Enter weight of person : “+(i+1));
ARR[i]=Integer.parseInt(y.readLine());
}

for(i=0;i<10;i++)
{
sml=ARR[i];
pos=i;
for(j=i+1;j<10;j++)
{
if(ARR[j]>sml)
{
sml=ARR[j];
pos=j;
}
}
temp=ARR[i];
ARR[i]=sml;
ARR[pos]=temp;
}

System.out.println(“Weight in sorted order :”);
for(i=0;i<10;i++)
{
System.out.println(ARR[i]);
}
}
}

Question 6

( ITERATION TYPE USING FOR & WHILE )

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

int n,i,temp,f,r,sum=0;
System.out.println(“Enter a number”);
n=Integer.parseInt(y.readLine());
temp=n;

while(temp>0)
{
r=temp%10;
f=1;
for(i=r;i>=1;i–)
{
f=f*i;
}
sum=sum+f;
temp=temp/10;
}

if(sum==n)
System.out.println(“Special Number”);
else
System.out.println(“Not a Special Number”);

}
}

Question 7

( STRING TYPE )

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

String s,w=””;
System.out.println(“Enter a word”);
s=y.readLine();
s=s.toLowerCase();
int i;
char ch;
int l=s.length();
for(i=0;i<l;i++)
{
ch=s.charAt(i);
if(ch==’a’||ch==’e’||ch==’i’||ch==’o’||ch==’u’)
ch=(char)(ch+1);

w=w+ch;
}
System.out.println(w);
}
}

Question 8

( FUNCTION TYPE )

class CompareOverload
{
void compare(int n1,int n2)
{
System.out.println(Math.max(n1,n2));
}

void compare(char ch1, char ch2)
{
int n1,n2;
n1=(int)ch1;
n2=(int)ch2;

if(n1>n2)
System.out.println(ch1);
else
System.out.println(ch2);
}

void compare(String s1, String s2)
{
int l1,l2;
l1=s1.length();
l2=s2.length();

if(l1>l2)
System.out.println(s1);
else
System.out.println(s2);
}

public static void main()
{
CompareOverload obj = new CompareOverload();
obj.compare(10,20);
obj.compare(‘A’,’Z’);
obj.compare(“Computer”,”Applications”);
}
}

Question 9

( FUNCTION TYPE )

import java.io.*;
class Series2011
{
public static void main() throws IOException
{
InputStreamReader x= new InputStreamReader(System.in);
BufferedReader y= new BufferedReader(x);
int i,n,ch;
double d,sum=0.0;

System.out.println(“1. Series: 0,3,8,15,24… n terms”);
System.out.println(“2. Sum of series: 1/2 + 3/4 + 5/6 +…+ 19/20”);
System.out.println(“Enter choice”);
ch=Integer.parseInt(y.readLine());

switch(ch)
{
case 1:
System.out.println(“Enter a number”);
n=Integer.parseInt(y.readLine());
for(i=1;i<=n;i++)
System.out.print((i*i)-1 + “,”);
break;

case 2:
for(d=1;d<=19;d++)
sum=sum+(d/(d+1));

System.out.println(“1/2 + 3/4 + 5/6 +…+ 19/20 = “+sum);
break;

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

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