A method that takes two ints and returns their sum.
A method that takes two ints and returns their difference.
A method that takes two ints and returns their product.
A method that takes two doubles and returns their quotient.
You can assume the second argument (the divisor) is not 0.
A method that takes two ints and returns the remainder after
dividing the first by the second.
You can assume the second argument (the divisor) is not 0.
A method that takes two doubles and returns their average.
A method that takes three doubles and returns their average.
A method that takes two doubles and returns how far apart
they are on the number line.
A method that takes four doubles representing two points in
the X/Y plane (x1, y1, x2, y2) and returns how far apart they are
according to Manhattan distance (i.e. the sum of their distance on the
x-axis and their distance on the y-axis).
A method that takes four doubles representing two points in
the X/Y plane (x1, y1, x2, y2) and returns how far apart they are
according to Euclidean distance (i.e. the square root of the sum of the
squares of both the distance on the x-axis and the y-axis).
The goal of this exercise is to write methods in the editor to the left that pass the test cases for the methods shown below. Whenever you are ready to run the tests, hit the button above the editor. To see the specification for a method you are supposed to write, click a button in the test panel. Once you have written the method with the right name, the button will indicate whether the test cases are all passing (green, with a ✅) or some are failing (red, with an ❌) and clicking the button will show the results of the individual test cases.
In Java you have to declare the type of each argument and the type of value
the method returns. In this assignment the first five
methods—except divide—take int arguments and
return an int; divide and everything after it take
double arguments and return a double.
Pro tip: when you click one of the method buttons, the name of the method is copied to your clipboard so you can paste it into your code, saving typing and avoiding spelling errors.