Few expected programs for ICSE 2012 examination with solution are
posted here. Last week I have posted theoretical expected questions for ICSE 2012Computer paper .
BlueJ program on wage calculation
A man is paid the hourly rate ® for thr first 35 hours he works in
a week. Thereafter he is paid at 1.5 times that hourly rate ® for the next 25
hours he works in a week and at twice the hourly rate ® for a further 10 hours
in a week. He is not allowed to work for more than 70 hours in a week.
Taking that the number of hours worked (H) and the rate per hour ®
as inputs, the weekly wages (W) are to be calculated and printed. Write a java
program for the above situation and print the weekly wages.
import java.io.*;
class Payment
{
double w,r;
int h;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void take()throws
IOException
{
while(true)
{
System.out.println("Enter the Hours worked:");
h=Integer.parseInt(br.readLine());
if(h>0
&& h<=70)
break;
}
System.out.println("Enter
the Wage Rate:");
r=Double.parseDouble(br.readLine());
if(h<=35)
{
w=h*r;
h=0;
}
else if(h>35)
{
w=35*r;
h=h-35;
}
if(h>25)
{
w+=25*r*1.5;
h=h-25;
}
else if(h>0)
{
w+=h*1.5*r;
h=0;
}
if(h>0)
{
w+=h*2*r;
}
System.out.println("Payment Rs." + w);
}
public static void main(String args[])throws IOException
{
Payment ob=new Payment ();
ob.take();
}
}
Sample input and output
Enter the Hours worked:
89
Enter the Hours worked:
70
Enter the Wage Rate:
2
Payment Rs.185.0
BlueJ programs on pattern
Print the pattern using java program
1
1
2 1
1
2 3 2 1
1
2
3 4 3
2 1
class Pat
{
int i,j,k,x;
public void take()
{
for(i=0;i< 4;i++)
{
x=1;
for(j=i;j< 3;j++)
System.out.print(" ");
for(j=0;j<=i;j++)
System.out.print(x++);
x=x-2;
for(k=0;k< i;k++)
System.out.print(x--);
System.out.println();
}
}
public static void main(String args[])
{
Pat ob=new Pat ();
ob.take();
}
}
A
A B
A B C
A
B C D
class border
{
int i,j,k=1;
char x='A';
public void take()
{
for(i=0;i< 4;i++)
{
x='A';
for(j=i;j< 3;j++)
System.out.print(" ");
for(j=0;j< k;j++)
{
if(j%2==0)
{
System.out.print(x);
x=(char)(x+1);
}
else
System.out.print("
");
}
k=k+2;
System.out.println();
}
}
public static void main(String args[])
{
border ob=new border();
ob.take();
}
}
Write a program in java that outputs the results of the following
evaluations based on chice entered by user.
1.
Print the factors of the number
2.
Print the factorial of the number
3.
Check whether the number is prime or not
4.
Check the entered number is perfect or not
import java.io.*;
class Number
{
int i,n;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
public void take()throws
IOException
{
System.out.println("Enter the number:");
n=Integer.parseInt(br.readLine());
System.out.println("Enter the Choice ('1' for showing factors, '2'
for factorial , '3' for prime checking and '4' for perfect number
checking:");
i=Integer.parseInt(br.readLine());
if(i==1)
factors(n);
else if(i==2)
factorial(n);
else if(i==3)
prime(n);
else if(i==4)
perfect(n);
else
System.out.println("Wrong
Choice..");
}
private void perfect(int n)
{
int i,s=0;
for(i=1;i< n;i++)
{
if(n%i==0)
s+=i;
}
if(s==n)
System.out.println(n +
" is a perfect number.");
else
System.out.println(n +
" is not a perfect number.");
}
private void prime(int n)
{
int i;
for(i=2;i< n;i++)
{
if(n%i==0)
break;
}
if(i==n)
System.out.println(n +
" is a prime number.");
else
System.out.println(n +
" is not a prime number.");
}
private void factors(int n)
{
int i;
System.out.println("\nFactors of "+n
+ " are=");
for(i=1;i< n;i++)
{
if(n%i==0)
System.out.print(" "+i);
}
}
private void factorial(int n)
{
int i,f=1;
for(i=2;i<=n;i++)
{
f=f*i;
}
System.out.println("\nFactorial value ="+f);
}
public static void main(String args[])throws IOException
{
Number ob=new Number ();
ob.take();
}
}
Define a class Stock having the following members:
Data Members: name, quantity, rate
Function members are:
Public void input() to input name, quantity and rate
Public void sell(int x)- reduce x quantity from stock after
checking stock
Public void add(int y) – add y quantity to the stock
Public void display() – display current stock position
class Xyz
{
int q;
double rate;
String name;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
public void input()throws
IOException
{
System.out.println("Enter the name:");
name=br.readLine();
System.out.println("Enter the quantity:");
q=Integer.parseInt(br.readLine());
System.out.println("Enter the rate:");
rate=Double.parseDouble(br.readLine());
}
public void sell(int x)
{
q=q-x;
}
public void add(int y)
{
q=q-y;
}
public void display()
{
System.out.println("Name="+name);
System.out.println("Quantity
Balance="+q);
System.out.println("Rate="+rate);
}
}
BlueJ program on lexicography
Write a java program to accept a string and display the words in
the lexicographical order I,e., in the dictionary order. For example, if the
input string is “java is an object oriented programming language”, the output
will be: “an is java language object oriented programming”
import java.io.*;
class Strg
{
String name;
String str[]=new String [30];
int i,j,x=0;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
public void input()throws
IOException
{
System.out.println("Enter the sentence:");
name=br.readLine();
while(true)
{
i=name.indexOf(' ');
if(i<0)
break;
str[x++]=name.substring(0,i);
name=name.substring(i+1);
}
str[x]=name;
show();
}
public void show()
{
for(i=0;i< x;i++)
{
for(j=i+1;j<=x;j++)
{
if(str[i].compareTo(str[j])>0)
{
name=str[i];
str[i]=str[j];
str[j]=name;
}
}
}
name="";
for(i=0;i<=x;i++)
name=name+str[i]+ " ";
name=name.trim();
System.out.println("Result="+name);
}
this is very helpful
ReplyDeletesir can u hlp me do this program...
ReplyDeleteJ
EE
UUU
LLLLL
BBBBB
Program will be posted very soon.
Delete