Answers| Latest Update
Write a method named getName that prompts the user to enter his or her first name, and then
returns the user's input. ✔️✔️// Assume java.util.Scanner has been imported. public static String
getName() { String name; Scanner keyboard = new Scanner(System.in); System.out.print("Enter
your first name: "); name = keyboard.nextLine(); return name; }
Write a method named quartersToDollars. The method should accept an int argument that is a
number of quarters, and return the equivalent number of dollars as a double. For example, if
you pass 4 as an argument, the method should return 1.0; and if you pass 7 as an argument, the
method should return 1.75. ✔️✔️
What is the "divide and conquer" approach to problem solving? ✔️✔️A large complex problem is
broken down into smaller manageable pieces. Each smaller piece of the problem is then solved.
What is the difference between a void method and a value-returning method? ✔️✔️A void
method, which does not return a value, uses the key word void as its return type in the method
header. A value-returning method will use int, double, boolean, or any other valid data type in
its header.
What is the difference between an argument and a parameter variable? ✔️✔️An argument is a
value that is passed into a method when the method is called. A parameter variable is a variable
that is declared in the method header, and receives the value of an argument when the method
is called.
Where do you declare a parameter variable? ✔️✔️are declared inside the parentheses in the
method header. This is often referred to as a parameter list.
Explain what is meant by the phrase "pass by value." ✔️✔️When an argument is passed to a
method, only a copy of the argument is passed. The method cannot access the actual
argument.
, Why do local variables lose their values between calls to the method in which they are
declared? ✔️✔️A method's local variables exist only while the method is executing. This is known
as the lifetime of a local variable. When the method begins, its local variables and its parameter
variables are created in memory, and when the method ends, the local variables and parameter
variables are destroyed. This means that any value stored in a local variable is lost between
calls to the method in which the variable is declared
Is the following line of code a method header or a method call? calcTotal(); ✔️✔️Method call
Is the following line of code a method header or a method call? public static void calcTotal()
✔️✔️Method header
import javax.swing.JOptionPane; public class Checkpoint { public static void main(String[] args) {
String input; int number;
input = JOptionPane.showInputDialog("Enter a number."); number = Integer.parseInt(input);
if (number < 10) method1(); else method2();
System.exit(0); }
public static void method1() { JOptionPane.showMessageDialog(null, "Able was I."); }
public static void method2() { JOptionPane.showMessageDialog(null, "I saw Elba."); } } ✔️✔️
What message will the following program display if the user enters 5? ✔️✔️If the user enters 5
the program will display Able was I.
What if the user enters 10? ✔️✔️If the user enters 10 the program will display I saw Elba.
What if the user enters 100? ✔️✔️If the user enters 100 the program will display I saw Elba.