Conditional Statements:
1. 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.
2. Write a program to enter the three sides of a triangle. Decide whether it is a scalene, isosceles or
equilateral triangle.
3. 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.) :
4. 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.
5. Write a program to compute BI-monthly telephone charges for subscriber. Use the following
information:
Fixed BI-monthly 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
6. 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
7. 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
8000-9000 20% of Monthly salary
9000-10000 30% of Monthly salary
10000 or above 40% of Monthly salary
8. 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.
9. 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.
10. 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
11. 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/-
12. Write a program 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
13. There are 55 employees in an organization. You have to display the number of employees getting
Net-Salary 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
14. 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.
15. 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.
16. 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.
17. 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.
18. Write a program to accept ages (in year) of 100 peoples. Then count & display the number of
people lies between each age categories. The output is look like this,
INDIAN AGE SURVEY
Children (1-9) :
Toddlers (10-17) :
Adults (18-25) :
Married (26-60) :
Retired (61-80) :
Elder (81-99) :
Centurion (above 100) :
19. 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.
20. 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.
21. An employee wants to deposit certain sum of money under “Term Deposit” scheme in Syndicate
Bank. The bank has provided the tariff of the scheme which is given below:
NO. OF DAYS RATE OF INTERES NO. OF DAYS RATE OF INTEREST
Up to 180 days 5.5% Exact 365 days 9.0%
181 to 364 days 7.5% More than 365 days 8.5%
22. Electronic world' has announced an off-Season discount on the purchase of certain items as per
the given bellow
Amount Discount on A/C Discount on LCD TV
up to Rs. 20,000 5% 2.5%
Rs. 20,001 - Rs. 40,000 7.5% 5%
Rs. 40,001 - Rs. 60,000 10% 7% more than Rs. 60,000 12% 8.5%
23. . Mr. Kumar is an LIC agent. He offers discount to his policy holders on the annual premium.
However, he also gets commission on the sum assured as per the given tariff.
Sum Assured Discount Commission
Up to Rs. 1,00,000 5% 2%
Rs. 1,00,001 and up to Rs. 2,00,000 8% 3%
Rs. 2,00,001 and up to Rs. 5,00,000 10% 5%
More than Rs. 5,00,000 15% 7.5%
Write a program to input name of the policy holder, the sum assured and first annual premium.
Calculate the discount of the policy holder and the commission of the agent. The program
displays all the details as:
Name of the policy holder :
Sum assured :
Premium :
Discount on the first premium :
Commission of the agent :
24. Given below is a hypothetical table showing rate of income tax for an India citizen, who is below
or up to 60 years.
Taxable income (TI) in Rs. Income Tax in Rs.
Up to Rs. 2,50,000 Nil
More than Rs. 2,50,000 and less than (TI - 1,60,000) * 10%
or equal to Rs. 5,00,000
More than Rs. 5,00,000 and less than or (TI - 5,00,000) * 20% + 34,000
equal to Rs. 10,00,000
More than Rs. 10,00,000 (TI - 10,00,000) * 30% + 94,000
Write a program to input the name, age and taxable income of a person. If the age is more than
60 years then display the message "Wrong Category". If the age is less than or equal to 60 years
then compute and display the income tax payable along with the name of tax payer, as per the
table given above
Switch statement:
1. Write a program to read a weekday number and print weekday name using switch statement
2. Write a java program that takes a grade letter from the user (A, B, C, D, or F) and prints the
corresponding GPA value
3. Write a java program that uses a switch statement to print the name of the month
corresponding to a given integer value.
4. Write a java program that calculates the total cost of an order based on the number of
items and a per-item cost that varies depending on the type of item
5. Using the switch statement, write a menu-driven program to:
(i) To find and display all the factors of a number input by the user (including 1 and excluding
the number itself)
(ii) To find and display the factorial of a number input by the user. The factorial of a
non-negative integer n, denoted by n!, is the product of all integers less than or equal to n.
6. Using the switch statement, write a menu-driven program to calculate the maturity amount of a
bank deposit. The user is given the following options: (i) Term Deposit (ii) Recurring Deposit
For option (i) accept Principal (p), rate of interest (r) and time period in years (n). Calculate and
output the maturity amount (a) receivable using the formula a = p[1 + r / 100]n.
For option (ii) accept monthly installment (p), rate of interest (r) and time period in months (n).
Calculate and output the maturity amount (a) receivable using the formula a = p * n + p * n(n
+ 1) / 2 * r / 100 * 1 / 12.
For an incorrect option, an appropriate error message should be displayed.
7. Using the switch statement, write a menu-driven program:
(i) To check and display whether a number input by the user is a composite number or
not. (A number is said to be composite if it has one or more than one factor excluding 1
and the number itself.). Example: 4, 6, 8, 9, …
(ii) To find the smallest digit of an integer that is input: Sample Input: 6524 Output:
Smallest digit is 2.
8. Using the switch statement, write a menu-driven program to:
(i) Generate and display the first 10 terms of the Fibonacci series 0, 1, 1, 2, 3, 5, … The
first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of
the previous two.
(ii) (ii) Find the sum of the digits of an integer that is input. Sample Input: 15390 Sample
Output: Sum of the digits = 18. For an incorrect choice, an appropriate error message
should be displayed.
9. Write a menu-driven program to accept a number and check and display whether it is a prime
number or not, or an automorphic number or not. Use switch-case statement.
(a) Prime number: A number is said to be a prime number if it is divisible only by 1 and itself
and not by any other number. Example: 3, 5, 7, 11, 13, etc.
(b) Automorphic number: An automorphic number is the number which is contained in the last
digit(s) of its square. Example: 25 is an automorphic number as its square is 625 and 25 is
present as the last two digits.
Loops:
1. 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.
2. Generate the following series:
Note: you can use any predefined methods of Math class.
a. 1 2 4 7 11 16 22
b. 0 1 3 6 10 15 21
c. 0 3 8 15 24 35
d. 1 2 2 4 8 32
e. 2 3 4 6 6 9 8 12 10 15
f. 1 5 2 4 3 3 4 2 5 1
g. 0 7 26 63 124
h. S = (1+2) + (1+2+3) + (1+2+3+4) + ………… + (1+…………+15)
3. Write a program to display the factorial of the first ten natural numbers.
4. Write a program to generate all Perfect numbers up to 1000.
5. Write a program to accept a number then print the sum of digits and number of digits present in it.
6. Write a program to check whether all digits of the given number are same type or not (i.e. all are
odd, all even numbers or both present)
7. Write a program to accept a number and then add all digits until you found a single digit number. If
that single digit number is 1, then that number is called lucky number. (e.g. if number is 2345 then
sum of its digits becomes 14, further sum of this digits is 5, so the number is not a lucky number)
8. Write a program to accept any 10 numbers. Then count how many numbers are odd, even or zero
among them.
9. Write a program to accept any 10 numbers. Then count how many numbers are positive, negative
or zero among them.
10. Write a program to accept any number between 1 to 10, and then display the number in word.
11. Write a program to accept 10 numbers. Display the second highest number among them.
12. Write a program to accept 10 numbers and count how many numbers are divisible by 2 & 3 among
them.
Patterns: