Section 3.2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Write the code for invoking a static method named sendDouble, provided by the DataTransmitter class. There is one double argument for this method. Assume that a double variable called x has already been declared and initialized to some value. Use this variable's value as an argument in your method invocation.

DataTransmitter.sendDouble(x);

Write the code for invoking a static method named sendNumber , provided by the DataTransmitter class. There is one int argument for this method. Invoke this method and use the number 5 as an argument.

DataTransmitter.sendNumber(5);

Assume the availability of class named DataTransmitter that provides a static method, sendSignal that takes no arguments. Write the code for invoking this method.

DataTransmitter.sendSignal();

Write the code for invoking a static method named sendTwo, provided by the DataTransmitter class. 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.

DataTransmitter.sendTwo(15.955,133);

Assume the availability of class named DateManager that provides a static method, printTodaysDate, that accepts no arguments and returns no value. Write a statement that calls printTodaysDate.

DateManager.printTodaysDate();

Assume the availability of class named Logger that provides a static method, printErrorDescription, that accepts one int argument and returns no value. Write a statement that invokes the method printErrorDescription, passing it the value 14.

Logger.printErrorDescription(14);

Assume the availability of a class named Logger that provides a static method, printLarger 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.

Logger.printLarger(sales1, sales2);

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.

Math.max(Math.max(population1,population2),Math.max(population3,population4))

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.

Math.max(population1,population2)

If a right triangle has sides of length A, B and C and if C is the largest, then it is called the "hypotenuse" and its length is the square root of the sum of the squares of the lengths of the shorter sides (A and B). Assume that variables a and b have been declared as doubles and that a and b contain the lengths of the shorter sides of a right triangle: write an expression for the length of the hypotenuse.

Math.sqrt(Math.pow(a,2) + Math.pow(b,2))

The length of a rectangle is stored in a double variable named length, the width in one named width. Write an expression whose value is the length of the diagonal of the rectangle.

Math.sqrt(Math.pow(length,2) + Math.pow(width,2))

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.)

Math.sqrt(Math.sqrt(x))

The area of a square is stored in a double variable named area. Write an expression whose value is length of one side of the square.

Math.sqrt(area)

The area of a square is stored in a double variable named area. Write an expression whose value is length of the diagonal of the square.

Math.sqrt(area*2)

Assume the availability of class named IMath that provides a static method, 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.

cubeVolume = IMath.toThePowerOf(cubeSide, 3);

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.

cubeVolume = toThePowerOf(cubeSide, 3);

Assume the availability of a class named Arithmetic that provides a static method, add, 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 been declared. Write a statement that calls add to compute the sum of euroSales and asiaSales and that stores this value in eurasiaSales.

eurasiaSales = Arithmetic.add(euroSales, asiaSales);

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 been declared. 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.

eurasiaSales = add ( euroSales, asiaSales);

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.

max(max(population1, population2), max(population3, population4))

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.

max(population1,population2)

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 single integer 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 to oneMore 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.

oneMore(oneMore(oneMore(oneMore(x))))

Write the definition of a method add, which receives two integer parameters and returns their sum.

public static int add(int a, int b) { int c = a + b; return c; }

Write the definition of a method twice, which receives an integer parameter and returns an integer that is twice the value of the parameter.

public static int twice(int a) { int b = 2 * a; return b; }

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 twice 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 twice() function-- no other functions or operators.

twice(twice(twice(x)))


Ensembles d'études connexes

Veterinary Diseases (125) Midterm Practice Questions

View Set

Yes/No Questions (Est-ce que/ n'est-ce pas)

View Set

Mitigation and Adaptation strategies for climate change.

View Set

English IV - The Secret History (Vocabulary pg. 1 - 75)

View Set

A&P Chapter 25 Nutrition and Metabolism

View Set

Chapter 35: Skin Integrity & Wound Healing

View Set