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

Java Programs for User Input Calculations

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)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (2 votes)
434 views9 pages

Java Programs for User Input Calculations

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)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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: [Link]

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

Filename: [Link]

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: [Link]

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: [Link]
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: [Link]
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: [Link]
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: [Link]
Modify the [Link] 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: [Link]
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: [Link]
(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: [Link]
Write a program that finds the smallest among the five integers inputted by the users.
Filename: [Link]
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: [Link]
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: [Link]
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: [Link]
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: [Link]
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: [Link]
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: [Link]
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: [Link]
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: [Link] (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: [Link]
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: [Link]
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: [Link]
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:[Link]

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: [Link]

Write a program that would compute the following AREA, RADIUS, and VOL into a single
program called [Link] 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: [Link]
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: [Link]
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: [Link]
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: [Link]
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: [Link]
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…

Common questions

Powered by AI

Using a dialog box interface, as implemented in several programs, provides a more interactive user experience with clear prompts and immediate feedback, enhancing usability in entering data. However, it may limit user input flexibility in terms of automation and bulk data processing compared to console inputs, which handle scripts or less interactive challenges better, illustrating trade-offs between user-friendliness and functionality .

The ATM program in SET_A.JAVA maintains transaction integrity by implementing checks such as ensuring deposits are greater than zero, and withdrawal amounts are not negative or exceed the available balance. The program also caps withdrawal transactions at 4000 pesos to prevent over-withdrawing per session. These mechanisms protect user funds and ensure error-free interactions by printing specific messages when inputs are invalid .

The MP5.JAVA program calculates payroll by first reading the employee’s name, hours worked, hourly pay rate, and federal and state tax withholding rates. It then computes the gross pay by multiplying hours worked by the hourly rate. The program calculates deductions using the withholding rates, and the net pay is the gross pay minus the deductions. It offers two input/output methods: dialog boxes and console input/output for the user interaction .

The MP25.JAVA program provides options for calculating the area of a circle, the circumference of a circle, and the volume of a cylinder using options 'A', 'C', and 'V' respectively. It uses a loop to repeatedly prompt the user for inputs until the quit option 'Q' is chosen. For each geometric calculation, it requests appropriate measurements such as radius for area or radius and height for volume, computes the result, and displays it before returning to the menu .

MP7.JAVA generates two random single-digit integers with the condition that the first number must be greater than the second to avoid negative results in subtraction. This constraint ensures that the problems posed to first graders remain straightforward, focusing on basic subtraction skills suitable for their educational level .

The MP09.JAVA program checks triangle validity by ensuring the sum of any two edges is greater than the third edge. This is a fundamental criterion to ascertain whether given measurements can form a triangle. For example, the edges 1, 2, and 1 are invalid since 1 + 1 is not greater than 2, whereas 2, 2, and 1 are valid since each required sum condition meets the criteria .

The vending machine program in SET_C.JAVA handles transactions by asking the user to input an item code and a payment mode (Hot or Cold). It processes payments by accepting only 20, 50, and 100 bills, ensuring fault tolerance. The program displays the order details, calculates the total amount due, and determines the change. The system uses Switch and if statements to ensure correct processing and asks the user if another transaction is desired before exiting .

MP8.JAVA enhances student learning by tracking correct and incorrect answers in subtraction exercises. It calculates the student's grade as a percentage and provides feedback on performance. Receiving grades and suggestions on whether to advance or review material helps students understand their learning progress and areas needing improvement, facilitating personalized learning and targeted practice .

The program in MP10.JAVA prompts the user for the month and year to determine the number of days. It accounts for leap years by calculating February with 29 days if the year is divisible by 4 (and not by 100, unless also divisible by 400). Other months are calculated with standard days, i.e., April, June, September, and November with 30 days, and the rest with 31 days .

The MP13.JAVA program calculates bonuses based on hours worked, applying a tiered bonus system: over 45 hours earns a 500 MPsos bonus, over 40 but less than or equal to 45 earns 250 MPsos, and over 35 up to 40 carries a 150 MPsos bonus. The base salary is computed by multiplying hours worked by the hourly rate, and this bonus is added to determine the total weekly salary, enhancing the basic income .

You might also like