0% found this document useful (0 votes)
71 views

Problems For Algorithm Development

This document provides 23 programming problems involving conditional logic, calculations, and input/output. Some examples include programs to calculate total resistance based on circuit configuration, determine highest/lowest numbers from user input, and calculate parking fees based on hours parked. The problems cover a range of skills like data validation, mathematical operations, and conditional branching.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Problems For Algorithm Development

This document provides 23 programming problems involving conditional logic, calculations, and input/output. Some examples include programs to calculate total resistance based on circuit configuration, determine highest/lowest numbers from user input, and calculate parking fees based on hours parked. The problems cover a range of skills like data validation, mathematical operations, and conditional branching.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

1

Problems for Algorithm Development:

CONDITIONAL

11. TotalResistance
Create a java program that reads three resistors and the connection desired. Compute and output the total
resistance based on desired connection.
Type of Connection
Series Parallel
Formula to compute total resistance: Formula to compute total resistance:
totalResistance=resistor1 + resistor2 +…+ resistorN totalResistance = 1/((1/ resistor1)+(1/ resistor2)+…+(1/ resistor3))
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter resistor1:
Enter resistor2:
Enter resistor3:
Enter type of connection:
The total resistance is

12. ThreeNumbers
Create a java program that reads a three distinct numbers (X,Y,Z). Determine and output the following:
a) highest number (HN)
b) middle number (MN)
c) smallest number (SN)
d) the numbers in ascending order
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter x: 4 Enter x: 1 Enter x: 6


Enter y: 2 Enter y: 8 Enter y: 2
Enter z: 9 Enter z: 5 Enter z: 4
The Highest Number is 9 The Highest Number is 8 The Highest Number is 6
The Median Number is 4 The Median Number is 5 The Median Number is 2
The Lowest Number is 2 The Lowest Number is 1 The Lowest Number is 4
Ascending Order: 2 4 9 Ascending Order: 1 5 8 Ascending Order: 2 4 6

13. Year
A leap year is a year divisible by 4 unless it is a century year, in which case it must be divisible by 100.
Create a java program that reads a year and output a message whether the year is a leap year, century
year or ordinary year.
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter a year: 2012 Enter a year: 2018 Enter a year: 2100


It is a leap year. It is an ordinary year. It is a century year.

14. There are 15 numbers. Output the first, middle and last numbers.
2

15. Grade
A professor converts numeric grades to letter grades in the following way:
93 – 99 Excellent
87 – 92 Very Good
80 – 86 Good
70 – 79 Fair
65 - 69 Poor
Create a java program that reads a numeric grade and output the equivalent description.
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter a grade: 97 Enter a year: 79 Enter a year: 102


Excellent. Fair. Invalid Input.

16. Write a program that reads an integer, then determine if it is a prime number or not. Write a message
saying so.
17. Given two numbers, write a program that would determine the greatest common denominator of the two.

18. ParkingFee
Parking charge per hour at SMBC underground parking is as follows:
P 35.00 - minimum charge for 4 hours parking or less,
P 15.00/hr. - additional charge in excess of 4 hours parking,
P 250.00 - maximum charge.
Create a java program that reads the number of hours a vehicle was parked. Calculate and output the
parking charge.
(Note: Inputs should be integers only)
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter number of hours: 3 Enter a year: 6 Enter a year: 23


Parking Fee: P 35 Parking Fee: P 65 Parking Fee: P 250

19. TelephoneAreaCode
A telephone area code is a three-digit number. The first of which is either 1 or 9, the second is any
number among 5, 6, 7, 8, and 9. The third digit is any non zero number. Create a java program that reads
a three-digit number, determine and output a message if it is a valid or invalid code.
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter telephone area code: 357 Enter telephone area code: 163
Invalid Code Valid Code

20. Read the ID number and course of some Engineering students. Data input is terminated by an ID number
of –999. Tally and output as required:
Department: Number of Students:
EE xx
CE xx
IE xx
ME xx
ChE xx
3

ECE xx

21. ElectricBill
The ABC Electric Company bases its electricity charges on two rates. Customers are charged P30.12 per
kilowatt-hour (KWH) for the first 400 KWH used in a month, and P25.23 for all KWH used thereafter.
Create a java program that reads an electric consumption and output the amount to be charged to the
customer.
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter electric consumption: 331 Enter telephone area code: 403


Electric bill is P9969.72 Electric bill is 12123.69

22. CommodityCode
A certain store has the following scheme:
Commodity Code:
A - commodities are discounted by 15%
B - commodities are taxed by 12%
C - commodities are charged as priced
Create a program that reads a commodity code, quantity of the commodities bought and the unit price
and output the amount to be paid by the customer.
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):

Enter commodity code: E Enter commodity code: A


Invalid Code Enter quantity of commodity: 2
Enter unit price: 53.25
Amount to be paid is P90.53

Enter commodity code: B Enter commodity code: A


Enter quantity of commodity: 2 Enter quantity of commodity: 2
Enter unit price: 53.25 Enter unit price: 53.25
Amount to be paid is P119.28 Amount to be paid is P106.50

23. A 5 horsepower motor has an efficiency of 74.6%. Power rates are the following:
P 3.00 /kilowatt-hr for the 1st 50 kilowatt-hrs.
P 2.98 /kilowatt-hr for the 2nd 50 kilowatt-hrs.
P 2.96 /kilowatt-hr for the 3rd 50 kilowatt-hrs.
And so on until a minimum cost of P 1.50 per kilowatt-hour is reached. Calculate and print the cost to
run the motor continuously for 287 days.

You might also like