Write the definition of a method powerto which receives


Text book: Java from control structures through objects edition 6

20658:
Write the definition of a method powerTo, which receives two parameters . The first is a double and the second is an int . The method returns adouble.

If the second parameter is negative, the method returns zero. Otherwise it returns the value of the first parameter raised to the power of the second parameter .

20574:
Write the code for invoking a method named sendNumber . There is one int argument for this method . Send the number 5 as an argument to this method.

Assume that sendNumber is defined in the same class that calls it.

20575:

Write the code for invoking a method named sendVariable. There is one int argument for this method .

Assume that an int variable called x has already been declared and initialized to some value . Use this variable 's value as an argument in yourmethod invocation.

Assume that sendVariable is defined in the same class that calls it.

20576:

Write the code for invoking a method named sendTwo. There are two arguments for this method : a double and an int . Invoke the method with the double value of 15.955 and the int value of 133.

Assume that sendTwo is defined in the same class that calls it.

20644:

printErrorDescription is a method that accepts one int argument and returns no value.

Write a statement that invokes the method printErrorDescription, passing it the value 14.

Assume that printErrorDescription is defined in the same class that calls it.

20645:

printLarger is a method that accepts two int arguments and returns no value.

Two int variables , sales1 and sales2, have already been declared and initialized .

Write a statement that calls printLarger, passing it sales1 and sales2.

Assume that printLarger is defined in the same class that calls it.

20646:

add is a method that accepts two int arguments and returns their sum.

Two int variables , euroSales and asiaSales, have already been declared and initialized . Another int variable , eurasiaSales, has already beendeclared.

Write a statement that calls add to compute the sum of euroSales and asiaSales and that stores this value in eurasiaSales.

Assume that add is defined in the same class that calls it.

20647:

toThePowerOf is a method that accepts two int arguments and returns the value of the first parameter raised to the power of the second.

An int variable cubeSide has already been declared and initialized . Another int variable , cubeVolume, has already been declared .

Write a statement that calls toThePowerOf to compute the value of cubeSide raised to the power of 3 and that stores this value in cubeVolume.

Assume that toThePowerOf is defined in the same class that calls it.

21155:

printStars is a method that accepts a single int argument and returns no value . It prints as many stars as indicated by its argument.
Given a variable x of type double that has been given a value , write a statement that invokes printStars passing x as an argument.

Assume that printStars is defined in the same class that calls it.

21017:

Given that a method receives three parameters a, b, c, of type double, write some code, to be included as part of the method, that determineswhether the value of "b squared" - 4ac is negative. If negative, the code prints out the message "no real solutions" and returns from the method

20604:

Write a method max that has two string parameters and returns the larger of the two.

20605:

Write a method min that has three string parameters and returns the smallest.

20840:

Write a method , makeSubjectLine, that gets a String argument and returns the same String but with "Subject: " in front of it. So if the argument is "Are you going to the show?" the method returns "Subject: Are you going to the show?".

20660:

Given the integer variables x, y, and z, write a fragment of code that assigns the smallest of x, y, and z to another integer variable min.
Assume that all the variables have already been declared and that x, y, and z have been assigned values .

21015:

Assume that x is a variable that has been declared as an int and been given a value . Assume that twice is a method (in the same class as the caller) that receives a single integer parameter and returns twice its value . (So if you pass 7 to twice it will return 14. Thus the expression twice(7) has the value 14.

Write an expression whose value is eight times that of x without using the standard Java arithmetic operators (*,+, etc.). Instead, use calls to twiceto accomplish this.

In this exercise you must write this as a single expression -- you must not write any statements . Also, you may only use the twice() function-- no other functions or operators .

21016:
Assume that x is a variable that has been declared as an int and been given a value . Assume that oneMore is a function that receives a singleinteger parameter and returns a value that is one greater than its argument . (So if you pass 7 to oneMore it will return 8. Thus, the expression oneMore(9) has the value 10.

Write an expression whose value is four more than x without using the standard Java arithmetic operators (*,+, etc.). Instead, use calls tooneMore to accomplish this.

In this exercise you must write this as a single expression -- you must not write any statements . Also, you may only use the oneMore function-- no other functions or operators .

20648:
max is a method that accepts two int arguments and returns the value of the larger one.

Two int variables , population1 and population2, have already been declared and initialized.

Write an expression (not a statement !) whose value is the larger of population1 and population2 by calling max.
Assume that max is defined in the same class that calls it.

20649:
max is a method that accepts two int arguments and returns the value of the larger one.

Four int variables , population1, population2, population3, and population4 have already been declared and initialized .

Write an expression (not a statement !) whose value is the largest of population1, population2, population3, and population4 by calling max.
Assume that max is defined in the same class that calls it.

21154:

The Math class provides a static method , max, that accepts two int arguments and returns the value of the larger one.

Four int variables , population1, population2, population3, and population4 have already been declared and initialized .

Write an expression (not a statement !) whose value is the largest of population1, population2, population3, and population4 by calling max.

21153:

The Math class provides a static method , max, that accepts two int arguments and returns the value of the larger one.

Two int variables ,population1 and population2, have already been declared and initialized .

Write an expression (not a statement !) whose value is the larger of population1 and population2 by calling max.

21014:

Assume that x is a variable that has been declared as a double and been given a value .

Write an expression to compute the quartic root of x. The quartic root of a number is the square root of its square root.

EXAMPLES: For example, the quartic root of 16.0 is 2.0 because: the square root of 16.0 is 4.0 and the square root of 4.0 is 2.0. Another example: the quartic root of 81.0 is 3.0 because the square root of 81.0 is 9.0 and the square root of 9.0 is 3.0. Thus, to find the quartic root of a number you take the square root of the number and then take the square root of that.

In this exercise you must find the quartic root of x in a single expression -- you must not write any statements . Also, you may only use the sqrt()static method defined in the Math class -- no other methods .

(HINT: you will need to call the Math.sqrt() method twice-- and you will need to pass the return value of one of those calls as argument to the other call. AND REMEMBER: write an expression , not a statement .)

73084:

A showChar Method

Write a method named showChar. The method should accept two arguments : a reference to a String object and an integer . The integer argument is a character position within the String , with the first character being at position 0. When the method executes, it should display the character at that character position. The method does not return anything.

Here is an example of a call to the method :

showChar("New York", 2);

In this call, the method will display the character w because it is in position 2. Demonstrate the method in a complete program .

73085:

Test Average and Grade

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program :

calcAverage:

This method should accept five test scores as arguments and return the average of the scores.

 

 

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write the definition of a method powerto which receives
Reference No:- TGS01405243

Now Priced at $110 (50% Discount)

Recommended (91%)

Rated (4.3/5)