ICSE BlueJ Logical Program

Logical Questions for Java or BlueJ


(Note: All programs codes are Tested in BlueJ
(The programs which are not solved try it out yourself, because one same pattern questions already solved)

Questions Based on Logic & Calculation:

1. Accept the value of A, B & C then calculate this formula.
R = 6.5 (A + B)^{2}  7.3 (B + C)^{1/2}
(A + C)^{1/2}

class ques1
{
public static void main(String args[])
{
int a = 2,b = 3,c = 4;
double r;
double x = 6.5*Math.pow((a+b),2);
double y = 7.3*Math.sqrt(b+c);
double z = Math.sqrt(a+c);
r = (xy)/z;
System.out.println ("The answer is : "+r);
}
} 
2. WAP to calculate the Simple Interest.

class ques2
{
public static void main(String args[])
{
int p = 5000;
int r = 5;
int t = 2;
float si = (p*r*t)/100;
System.out.println ("Simple intrest = "+si);
}
} 
3. Calculate the area and circumference of circle. 
class ques3
{
public static void main(String args[])
{
int r = 3;
double a = 3.14*r*r;
double c = 2*3.14*r;
System.out.println ("Area of the Circle of radious "+r+" is : "+a);
System.out.println ("Circumference : "+c);
}
} 
4. Calculate the area of a triangle. 
class ques4
{
public static void main(String args[])
{
int a = 2,b = 3,c = 4;
double area;
double s = (a+b+c)/2.0;
area = Math.sqrt(s*(sa)*(sb)*(sc))/(2*a*b);
System.out.println ("Area of the Triangle");
System.out.println ("of sides "+a+","+b+","+c);
System.out.println ("is : "+area);
}
} 
5. Write a program with supporting documentation to enter any three real numbers and calculate X where:
X = Product of integer portion
Sum of decimal portion 
class ques5
{
public static void main(String args[])
{
double n1 = 12.85,n2 = 7.19,n3 = 3.65;
int i1 = (int) n1;
int i2 = (int) n2;
int i3 = (int) n3;
double d1 = n1i1;
double d2 = n2i2;
double d3 = n3i3;
double x = (i1*i2*i3)/(d1+d2+d3);
System.out.println ("The value of X is : "+x);
}
} 
Questions Based on Condition:

6. WAP to check whether a number is divisible by 5 or not. 
class ques6
{
public static void main(String args[])
{
int n = 10;
if(n%5 = = 0)
System.out.println ("The number "+n+" is divisible by 5");
else
System.out.println ("The number "+n+" is not divisible by 5");
}
} 
7. Accept a numbers and check whether the number is divisible by both 2 and 3 or not. 
class ques7
{
public static void main(String args[])
{
int n = 10;
if(n%2 = = 0 && n%3 = = 0)
System.out.println ("The number "+n+" is divisible by 2 and 3");
else
System.out.println ("The number "+n+" is not divisible by 2 and 3");
}
} 
8. Write two separate programs to accept three numbers and find which one is greater (one using if statement and another using ternary operator). 
class ques8
{
public static void main(int a,int b,int c)
{
int max = (a>b) ? ((a>c)?a:c) : ((b>c)?b:c);
System.out.print ("The Highest Number is : "+max);
}
} 
9. Accept a numbers and find out the given number is divisible by 5 or not, if not then print the nearest number from the given number which is divisible by 5. 
class ques9
{
public static void main(int n)
{
int r = n%5;
if(r = = 0)
System.out.println ("The number "+n+" is divisible by 5");
else
if(r>2)
System.out.println ("The nearest number is "+(nr+5));
else
System.out.println ("The nearest number is "+(nr));
}
} 
10. Write a program to input the basic salary of a person. He get 15% of the basic as HRA, 15% of the basic as Conveyance allowance and 10% of the basic as Entertainment allowance. The total salary is calculated by adding Basic + HRA + Conveyance + Entertainment Allowance. Calculate and print the total salary of person. 
class ques10
{
public static void main(int basic)
{
double HRA = basic*.15;
double conveyance = basic*.15;
double entertainment = basic*.10;
double totalSalary = basic + HRA + conveyance + entertainment;
System.out.println ("Total Salary : "+totalSalary);
}
} 
11. A computer salesman gets commission on the following basis:
Sales Commission Rate
Rs. 0  20,000 3%
Rs. 20,000  50,000 12%
Rs. 50,001 and more 31%
After accepting the sales as input, calculate and print his commission amount and rate of commission. 
class ques11
{
public static void main(int sales)
{
int rate = 0;
double commission = 0.0;
if(sales< = 20000)
{
rate = 3;
commission = sales*.03;
}
if(sales> = 20001 && sales< = 50000)
{
rate = 12;
commission = sales*.12;
}
if(sales> = 50001)
{
rate = 31;
commission = sales*.31;
}
System.out.println ("Commission Rate : "+rate+"%");
System.out.println ("Commission Amount : "+commission);
}
} 
12. Write a program to enter the three sides of a triangle. Decide whether it is a scalene, isosceles or equilateral triangle. 
public class ques12
{
public static void main(String args[])
{
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int c = Integer.parseInt(args[2]);
if (a = = b && b = = c && c = = a)
System.out.println ("Equileteral Triangle");
else if (a! = b && b! = c && c! = a)
System.out.println ("Scalean Triangle");
else
System.out.println ("Isoceles Triangle");
}
} 
13. A library charges fine for books returned late. Following are the fines: first five days 40 paisa per day, Six to ten days 65 paisa per day, above 10 days 80 paisa per day. Design a program to calculate the fine assuming that a book is returned N days late. 
class ques13
{
public static void main(int Ndays)
{
double fineAmount = 0;
if(Ndays< = 5)
fineAmount = Ndays*.40;
if(Ndays> = 6 && Ndays< = 10)
fineAmount = Ndays*.65;
if(Ndays>10)
fineAmount = Ndays*.80;
System.out.println ("FINE AMOUNT (Rs.) : "+fineAmount);
}
} 
14. The telephone department wishes to compute monthly telephone bills for its customers using the following rules. Minimum Rs. 250 for first 80 message units, plus 60 paise per unit for next 60 units, plus 50 paise per unit for next 60 units, plus 40 paise per unit for any units above 200. Write a program that calculates the monthly bill, with input MESSAGE (the number of message units) and CUSTNO (the registration number of a customer). Then Display the bill in following format.
CUSTOMER NO :
MESSAGE UNITS :
AMOUNT (Rs.) : 
class ques14
{
public static void main(int messageUnit,int customerNo)
{
double bill = 0;
if(messageUnit< = 80)
bill = 250;
else if(messageUnit>80 && messageUnit< = 140)
bill = 250+(messageUnit80)*0.60;
else if(messageUnit>140 && messageUnit< = 200)
bill = 250+36+(messageUnit140)*0.50;
else if(messageUnit>200)
bill = 250+36+30+(messageUnit200)*0.40;
System.out.println ("CUSTOMER NUMBER : "+customerNo);
System.out.println ("MESSAGE UNIT : "+messageUnit);
System.out.println ("BILL AMOUNT : "+bill);
}
} 
15. A security man paid at the hourly rate (R) for the first 40 hours of work in a week. Thereafter, he is paid at 1.25 times of the hourly rate (R) for the next 16 hours and at 1.5 times of the hourly rate (R) for the further hours of work in the week. Taking the numbers of hours (H) and the rate per hour (R) as input, the weekly wages (W) is to be calculated. 
class ques15
{
public static void main(int H,int R)
{
double W = 0;
if(H< = 40)
W = H*R;
else if(H>40 && H< = 56)
W = 40*R+(H40)*R*1.25;
else if(H>56)
W = 40*R+16*R*1.25+(H56)*R*1.5;
System.out.print ("The Weekly Wages : "+W);
}
} 
16. Write a program to compute BImonthly telephone charges for subscriber. Use the following information:
Fixed BImonthly rent: Rs.380
Free calls during two months: 120
Charge/call beyond free limits upto 100 calls: Rs.1
Charge per call in excess of 100 calls: Rs. 1.25 
class ques16
{
public static void main(int calls)
{
double bill = 280.0;
if(calls>120 && calls< = 220)
bill = bill+(calls120)*1;
else if(calls>220)
bill = bill+100+(calls220)*1.25;
System.out.println ("BILL AMOUNT : "+bill);
}
} 
17. Write a program to input the code of a particular item, quantity purchased and rate. Then calculate the purchased price and print it along with gift to be presented. The gifts to the customers are given in the following manner:
Amount of Purchase (Rs.) Gift
Between 100 to 500 A key ring
Between 500 to 1000 A leather purse
Above 1000 A pocket calculator 
class ques17
{
public static void main(int code, int qty, double rate)
{
double price = qty*rate;
System.out.println ("Purchase Price : "+price);
if(price> = 100 && price< = 500)
System.out.println ("Gift item : Key Ring");
if(price>500 && price< = 1000)
System.out.println ("Gift item : Leather Purse");
if(price>1000)
System.out.println ("Gift item : Pocket Calculator");
}
} 
Some Questions on multiple IF condition

Q. Write a program to take the monthly salary from the user, find and display income tax with the help of the following slab:
Monthly Salary Income Tax
8000 or less Nil
80009000 20% of Monthly salary
900010000 30% of Monthly salary
10000 or above 40% of Monthly salary 

Q. A salesman earns a commission on the value of his sales as per the following table.
Value of sales(Rs.) Commission(%)
1  999 1
1000  9999 5
10000  99999 10
Write a program to calculate and print the commission using sale value as input. The program is to keep on calculating the commission for various salesmen until a sales value zero is input. 

Q. A company wants to set target for each of the four regions (EAST, WEST , NORTH and SOUTH). The company allots the following percentage target for each region.
East 15%
West 25%
North 30%
South 30%
Write a program to pass through command line parameters, the total target amount proposed by the company and print out the breakup of the target for each region. 

Q. Write a program to find the car bill for a particular tourist.
Type of car Distance Charge Driver.
Maruti < = 100 Rs.800 Rs.100.
>100 & < = 200 Rs.800+Rs10/km Rs 300.
above 100
>200 Rs.15per km Rs 500
Sumo < = 100 Rs.600 Rs 100.
>100 & < = 200 Rs.600+Rs.8/km Rs 300
above 100
> 200 Rs.12 per km Rs.500 

Q. Write a program using method to calculate the salary increment of employees based on their basic pay. Calculate the final salary after increment.
Basic Pay Rise
10700/ 550/
12500/ 750/
15000/ 1050/ 

Q. Write a program using the this keyword, to calculate the prize amount for a cricketer depending upon his text average. Use the following date.
Test Average Graduate Prize Amount
> = 80 A Rs. 1,00,000.00
80> & > = 65 B Rs. 50,000.00
50> & > = 40 C Rs. 25,000.00
<40 D Rs. 10,000.00 

Q. Using ifelse statements write a program in java to calculate the grade as per the given criteria:
Marks Grade
> = 80 and <100 Excellent
> = 70 and <80 First Div.
> = 60 and <70 Second Div.
> = 50 and <60 Third Div.
Less than 50 Fail 

Q. Write a program to assign values the variable basic salary and calculate the DA and the gross salary and print them. The DA is calculated as per the rules given below:
if basic< 2000 then DA is 5% of basic
if basic> = 2000 & <7000 then DA is 8% of basic
if basic> = 7000& <10000 then DA is 10% of basic
if basic> = 10000 then DA is 12% of basic
Gross Salary = Basic + DA. 

Q. There are 55 employees in an organization. You have to display the number of employees getting NetSalary above 20000 by taking only Basic_Salary as input and following the table given below.
Basic Salary DA (% Basic_salary) IT (% Gross_Salary)
Below 5000 8% 6%
5000 to < 10000 15% 9%
10000and above 18% 12%
Where DA and IT are Dearness Allowance and income Tax respectively.
Gross_Salary = Basic_Salary + DA
Net_Salary = Gross_Salary  IT 

Q. Calculate and display the traveling allowance for 50 employees of an organization by taking distance traveled as input. The organization gives traveling allowance according to the following table.
Distance Amount.
< = 20 Rs 200
>20 and < = 50 Rs 200 + Rs 5 per extra km above 20
>50 and < = 100 Rs 500 + Rs 5 per extra km above 50.
>100 Rs 15 per km. 

Q. Commission according to the following tables:
Sale (in Rs.) Commission(% of sale)
8000 or less Nil
8000  9000 12%
9000  10000 15%
10000 or above 18%
apart from this each salesman gets a fixed allowance of Rs 550 and also a bonus of Rs 500 if a salesman achieves the target of 10000. Display the total income of each salesman along with the sales. Also display the number of salesman having income of 5000 or above.


Q. A company has 120 employees who are divided into four grades as follows:
Grade Basic( Rs. per month) D.A.(% of Basic) H.R.A.(% of Basic)
1 10,000 or more 40% 30%
2 5,000  10,000 40% 25%
3 < 5,000 but > 2,000 30% 20%
4 2,000 or less 30% 15%
If the salary which is the total of Basic, D.A., and H.R.A., is above Rs.50,000 per month then Income Tax at the rate of 30% of the annual salary exceeding 50,000 is deducted on monthly basis at source. Taking name of the employees and the Basic(monthly) pay as inputs, a pay slip, which contains Name, Basic monthly pay, DA, HRA, Monthly Income Tax and Net Monthly Salary, for each employee is to be printed. Write a java program to perform this job. 

Q. Define class calcComm with member variables: sales, commission
method:
void acceptsales() to accept sales value
float commAmt() to calculate and return commission amount.
the commission will be calculated according to the following criteria
sales commission rate
above or equal to 5000 15%
above or equal to 3000 but below 5000 10%
above or equal to 1000 but below 3000 5%
below 1000 2% 

Q. Define class calculateBill having member variable: calls, charge
Member methods:
void calCharge(int type) to calculate the telephone bill.
Type is type of connection
1. For domestic
2. For business
Bill will be calculated according to the following rule
Monthly rent  Rs. 450
Number of call free  100
Next 150 calls  Rs. 1/call
Next 100 calls  Rs. 1.50/call
Extra calls  Rs. 2/call
for business type connection Rs 50/ will be paid extra by the customer
void display() to show the bill amount
Write main program to accept no. of calls and display menu
1. Domestic Connection
2. Business Connection
Enter Your Choice (1 or 2)
Bill will be calculated according to the option entered by the user and then finally display the bill. 

Q. Write a program to calculate monthly telephone bill for a consumer after accept number of call according to given criteria.
Monthly rent Rs 400/
No. of free calls 100
for next 150 calls Rs. 1.25/call
for extra calls Rs. 1.50/call 

Q. Write a program to input the sales or any 20 sales men. Calculate and print the commission with an added allowance of Rs. 500. The commission can be calculated by using the following table:
Sales Commission
Upto 5000 nil
50018000 10%
800110,000 12%
10,001 Or more 15% 

Q. Write a Java program to accept an amount from the user and hence
find in each case:
a) No of Rs. 100 notes and the remainder amount.
b) No of Rs. 50 notes and the remainder amount.
c) No of Rs. 20 notes and the remainder amount.
d) No of Rs. 10 notes and the remainder amount.
Eg. In Rs. 542; No of Rs. 100 = 5, Remainder = Rs. 42
No of Rs. 50 = 10, Remainder = Rs. 42
No of Rs. 20 = 27, Remainder = Rs. 2.
No of Rs. 10 = 54, Remainder = Rs. 2. 

Q. A class namely student has three data member Name, roll and Marks of 5 Subjects the steam is assigned based on the following criteria :
Avg. Marks Stream
90% and above science with computers
80% ___89% science without Computers
70%____79% commerce with Maths
60%___69% commerce without Maths
Write a program to declare a class student and allot the stream and print them. 

Q. ABC stand decided to take charge for the parking of 2wheeler, 3wheeler and 4wheller (same charges) as per the following criteria:
No. of Hrs. Parked Charge
upto 8 hrs Rs 10
next 8 hrs Rs. 6 for additional 8 hours
above 16 hours Rs. 5 for each addition 8 hrs.
Input number of hours parked and prints the charges as per given criteria. 

Questions Based on Loops or Nested Loops

18. Display the first ten natural numbers (using for, while and dowhile loop). 

19. Display the first ten odd numbers and the sum of them. 

20. Write a program to Display the table of given number. 

21. The present population of a country is PO and it increases by 5% every year. The population (P) after n years is given by the formula: P = PO (1.05)n. Write a program to find the population every year for the next ten years. 

22. Generate the following series 
(a) 1 2 4 7 11 16 22 
class ques22a
{
public static void main(String args[])
{
int s = 1;
for(int i = 1;i< = 7;i++)
{
System.out.print (s+" ");
s = s+i;
}
}
} 
(b) 0 1 3 6 10 15 21 
class ques22b
{
public static void main(String args[])
{
int s = 0;
for(int i = 1;i< = 7;i++)
{
System.out.print (s+" ");
s = s+i;
}
}
} 
(c) 0 3 8 15 24 35 
class ques22c
{
public static void main(String args[])
{
for(int i = 1;i< = 6;i++)
System.out.print ((int) Math.pow(i,2)1 + " ");
}
} 
(d) 0 1 1 2 3 5 8 13 (fibonacci series) 
class ques22d
{
public static void main(String args[])
{
int a = 0,b = 1,c,i;
for(i = 1;i< = 8;i++)
{
System.out.print (a+" ");
c = a+b;
a = b;
b = c;
}
}
} 
(e) 1 2 2 4 8 32 
class ques22e
{
public static void main(String args[])
{
int a = 1,b = 2,c,i;
for(i = 1;i< = 6;i++)
{
System.out.print (a+" ");
c = a*b;
a = b;
b = c;
}
}
} 
(f) 2 3 4 6 6 9 8 12 10 15 
class ques22f
{
public static void main(String args[])
{
for(int i = 1;i< = 5;i++)
System.out.print ((i*2)+" "+(i*3)+" ");
}
} 
(g) 1 5 2 4 3 3 4 2 5 1 
class ques22g
{
public static void main(String args[])
{
int i;
int a = 1,b = 5;
for(i = 1;i< = 5;i++)
{
System.out.println (a+" ");
System.out.println (b+" ");
a++;
b;
}
}
} 
(h) 0 7 26 63 124 
class ques22h
{
public static void main(String args[])
{
int n;
for(int i = 1;i< = 5;i++)
{
n = ((int) Math.pow(i,3))  1;
System.out.print (n+" ");
}
}
} 
23. Calculate the Sum of given series 
(a) S = 1 + 2  3 + 4  5 + 6  7 + 8  9 + ……………… + N^{th} 

(b) S = (X+1)^{2}+(X+2)^{3}+(X+3)^{4}+(X+4)^{5}+…………… +(X+N)^{N+1} 

(c) S = (1+2) + (1+2+3) + (1+2+3+4) + ………… + (1+…………+15) 

(d) S = 1 + X + 2!X^{2} + 3!X^{3} + 4!X^{4} 

(e) S = X^{2} + X^{3} + X^{4} + X^{5} + X^{6}
2! 3! 4! 5! 6!


(f) S = 1x2 + 2x3 + 3x4 + 4x5 + ... + 19x20 

Typical Logical Questions:

24. WAP to display the factorial of the first ten natural numbers. 
class ques24
{
public static void main(String args[])
{
int f = 1;
for(int i = 1;i< = 10;i++)
{
f = f*i;
System.out.println ("The factorial of number "+i+" is "+f);
}
}
} 
25. Write a program to print all the factors of a number. 
