EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 1PE
Program Plan Intro
Java Method calling:
- The java method is a collection of statements used to perform certain operations.
- The method should be called in order to use it. The methods can be called in two ways,
- Method returning a value
- Methods returning nothing
- The method calling process is very simple. When calling a method, the program control gets transferred to the called method.
- The above stated called method returns control to the caller in two separate conditions. That are,
- The return statement is executed.
- It reaches the closing brace of the method.
- The arguments of the method call should be same as in the definition of the method.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
What value is returned from the following method?
public static double methodA()
{
double a = 8.5 + 9.5;
return a;
}
Write 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.57
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);
}
}
Chapter 3 Solutions
EBK JAVA PROGRAMMING
Ch. 3 - Prob. 1RQCh. 3 - Prob. 2RQCh. 3 - Prob. 3RQCh. 3 - Prob. 4RQCh. 3 - Prob. 5RQCh. 3 - Prob. 6RQCh. 3 - Prob. 7RQCh. 3 - Prob. 8RQCh. 3 - Prob. 9RQCh. 3 - Prob. 10RQ
Ch. 3 - Prob. 11RQCh. 3 - Prob. 12RQCh. 3 - Prob. 13RQCh. 3 - Prob. 14RQCh. 3 - Prob. 15RQCh. 3 - Prob. 16RQCh. 3 - Prob. 17RQCh. 3 - Prob. 18RQCh. 3 - Prob. 19RQCh. 3 - Prob. 20RQCh. 3 - Prob. 1PECh. 3 - Prob. 2PECh. 3 - Prob. 3PECh. 3 - Prob. 4PECh. 3 - Prob. 5PECh. 3 - Prob. 6PECh. 3 - Prob. 7PECh. 3 - Prob. 8PECh. 3 - Prob. 9PECh. 3 - Prob. 10PECh. 3 - Prob. 11PECh. 3 - Prob. 12PECh. 3 - Prob. 13PECh. 3 - Prob. 1GZCh. 3 - Prob. 2GZCh. 3 - Prob. 1CP
Knowledge Booster
Similar questions
- 1). What will be returned from the following method? public static double methodXY() { double a = 6.5 + 8.5; if( a > 12) return a; else return 10; }arrow_forwardIf 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_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_forwardSuppose you have declared a variable as int myAge = 21;. Which of the following is a legal call to a method with the following declaration?private static void AMethod(int num) a. AMethod(myAge); b. AMethod(int myAge); c. AMethod(); d. AMethod(int 55);arrow_forwardDeclare a method with three arguments all of the type int. The method should return the greatest of the three arguments, however, if any two or all three are the same, your method should return that valuearrow_forward
- The 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_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_forwardYou are given a Conversion class and need to complete it by adding two static methods. The first method should be called gallonsToPints and take a double gallons and return the number of pints as a double (1 gallon = 8 pints). The second method should be called feetToInches, also taking a double number of feet and returning the number of inches as a double (1 foot = 12 inches). Test your program in the ConversionTester class by printing out two conversions. In javaarrow_forward
- Write a method that receives three double numbers and returns their average. You can use any valid method name and variable names.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_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
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage