Java Programming, Loose-leaf Version
8th Edition
ISBN: 9781337685917
Author: Joyce Farrell
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 3, Problem 2PE
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
Suppose 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);
Assume that you declare a variable as int x = 100; and correctly pass it to a method with the declaration private static void IncreaseValue(int x). There is a single statement within the IncreaseValue() method: x = x + 25;. Back in the Main() method, after the method call, what is the value of x?
a. 125
b. It is impossible to tell.
c. The program will not run.
d. 100
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
Chapter 3 Solutions
Java Programming, Loose-leaf Version
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
- 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_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_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
- Java Question - Which option is correct? Question - Given the following code, which is the correct statement to call an overloaded method named "subIt"? class Sample { static int subIt(int x, int y) { return x-y; } static double subIt(double x, double y) { return x-y; } static char subIt(char x, char y) { return (char) ((int) x - (int) y); } static void subIt(int x) { System.out.println(x-5); } static void subIt(int x, int y, int z) { System.out.println(x-y-z); } } Group of answer choices a - System.out.print(subIt(3.15, 8.72)); b - subIt(8, 4); c - subIt('A', 'B'); d - subIt(35); e- System.out.print(subIt(35, 12, 7));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_forwardQuestion 2 has bigger options otherwise according to your policy they are 3 questions at a time. 1.) The signature of a method consists of ____________. a. method name b. parameter list c. return type d. None of the above 2.) You should fill in the blank in the following code with ______________. public class Test { public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5); System.out.print("The grade is "); printGrade(59.5); } public static void __________ (double score) { if (score >= 90.0) { System.out.println('A'); } else if (score >= 80.0) { System.out.println('B'); } else if (score >= 70.0) { System.out.println('C'); } else if (score >= 60.0) { System.out.println('D'); } else { System.out.println('F'); } } } a. int b. printGrade c. printMe d. double e. void 3.) Assume double[][] x = new double[10][5], what are x.length and x[2].length? a. 4 and 4 b. 10 and 5 c. 5 and 10 d. 5 and 5arrow_forward
- In this program, create a method with the following signature: public static double getAverage(double d1, double d2, double d3, double d4, double d5) This method will accept five doubles and return the average. Also in program, create a method with the following signature: public static char determineGrade(double avg) This method will take an average, then return the corresponding letter grade. Write in java and use test case# as an example.arrow_forwardHow can I create a method for an object of another class? Here's my method code: public Rental higherRent(Rental obj1, Rental obj2){ if(obj1.getHoursAndMinutes() > obj2.getHoursAndMinutes()) return obj1; else if(obj1.getHoursAndMinutes() < obj2.getHoursAndMinutes()) return obj2; else return obj1;It's giving me this error:Main.java:43: error: illegal start of expressionpublic Rental higherRent(Rental obj1, Rental obj2){Attaching images below.arrow_forwardExamine the following method header; then write an example call to the method. private void ResetValue(ref int value)arrow_forward
- 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_forwardWhat value is returned from the following method? public static double methodA() { double a = 8.5 + 9.5; return a; }arrow_forwardWrite a program called AveMethod (main method) that contains a method calledthreeAve (method name) that computes the average of three numbers. NO CREDIT if amethod is not used. (7 pnts)a) The main method will do the following:• asks the user for 3 number (double type).• calls the threeAve method• print the average of the three numbersb) The threeAve method will do the following:• receives 3 numbers (parameters)• calculate the average of the three numbers• returns the averagearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author: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:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
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