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
Expert Solution & Answer
Chapter 5, Problem 3FTE
Explanation of Solution
Given
//Line 1- Define a method timesTwo()
public static double timesTwo(double num)
{
//Line 2- Compute value
double result = num*2;
}
Methods:
- The methods could be used to break a complex program into small pieces.
- The “void” method simply executes a statements group and then terminates.
- A value returning method would return a value to statement that has called it.
- While calling a method, program would branch to that method.
- It would then execute statements in its body.
- The values that are sent into a method are termed as “arguments”.
- A “parameter” denotes a special variable that holds a value that is being passed into a method.
- The “passed by value” means that only copy of a value of argument is been passed into parameter variable...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
public static int cube(int num
{
return num
num
num;
}
What is the correct statement to pass value 8 to this method and assigns its return value to a variable named result?
O cube(8) = int result;
int result = cube(8)
O int result =
O int result = int cube(8);
Examine the following method header; then write an example call to the method. private void ResetValue(ref int value)
2) Two integers are said to be relatively prime if their greatest common divisor (GCD) is one. For
example 12 and 13 are relatively prime, but 12 and 14 are not.
a. Write a method called relativelyPrime that accepts two integer parameters A and B. The
method should output if A, and B are relatively prime or nat.
Use the following method header:
public static void relativelyPrime(int A, int B)
b. Write a test program (main) to test the method by asking the user to input two positive
integers X and Y. Then the program will call the method relativelyPrime to output if X and Y are
relatively prime or not.
Sample Run 1:
Enter Two positive integers X and Y: 12 13
12 and 13 are relatively prime
Sample Run 2:
Enter Two positive integers X and Y: 12 14
12 and 14 are not relatively prime
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
- You can declare a void method as follow; public void int calculateSalary() { int num1=89; int num 2= 71; int sum= num1+num2; return sum; } a) True b) Falsearrow_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_forwardVoid methods can accept arguments. O True O Falsearrow_forward
- Language:Java - Requests two double values from the user and stores them in local variables in main() - Create a method which takes these two values as parameters- The method will use Math library functions to: o Print the square root of the 1st parametero Print the log of the 2nd parametero Print the value of the 1st parameter raised to the power of the 2nd parameterarrow_forwardUsing METHOD SAMPLE Problem: Create a method that will compute the value of PI, if pi is 3.14. Given formula is : value = pi x square of radius Solution: float area(int radius) final float pi = 3.14f; float val; val = pi * (float) (radius * radius); return(val); Direction: Analyze the given problem and create a java method. Problem: Create a method that will compute the Mass (m). Acceleration(a) is 9.80. if Force (F) is equal to acceleration multiplied by mass.arrow_forwardbasic java please Write a void method named emptyBox()that accepts two parameters: the first parameter should be the height of a box to be drawn, and the second parameter will be the width. The method should then draw an empty box of the correct size. For example, the call emptyBox(8, 5) should produce the following output: ***** * * * * * * * * * * * * ***** The width of the box is 5. The middle lines have 3 spaces in the middle. The height of the box is 8. The middle columns have 6 spacesarrow_forward
- Find the error in the following method definition:Look at the following method header:public static void showValue(int x)The following code has a call to the showValue method. Find the error.int x = 8;showValue(int x); // Error!arrow_forwardPROGRAMMING LANGUAGE: Javaarrow_forwarduse java as programming languagearrow_forward
- //Todo write test cases for SimpleCalculator Class // No need to implement the actual Calculator class just write Test cases as per TDD. // you need to just write test cases no mocking // test should cover all methods from calculator and all scenarios, so a minimum of 5 test // 1 for add, 1 for subtract, 1 for multiply, 2 for divide (1 for normal division, 1 for division by 0) // make sure all these test cases fail public class CalculatorTest { //Declare variable here private Calculator calculator; //Add before each here //write test cases here }arrow_forwarda) 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 50arrow_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 3741 46 50 55 64 69 73 78 82 87 91 96arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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,