Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 5.4, Problem 5.14CP
Program Plan Intro
Methods:
A collection of statements which are formed together to perform an operation is called as methods.
- The main advantage of using method is reusability of code and reduces the size of the program, because a method can be called for multiple numbers of times.
Method header:
The method header is the part of the method definition which holds the modifier, return type of the method, method name and the parameter list.
public static double findArea(double a, double b)
In the above example, the method “findArea()” holds the return type double and the parameters “a” and “b” and should not have a semicolon at the end.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Only variable definition/initialization can be done outside of a method. Everything else
should be inside a method.
true or false
Given the code below, write a method call for the method (assume that each parameter is a String). Then determine that method’s output given the arguments that you pass.
METHOD trickOrTreat (parameters: candy)
BEGIN
CREATE treat ← 26
SWITCH candy
CASE “Tootsie Roll”: treat ++
CASE “Candy Corn”: treat += 2
BREAK
CASE “Twizzlers”: treat -= 2
CASE “Dots”: treat --
CASE “Kit Kat”: treat *= 2
END SWITCH
RETURN treat
END METHOD
Method Call
Exact Output
a) Write a boolean method called productDivisibleByThree that returns true if the product of the digits of
its integer parameter is divisible by 3 and false otherwise. For example, if the value passed to the method
is 23 then the product of its digits is 6 (2*3). The method should retum true since 6 is divisible by 3.
b) Write a main method that calls the method productDivisibleByThree for the values between 10 and 50
inclusive 10 per line. This should output the following numbers:
10 13 16 19 20 23 26 29 30 31
Using java
32 33 34 35 36 37 38 39 40 43
46 49 50
Chapter 5 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 5.1 - Prob. 5.1CPCh. 5.1 - Prob. 5.2CPCh. 5.1 - Prob. 5.3CPCh. 5.1 - What message will the following program display if...Ch. 5.1 - Prob. 5.5CPCh. 5.2 - What is the difference between an argument and a...Ch. 5.2 - Prob. 5.7CPCh. 5.2 - Prob. 5.8CPCh. 5.2 - Prob. 5.9CPCh. 5.2 - What will the following program display? public...
Ch. 5.4 - Prob. 5.11CPCh. 5.4 - Prob. 5.12CPCh. 5.4 - Prob. 5.13CPCh. 5.4 - Prob. 5.14CPCh. 5 - Prob. 1MCCh. 5 - Prob. 2MCCh. 5 - Prob. 3MCCh. 5 - Prob. 4MCCh. 5 - A value that is passed into a method when it is...Ch. 5 - Prob. 6MCCh. 5 - Prob. 7MCCh. 5 - Prob. 8MCCh. 5 - Prob. 9MCCh. 5 - True or False: You terminate a method header with...Ch. 5 - Prob. 11TFCh. 5 - Prob. 12TFCh. 5 - Prob. 13TFCh. 5 - Prob. 14TFCh. 5 - Prob. 15TFCh. 5 - Prob. 16TFCh. 5 - Prob. 17TFCh. 5 - True or False: No two methods in the same program...Ch. 5 - True or False: It is possible for one method to...Ch. 5 - True or False: You must have a return statement in...Ch. 5 - Prob. 1FTECh. 5 - Look at the following method header: public static...Ch. 5 - Prob. 3FTECh. 5 - Prob. 4FTECh. 5 - Prob. 1AWCh. 5 - Here is the code for the displayValue method,...Ch. 5 - Prob. 3AWCh. 5 - What will the following program display? public...Ch. 5 - A program contains the following method...Ch. 5 - Prob. 6AWCh. 5 - Prob. 7AWCh. 5 - Write a method named square that accepts an...Ch. 5 - Write a method named getName that prompts the user...Ch. 5 - Write a method named quartersToDol1ars. The method...Ch. 5 - Prob. 1SACh. 5 - Prob. 2SACh. 5 - What is the difference between an argument and a...Ch. 5 - Where do you declare a parameter variable?Ch. 5 - Prob. 5SACh. 5 - Prob. 6SACh. 5 - Prob. 1PCCh. 5 - Retail Price Calculator Write a program that asks...Ch. 5 - Rectangle AreaComplete the Program If you have...Ch. 5 - Paint Job Estimator A painting company has...Ch. 5 - Prob. 5PCCh. 5 - Celsius Temperature Table The formula for...Ch. 5 - Test Average and Grade Write a program that asks...Ch. 5 - Conversion Program Write a program that asks the...Ch. 5 - Distance TraveLed Modification The distance a...Ch. 5 - Stock Profit The profit from the sale of a stock...Ch. 5 - Multiple Stock Sales Use the method that you wrote...Ch. 5 - Kinetic Energy In physics, an object that is in...Ch. 5 - isPrime Method A prime number is a number that is...Ch. 5 - Prime Number List Use the isPrime method that you...Ch. 5 - Even/Odd Counter You can use the following logic...Ch. 5 - Present Value Suppose you want to deposit a...Ch. 5 - Rock, Paper, Scissors Game Write a program that...Ch. 5 - ESP Game Write a program that tests your ESP...
Knowledge Booster
Similar questions
- QUESTION 10 A parameter variable and a method's local variable can have the same name. True Falsearrow_forwardT/F 2. Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.arrow_forwardIt has been realized that hackers have started hacking and changing the account detains of some banks, to stop this practice, you have been tasked to create a class called Abaaneke, your class should contain three variables (deposit, oldBalance, newBalace) all of type float and a variable of type String (name of the account holder) Your class should also have a method that takes three arguments – name of account holder, amount deposited and old balance. The method should add the deposit to the oldBalance and call it new balance. Using the right setters and getters, initialize the private variables and call the method to display the following in main a. Account holders name b. Amount deposited c. Old balance d. And new balancearrow_forward
- For do this program you need to use Eclipse Write a program called AveMethod (main method) that contains a method called threeAve (method name) that computes the average of three numbers. You need to use if method.arrow_forwardQuestion 1 Full explain this questionarrow_forwarda) Write a boolean method called sumDivisibleByFive that returns true if the sum of the digits of its integer parameter is divisible by 5 and false otherwise. For example, if the parameter passed to the method is 73 then the sum of its digits is 10 (7+3). The method should return true since 10 is divisible by 5. b) Write a main method that calls the method sumDivisibleByFive for the values between 10 and 100 inclusive 10 per line. This should output the following numbers: 14 19 23 28 32 37 41 46 50 55 Using java 64 69 73 78 82 87 91 96arrow_forward
- True or False: Between method calls, the value of a local variable is preserved.arrow_forwardLook through the method header below, then, as an example, write a call to the method.an internal void ValueReset (ref int value)arrow_forwarduse only C# programming Write a method call CubeIt(int x, ref int cube) that takes two arguments and does not return a value. The method will cube the first argument and assign it to the second argument.In your main, call this method twice and print the value of the parameters after each method call. Write a method with the following header: static void CalculateTuitionFee(int numberOfCourses, double costPerCourse, ref double fees). This method will calculate and assign the required fees amount to the third argument. [Fees = number of courses * cost per course + 15.25].From your program Main() method, call the CalculateTuitionFee () method four times supplying different arguments each time and display the value of the third argument after each method call. Write a method that takes four parameter of type int. The method will assign the sum of the first two arguments to the third and the difference of the first two to the fourth. This method should be coded so that the calling…arrow_forward
- Parameter variables are declared a. prior to a method call b. in a method call c. within the body of the method O d. in the method headerarrow_forwardIn this exercise you will use if and else statements to write some code that simulates a gambler who makes various wagers. As part of your solution, you will use the following parameters that are passed in to the method:A double variable with the identifier money that indicates how much money the gambler has.A double variable with the identifier wager that indicates how much money is being wagered in a particular bet.A Boolean variable with the identifier outcome that indicates if the gambler wins (true) or loses (false)1) In some cases the gambler is unable to fix the outcome of the wager ahead of time and must rely on luck.Use an if statement to check if outcome has a value (whether or not it is null)If it does not have a value, you will need to assign it one by instantiating a Random object and using one of its methods.2) Use an if/else statement to determine if the gambler has won the wager (outcome is true) If the gambler has won the wager, add the wager to amount of money the…arrow_forwardYour code should support the following: By default, the car's wheels should start with a pressure of 30. Every time the car drives the wheel pressure should drop by 5. The fillTires method should fill the wheels back to a pressure of 30. The Wheel class should not allow the pressure to go below 0. Any an attempt to set the pressure to a negative value should set the pressure to 0 instead. The toString methods should be written so they match the expected output of the provide Main class. The output produced by the Main class should be: Car (FR: Pressure = 30, FL: Pressure = 30, BR: Pressure = 30, BL: Pressure = 30) Car (FR: Pressure = 20, FL: Pressure = 20, BR: Pressure = 20, BL: Pressure = 20) Car (FR: Pressure = 30, FL: Pressure = 30, BR: Pressure = 30, BL: Pressure = 30) Car (FR: Pressure = 15, FL: Pressure = 15, BR: Pressure = 15, BL: Pressure = 15) Car (FR: Pressure = 30, FL: Pressure = 30, BR: Pressure = 30, BL: Pressure = 30) Car (FR: Pressure = 0, FL: Pressure = 0, BR:…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning