Jouf University: Department of Information Systems Dr. Abd El-Aziz Ahmed Java Programming Fall 2018 Practice Lab 1
Jouf University: Department of Information Systems Dr. Abd El-Aziz Ahmed Java Programming Fall 2018 Practice Lab 1
Java Programming
Fall 2018
Practice Lab 1
1. Write a java program that adds two numbers from the user.
2. Write a java program that asks the user to enter two numbers, obtains the two numbers from the
user, and prints the sum, product, difference, and quotient of the two numbers .
3. Write a java program that reads in the radius of a circle and prints the circle’s diameter,
circumference and area.
4. Write a program that accept X, Y for two points P1 = (X1, Y1) and P2 = (X2, Y2) and
calculate the Slope (m) = X1-X2 / Y1-2Y.
6. Write a program to calculate Total Resistance of four resistances in circuit, three of them
connected in parallel and the last one connected in series with them. Rt = R in parallel +
R in series.
7. Write a program to calculate I total (It) of a circuit contains voltage source (Vs) and five
resistances connected in parallel. It = Vs / Rt.
8. Write a program that uses a Purchase class to set the following prices: Oranges: 10 for
2.99, Eggs: 12 for 1.69, Apples: 3 for 1.00, Watermelons: 4.39 for each Bagels: 6 for
3.50. Calculate the total bill subtotals for each item of the following: 2 dozen oranges, 3
dozen eggs, 20 apples, 2 watermelons, and 1 dozen bagels.
9. Write a program that reads a Celsius degree in a double value from the console, then
converts it to Fahrenheit and displays the result. The formula for the conversion is as
follows: fahrenheit = (9 / 5) * celsius + 32.
10. Write a program that reads an integer between 0 and 1000 and adds all the digits in the
integer. For example, if an integer is 932, the sum of all its digits is 14.
11. Write a program that prompts the user to enter the minutes (e.g., 1 billion), and displays
the number of years and days for the minutes. For simplicity, assume a year has 365 days.
12. Write a program that calculates the energy needed to heat water from an initial
temperature to a final temperature. Your program should prompt the user to enter the
amount of water in kilograms and the initial and final temperatures of the water. The
formula to compute the energy is Q = M * (finalTemperature – initialTemperature) *
4184. where M is the weight of water in kilograms, temperatures are in degrees Celsius,
and energy Q is measured in joules.
13. Given an airplane’s acceleration a and take-off speed v, you can compute the minimum
runway length needed for an airplane to take off using the following formula
length=(v2)/(2a): Write a program that prompts the user to enter v in meters/second (m/s)
and the acceleration a in meters/second squared and displays the minimum runway
length.
14. Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3, y3) of
a triangle and displays its area. The formula for computing the area of a triangle is