CIS 3260 Java Chapter 6

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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

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

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 checks to see if the value of a is 0; if it is, the code prints the message "no solution for a=0" and returns from the method.

if (-0.000001 < a && a < 0.0000001) { System.out.println("no solution for a = 0"); return; }

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

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

min = x; if (y < min) min = y; if (z < min) min = z;

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

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

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

public static int twice(int x) { return 2 * x; }

Write the definition of a method dashedLine, with one parameter, an int. If the parameter is negative or zero, the method does nothing. Otherwise it prints a complete line terminated by a newline to standard output consisting of dashes (hyphens) with the parameter's value determining the number of dashes. The method returns nothing.

public static void dashedLine(int n) { for (int i = 0; i < n; i++) System.out.print('-'); System.out.println(); }

Write the definition of a method printDottedLine, which has no parameters and doesn't return anything. The method prints to standard output a single line (terminated by a new line) consisting of five periods.

public static void printDottedLine() { System.out.println("....."); }

Write the definition of a method printGrade, which has a char parameter and returns nothing. The method prints on a line by itself the message string Grade: followed by the char parameter (printed as a character) to standard output. Don't forget to put a new line character at the end of your line.

public static void printGrade(char ch) { System.out.println("Grade: " + ch); }

Write the code for invoking a method named sendObject. There is one argument for this method which is of type Customer. Assume that there is a reference to an object of type Customer, in a variable called John_Doe. Use this reference as your argument. Assume that sendObject is defined in the same class that calls it.

sendObject(John_Doe);

Write the code for invoking a method named sendSignal. There are no arguments for this method. Assume that sendSignal is defined in the same class that calls it.

sendSignal();


संबंधित स्टडी सेट्स

Prescott's Microbiology Chapter 1

View Set

Electronics Components Bucket Day Questions

View Set

PROP 8. Statement-Level Control Structures

View Set

ITSP 136 A+ CompTIA A+ Core 1 (220-1101) and Core 2 (220-1102) Exam Cram Chapters 13-16

View Set

Class 11: Insider Trading - Part 1 Classical Theory & Misappropriation Theory

View Set

MGMT Of Human Resources Chapter 10: Building Positive Employee Relations

View Set

Water Features of the United States

View Set