Instructor: Todd Dole
This lab assignment provides an opportunity to practice using methods with parameters and return values. You will create several methods to perform basic mathematical operations and conversions.
Construct a program that will perform basic mathematical operations, temperature conversion, and circle area calculation, all while utilizing methods with parameters and return values.
Note: You will not need to accept user input for this assignment. Simply enter values into your code yourself.
MathOperations
.int add(int a, int b)
- returns the sum of two integers.int subtract(int a, int b)
- returns the difference between two integers.int multiply(int a, int b)
- returns the product of two integers.double divide(int a, int b)
- returns the result of dividing two integers as a double
and handles division by zero.main
method, call each of the above methods, passing appropriate arguments, and display the results.double fahrenheitToCelsius(double fahrenheit)
that takes a temperature in Fahrenheit and converts it to Celsius using the formula: C = (5.0 / 9.0) * (F - 32)
.main
method, prompt the user for a temperature in Fahrenheit, call the method, and display the Celsius result.double calculateCircleArea(double radius)
that takes the radius of a circle as a parameter and returns the area of the circle using the formula: A = Math.PI * radius * radius
.int findMax(int a, int b, int c)
that takes three integers and returns the largest value.main
method and display the result.Math Operations: Addition: 5 + 3 = 8 Subtraction: 10 - 4 = 6 Multiplication: 7 * 6 = 42 Division: 9 / 3 = 3.0 Enter a temperature in Fahrenheit: 100 100.0 Fahrenheit is 37.77777777777778 Celsius. Enter the radius of the circle: 5 The area of the circle with radius 5 is 78.53981633974483 Maximum of 3 numbers: 9, 15, 7 = 15
Save your class as MathOperations.java
and submit it through Canvas. Your methods should be placed inside the class, but outside the main
method. Remember to declare all methods as static
so that they can be called from main
.