0% found this document useful (2 votes)
4K views9 pages

Program Exercises

The document describes 25 programming assignments involving writing Java programs to perform various calculations and tasks. The programs calculate things like momentum, kinetic energy, sums of integers, triangle properties, time conversions, payroll statements, coin denominations, subtraction practice, days in a month, minimum values, grades, salaries, bonuses, maximum/minimum values, perimeters/areas, temperatures, discounts, grades, BINGO letters, phone bills, number classifications, drawings, and circle properties/calculations. The programs require getting input from the user, performing calculations, and displaying outputs.

Uploaded by

jocansino
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
0% found this document useful (2 votes)
4K views9 pages

Program Exercises

The document describes 25 programming assignments involving writing Java programs to perform various calculations and tasks. The programs calculate things like momentum, kinetic energy, sums of integers, triangle properties, time conversions, payroll statements, coin denominations, subtraction practice, days in a month, minimum values, grades, salaries, bonuses, maximum/minimum values, perimeters/areas, temperatures, discounts, grades, BINGO letters, phone bills, number classifications, drawings, and circle properties/calculations. The programs require getting input from the user, performing calculations, and displaying outputs.

Uploaded by

jocansino
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1/ 9

Filename: MP1.

JAVA

Write a program that computes and display the momentum and kinetic energy of a moving
object with a given mass and velocity which are inputted by the user via the keyboard.

Filename: MP2.JAVA

Write a program that compute and display the sum of all integers from 1 to a given integer limit,
say N.

Filename: MP3.JAVA

Write a program that allows the user to enter the two perpendicular side lengths of a
perpendicular triangle, compute and display the hypotenuse and area of the triangle.

Filename: MP4.JAVA

Write a program that accept from the user through the keyboard the time in seconds, compute
and display the time in hours, minutes and seconds

Filename: MP5.JAVA
Write a program that reads the following information and prints a payroll statement:

• Employee's name (e.g., Smith)


• Number of hours worked in a week (e.g., 10)
• Hourly pay rate (e.g., 6.75)
• Federal tax withholding rate (e.g., 20%)
• State tax withholding rate (e.g., 9%)

Write this program in two versions: (a) Use dialog boxes to obtain input and display output; (b)
Use console input and output. A sample run of the console input and output is shown below.

The program prints a payroll statement.

Filename: MP6.JAVA
Write a program that classifies a given amount of money into smaller monetary units. The
program lets the user enter an amount value representing a total in pesos and cents, and outputs a
report listing the monetary equivalent in 5 pesos, 50 cents, 25 cents, 10 cents, and 1 cent. Write
this program in two versions: (a) Use dialog boxes to obtain input and display output; (b) Use
console input and out.
Filename: MP7.JAVA
Create a Java program for a first grader to practice subtraction. The program randomly generates
two single-digit integers number1 and number2 with number1 > number2 and displays a
question such as "What is 9-2?" to the student, as shown in Figure (a). After the student types
the answer in the input dialog box, the program displays a message dialog box to indicate
whether the answer is correct, as shown in Figure (b).

The program generates a subtraction question and grades the student's answer.

Filename: MP8.JAVA
Modify the MP7.java program for a first grader. This time the program should output how many
correct and wrong answers were made by the student. It will show the grade in terms of
percentage (assuming the number of items is 10, each questions weights 10 points) and the
program recommends the student to move to the next level or review back the teacher’s lecture
on subtraction though an appropriate message dialog boxes.

Filename: MP09.JAVA
Write a program that reads three edges for a triangle and determines whether the input is valid.
The input is valid if the sum of any two edges is greater than the third edge. For example, if your
input for three edges is 1, 2, 1, the output should be:
Can edges 1, 2, and 1 form a triangle? false

If your input for three edges is 2, 2, 1, the output should be :

Can edges 2, 2, and 1 form a triangle? true

Filename: MP10.JAVA
(Finding the number of days in a month) Write a program that prompts the user to enter the
month and year, and displays the number of days in the month. For example, if the user entered
month 2 and year 2000, the program should display that February 2000 has 29 days. If the user
entered month 3 and year 2005, the program should display that March 2005 has 31 days.

Filename: MP11.JAVA
Write a program that finds the smallest among the five integers inputted by the users.
Filename: MP12.JAVA
Write a program that computes the grade of a student using the formula:

Grade = 40% major exam + 30% ave of 2 long exams + 30% ave of 3 short quizzes

Display the average of 2 long exams, average of 3 quizzes and the grade of the student. Display
also a message whether the student passed or failed. Passing is 75%.

Filename: MP13.JAVA
Write a program that asks the user for the hours worked for the week and the hourly rate. The
basic salary is computed as:
Salary = hours worked * hourly rate
Bonuses are given:

No. of hours >45 Bonus of 500 MPsos


No. of hours >40 and <= 45 Bonus of 250 MPsos
No. of hours >35 and <=40 Bonus of 150 MPsos
Display the basic salary, bonus and the total salary (basic salary + bonus) for the week.

Filename: MP14.JAVA
XYZ company gives year-end bonus to its employees based on their number of years of service
and their salary, using the following:

Years of Service Bonus


1 10% of salary
2 to 5 20% of salary
6 to 10 50% of salary
11 and above 75% of salary

Filename: MP15.JAVA
Write a program that accepts five numbers from the user and displays the highest and lowest
number. Assume that there are no duplicate values.

Filename: MP16.JAVA
Write a program segment that will ask the user if he wants to compute the perimeter of the area
of rectangle. If the perimeter is wanted, ask the measure of the three sides and compute for the
perimeter. If the area is wanted, ask for the measures of the base and height and compute for the
area. Display the computed value.

Filename: MP17.JAVA
Write a program that will display “IT'S COLD!” if the temperature is less than 20, “IT'S HOT” if
the temperature is greater than 30, “COOL CLIMATE!” otherwise.

Filename: MP18.JAVA
Write a program that gives a discount of 100 pesos to a customer if the shirt bought is XL and
the price is greater than 500 pesos; a discount of 50 pesos if the shirt bought is L and the price is
greater than 400.
Filename: MP19.JAVA
Write a program to determine the equivalent grade of each student in class as follows:
a. Read in the student's name, midterm grade, minor B and final exam ratings.
b. Determine the final grade of the student by the formula:
final grade=0.30 of midterm grade + 0.10 of minor B + 0.60 final exam.
c. Determine the equivalent grade for the numerical value obtained by the following grading
marks:
98-100 = 1.00
95-97 =1.25
92-94 =1.5
89-91 =1.75
86-88 =2.0
83-85 =2.25
80-82 =2.50
77-79 =2.75
74-76 =3.00
71-73 =3.25
68-70 =3.5
64-67 =3.75
60-63 = 4.0
below 60=5.0

Filename: MP20.JAVA (using switch statement)


Write a program that gives the user the choice of computing of the following; the area of a circle,
a square, a rectangle, or a triangle. The program computes and refers to the following formulas:

Area of circle = pi * radius * radius


Area of square = side * side
Area of rectangle = length * width
Area of triangle = ½ * base * height

Let’s assume these options:

1=> AREA OF CIRCLE


2=> AREA OF SQUARE
3=> AREA OF RECTANGLE
4=> AREA OF TRIANGLE

Filename: MP21.JAVA
You were hired by PAGCOR as part of programming team in-charge of automating its BINGO
game. Your task is to write a program that will accept an integer whose value is 1 to 75.
Thereafter, your program should print the letter that corresponds to that number. That is, the
numbers from 1 to 15 correspond to 'B', 16 to 30 correspond to 'I', 31 to 45 correspond to 'N', 46
to 60 correspond to 'G' and 61 to 75 correspond to 'O'.
Filename: MP22.JAVA
You were hired as a programmer by TNP (Telepono ng Pilipino) a phone company. TNP
employs a metering scheme in computing the bill. The metering scheme is as follows: Calls
made on a weekday between 6:00 AM to 6:00 PM are charged at 2.50 pesos per minute.
Charges made at other times during a weekday are charged a discounted 2.00 pesos per minutes.
Calls made anytime on a weekend are charged a weekend rate of 1.50 per minute. Your job is to
write a program that will ask the user to enter the following information:

a. an integer representing the day the call was made


b. an integer representing the time (in 24 hours format ) the call started.
c. an integer representing the length of time or duration of the calls in minutes
(assume that all calls are rounded to next minute i.e. all lasting 2 minutes and 35 seconds is
billed as 3 minutes call.) (use the method ceil (x); example ceil (11.25) = 12, see to it
declare the as your header file)The rate applied depends on the day the call was made and on the
time the call was started (not when it ended). Based on the information entered, the program
should print the bill corresponding to the call.

Filename: MP23.JAVA
Write a program which quantifies numbers. Read an integer x and test it, producing the
following output:
x greater than or equal to 1000 Display the message “hugely positive”
x from 999 to 100 (including 100) Display the message “very positively”
x between 100 and 0 Display the message “positive”
x exactly 0 Display the message “zero”
x between 0 and -100 Display the message “negative”
x from -100 to -999 (including -100) Display the message “very negatively”
x less than or equal to -1000 Display the message “hugely negative”

Thus -10 would print the message “negative”. -100 “very negative” and 458 “very positive”.

Filename:MP24.JAVA

Write a program which draws an ‘X’ of user specified height. If the user typed 7, the following
series of ‘*’ characters would be drawn (without the columns and the numbers).

and if the user typed 6 would draw ‘*’ characters as follows


Filename: MP25.JAVA

Write a program that would compute the following AREA, RADIUS, and VOL into a single
program called CIRC.JAVA which accepts four options. The option ‘A’ or ‘a’ calculates the
area of a circle of a circle(prompting for the radius), the option ‘C’ or ‘c’ calculates the
circumference of a circle(prompting for the radius), the option ‘V’ or ‘v’ calculates the volume
of a cylinder (prompting for the radius and the height) while the option ‘Q’ or ‘q’ quits the
program. The program should loop until the quit option is chosen.

Filename: MP26.JAVA
Write a program that will ask the user to enter a number n and display all the numbers from 1 to
n on a single line.

Filename: MP27.JAVA
Write a program that will ask the user to enter a number n and display the sum of all numbers
from 1 to n.

Filename: MP28.JAVA
Write a program that asks the user to enter a number n and display the first n even numbers:
Example: if n=5, the first 5 even numbers are 2, 4, 6, 8, 10.

Filename: MP29.JAVA
Write a program that asks the user to enter a number n and display the first n odd numbers:
Example: if n=5, the first 5 odd numbers are 1, 3, 5, 7, 9

Filename: MP30.JAVA
Write a program containing a function that takes a 5-digit integer and returns the number with its
digit reversed. For example, if the number is 12345, the function should return 54321.
Filename:SET_A.JAVA
Write a Java program that will be used to handle Automated Teller Machine Transactions.
Such transaction includes; (1) balance inquiry, (2) deposit, (3) withdrawal and (4) exit.
Aside from these, the user should be presented a menu showing these transactions as possible
options.

Additional Requirements:

1. Initial balance is 5000.00.


2. Deposit amount should be greater than zero, if the user enters zero or negative amount,
the program should print “Deposit amount should be greater than zero”.
3. Withdrawal amount should not exceed the available balance, if the user enters amount
greater than the available balance, the program should print “Withdrawal amount exceeds
the available balance.
4. Withdrawal amount should be greater than zero, if the user enters zero or negative
amount, the program should print “Withdrawal amount should be greater than zero.”
5. Maximum withdrawal amount is 4000.00 per transaction, if the user enters more than
4000.00, the program should print “Maximum withdrawal amount is 4000.00.”
6. The program should print the current balance for every transaction.

Sample Dialogs:

*****AUTOMATED TELLER MACHINE MENU*****

(1) Balance Inquiry


(2) Deposit
(3) Withdrawal
(4) Exit

Enter your choice =>


Filename:SET_B.JAVA
Create a java program that will compute for the area of either a square, circle, and right triangle
given the following formulas:

FIGURE AREA FORMULA


Square l2
Circle πr2
Triangle ½bh
Parallelogram bh
Trapezoid ½(a+b)h
Ellipse πab
Sector 1/2r2

The system will continue asking for input/s until the user declines to. Display the computed area.
Ensure that the program is fault tolerant. Use Switch statements and goto and label functions.

SAMPLE OUTPUT

AREA CALCULATOR

FIGURE CODE
Square S
Circle C
Triangle T
Parallelogram P
Trapezoid R
Ellipse E
Sector O

Enter Code: T
Enter side a, b, and h separated by commas: 20,13,8

Your Figure is a Trapezoid.


The area of the figure you selected is 132.00.

Would you still like to calculate another area? [Y/N]: N

…press any key to halt…


Filename:SET_C.JAVA
Create a Java program for a vending machine that sells four items: Coffee (C), Milk (M), Tea
(T), and Chocolate (O). Each item may be served Hot (1) or Cold (2). Below is a table of the
price list:

HOT COLD
COFFEE Php 12.00 Php 14.00
MILK Php 10.50 Php 12.50
TEA Php 11.75 Php 13.75
CHOCOLATE Php 14.25 Php 16.25

The system will continue asking for orders until the user declines to order. Display the complete
order detail and the total amount tendered by the customer. Ensure that the program is fault
tolerant. Use Switch and if statements and goto and label functions.

SAMPLE OUTPUT

VENDING MACHINE

PRICE LIST
HOT(1) COLD(2)
COFFEE (C) Php 12.00 Php 14.00
MILK (M) Php 10.50 Php 12.50
TEA (T) Php 11.75 Php 13.75
CHOCOLATE (O) Php 14.25 Php 16.25

INSTRUCTION
Input the item code followed by a dash then mode of service (Hot or Cold).
The machine only accepts 20, 50, and 100 Bills.

SELECTION
Item Selected: M-2
Cash Amount: 100

ORDER DETAILS
Order: Cold Milk
Total Amount: Php 12.50
Cash Amount: Php 100.00
Change: Php 87.50

Would you still like to have another transaction [Y/N]: N

…press any key to halt…

You might also like