OOP Assignment-2
OOP Assignment-2
ASSIGNMENT No. 02
Course Name Object Oriented Programming
CSE202101154
Dr. Md. Ezharul Islam
Roll No :
Associate Professor
Session: 2021-22 Dept. of CSE.
Spring-2021
Jahangirnagar University
Semester:
Submitted By Submitted To
Level 1 Programming Exercises:
Output:
8. Write a program that inputs temperature in degrees Celsius and prints out the temperature in degrees
Fahrenheit. The formula to convert degrees Celsius to equivalent degrees Fahrenheit is
Fahrenheit = 1.8 * Celsius + 32
Output:
9. Write a program that accepts a person’s weight and displays the number of calories the person needs
in one day. A person needs 19 calories per pound of body weight, so the formula expressed in Java is
Calories = bodyWeight * 19;
Output:
10. Write a program that does the reverse of Exercise 9, that is, input degrees Fahrenheit and prints out
the temperature in degrees Celsius. The formula to convert degrees Fahrenheit to equivalent degrees
Celsius is
Celsius = 5/9 * (Fahrenheit – 32)
Output:
11. Write a program that inputs the year a person is born and outputs the age of the person in the
following format:
You were born in 1990 and will be (are) 18 this year.
Output:
12. A quantity known as the body mass index (BMI) is used to calculate the risk of weight-related health
problems.
Output:
13. If you invest P dollars at R percent interest rate compounded annually, in N years, your investment
will grow to dollars. Write an application that accepts P, R, and N and computes the amount of money
earned after N years.
Output:
14. The volume of a sphere is computed by the equation where V is the volume and r is the radius of the
sphere. Write a program that computes the volume of a sphere with a given radius r.
Output:
Output:
16. Your weight is actually the amount of gravitational attraction exerted on you by the Earth. Since the
Moon’s gravity is only one-sixth of the Earth’s gravity, on the Moon you would weigh only one-sixth of
what you weigh on Earth. Write a program that inputs the user’s Earth weight and outputs her or his
weight on Mercury, Venus, Jupiter, and Saturn. Use the values in this table.
Planet Multiply the Earth Weight by
Mercury- 0.4
Venus - 0.9
Jupiter- 2.5
Saturn - 1.1
Answer: Source Code:
Output:
17. When you say you are 18 years old, you are really saying that the Earth has circled the Sun 18 times.
Since other planets take fewer or more days than Earth to travel around the Sun, your age would be
different on other planets. You can compute how old you are on other planets by the formula
y= x*365/d
Output:
18. Write a program to solve quadratic equations of the form Ax2 + Bx + C + 0 where the coefficients A,
B, and C are real numbers. The two real number solutions are derived by the formula
Answer: Source Code:
Output:
22. According to Newton’s universal law of gravitation, the force F between two bodies with masses M1
and M2 is computed as where d is the distance between the two bodies and k is a positive real number
called the gravitational constant. The gravitational constant k is approximately equal to 6.67E-8 dyn
cm2/g2. Write an application that (1) accepts the mass for two bodies in grams and the distance between
the two bodies in centimeters and (2) computes the force F. Use the standard input and output, and
format the output appropriately. For your information, the force between the Earth and the Moon is
1.984E25 dyn. The mass of the earth is 5.983E27 g, the mass of the moon is 7.347E25 g, and the
distance between the two is 3.844E10 cm.
Output:
23. Dr. Caffeine’s Law of Program Readability states that the degree of program readability R (whose
unit is mocha) is determined as where k is Ms. Latte’s constant, C is the number of lines in the program
that contain comments, T is the time spent (in minutes) by the programmer developing the program, and
V is the number of lines in the program that contain nondescriptive variable names. Write an application
to compute the program readability R. Ms. Latte’s constant is 2.5E2 mocha lines2/min2.
Output:
Output:
Development Exercises:
29. MyJava Coffee Outlet runs a catalog business. It sells only one type of coffee beans, harvested
exclusively in the remote area of Irian Jaya. The company sells the coffee in 2-lb bags only, and the price
of a single 2-lb bag is $5.50. When a customer places an order, the company ships the order in boxes.
The boxes come in three sizes: the large box holds 20 bags of 2 lb, the medium 10 bags, and the small 5
bags. The cost of a large shipped in the least expensive manner. For example, the order of 52 bags will
be shipped in four boxes: two large, one medium, and one small. The rule for packing is to fill the large
and medium boxes completely; that is, the box is fully packed. Only the small boxes can have empty
spaces. For example, to ship 52 bags, you could have used 3 large boxes, but that would leave the third
box not fully packed. Develop a program that computes the total cost of an order
Answer:
Output: