a.
Given:
Variables declared:
int a = 5;
int b = 6;
Method defined:
public static void mathMethod(int a)
Here, the method “mathMethod()” is defined with integer variable as an argument.
b.
Explanation of Solution
mathMethod(b);
“mathMethod(b)” is considered as legal because it is called with ...
c.
Explanation of Solution
mathMethod(a + b);
“mathMethod(a+b)” is considered as legal because it is called with the variable “a&...
d.
Explanation of Solution
mathMethod(a , b);
“mathMethod(a,b)” is con...
e.
Explanation of Solution
mathMethod(2361);
“mathMethod(2361)” is cons...
f.
Explanation of Solution
mathMethod(12.78);
“mathMethod(12.78)” is cons...
g.
Explanation of Solution
mathMethod(29987L);
“mathMethod(29987L)” is con...
h.
Explanation of Solution
mathMethod();
“mathMethod()” is co...
i.
Explanation of Solution
mathMethod(x);
“mathMethod(x)” is co...
j.
Explanation of Solution
mathMethod(a / b);
“mathMethod(a/b)” is considered as legal because it is called with the variable “a...
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Java Programming, Loose-leaf Version
- Where do I place a return method for finding the area of a square, triangle, and rectangle? Also are the math equations correct for each shape? //PSEUDOCODE //Write a program that demonstrates method overloading by defining and calling methods that return the area //of a triangle //a rectangle //a square private static void area(float a) { System.out.println("The area of the square is " + String.format("%,.2f", Math.pow(a,2)) + " sq units"); } private static void area1 (float a, float b) { System.out.println("The area a of the rectangle is " + String.format("%,.2f", a * b) + " sq units"); } private static void area (float a, float b) { double c = 0.5 * (a * b); System.out.println("The area of the triangle is " + String.format("%,.2f", c) + " sq units"); } public static void main(String[] args) { area(5); area1(05,21); area(05,05); } }arrow_forwardWrite a method thatcomputes future investment value at a given interest rate for a specified numberof years. Use the following method header:public static double futureInvestmentValue(double investmentAmount, double monthlyInterestRate,int years)For example, futureInvestmentValue(10000, 0.05/12, 5) returns12833.59.Write a test program that prompts the user to enter the investment amount (e.g.,1,000) and the interest rate (e.g., 9%) and prints a table that displays future valuefor the years from 1 to 30, as shown below: The amount invested: 1000Annual interest rate: 9Years Future Value1 1093.802 1196.41...29 13467.2530 14730.57arrow_forwardWrite a method with the following header to display threenumbers in decreasing order:public static void displaySortedNumbers(double num1, double num2, double num3)Write a test program that prompts the user to enter three numbers and invokes themethod to display them in decreasing order.arrow_forward
- Given the following code, please write me a method called "getPerimeter()" which will sum up the lengths of the sides of my Triangle and return that value as a double. The method does not need any arguments. All the data should already be available in the the Triangle class. class Triangle { // class assumes a right triangle double side1 = 0; double side2 = 0; public Triangle() { side1 = 0; side2 = 0; } public Triangle(int s1, int s2) { side1 = s1; side2 = s2; } public double getHypotenuse() { return Math.sqrt(side1*side1 + side2 * side2); } public double getArea() { return 0.5 * side1 * side2; } // your getPerimeter method here } class Main { public static void main(String[] args) { Triangle myTriangle = new Triangle(3,4); System.out.println("myTriangle hypotenuse is: " + myTriangle.getHypotenuse()); System.out.println("myTriangle area is: " +…arrow_forwardThe method half shown below, takes a variable of type int and returns the result of dividing the variable by 2. Write the overloaded method for half that accomplishes the same task for a variable of type double. public static int half(int val) { return val/2;}arrow_forwardFor the Java code below, you will demonstrate the ability to use and call multiple methods in your program. Using the code below, create the following methods: 1. A method that converts the temperature from Fahrenheit to Celsius. The method should be passed a parameter - Fahrenheit and should return a result - Celsius. 2. A method to output the results of your temperature conversion. The method should be passed 2 parameters - temperature in Fahrenheit and the temperature in Celsius. Finally, place an edit in your code to ensure that the user only enters a numeric value. Your output should appear as follows: Enter the Fahrenheit temperature you want to convert: 212 This converts to 100 Celsius Do you want to convert another temperature – Y or N? Y Enter the Fahrenheit temperature you want to convert: 100 This converts to 37.8 Celsius Do you want to convert another temperature – Y or N? N The program has ended import java.text.DecimalFormat;import java.util.Scanner; public class…arrow_forward
- If the value passed into the parameter x in the following method is 10. What is the value returned by the method? public static int fun3(int x) { int y = 1; for (int i =x; i > 0; x -= 2) y = y*i; return y; }arrow_forwardThis method simulates the playing of one round of “Rock Paper Scissors”. In this strange version of the game, if both players have the same hand gestures, the return value is 1. If they have different hand gestures, the return value is a 0. If at least one player, provides a string argument that is anything other than rock, paper, or scissors, the return value is -1. The method should not be case-sensitive. For example, rock, ROCK, Rock, and RocK are all valid. The output is in the image I addedarrow_forwardIf the value passed into the parameter x in the following method is 30. What is the value returned by this method? public static int method1(int x) { int y = 4*x -5; return y; }arrow_forward
- Program62.javaWrite a program that prompts for a full name (first and last) and assigns it to one string. The program then passes the full name to a void method as its sole parameter. The void method should print the first name, on one line, as many times as indicated by the length of the last name. Sample Output (image below) Program64.javaWrite a program that demonstrates method overloading by defining and calling methods that return the area of a triangle, a rectangle, or a square.arrow_forwardUsing Java, Write a method named isEven that accepts an int argument. The method should return true if the argument is even, or false otherwise. Also write a program to test your method.arrow_forwardWrite a method called DisplayHorizontalStars(int numberOfStars). This method will output the number of stars horizontally specified by its argument. Call the DisplayHorizontalStars() method three times from your program Main() method, supplying 0, 5 and 10 respectively for the number of stars. Write a method similar to the one above that displays a vertical line of stars.Call this method three times with arguments 0, 5 and 10 respectively. Write a method that accepts an argument of type double. The method will calculate and display the volume of a sphere with radius specified by its argument. [ ].Call this method from your main three times, with arguments 1, 2, and 10 respectively. The answers are 4.1888, 33.5103 and 4188.7902 respectively.Use Math.PI for the value of Write a method that takes two arguments: a cost price and a two-letter province code. It will calculate and display the selling price. (If province is Ontario a tax of 13% is added to the price, if the province is…arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage