Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Java Chapter 5 Methods Test Questions and Answers| Latest Update

Rating
-
Sold
-
Pages
8
Grade
A+
Uploaded on
21-03-2025
Written in
2024/2025

Java Chapter 5 Methods Test Questions and Answers| Latest Update

Institution
JAVA
Course
JAVA

Content preview

Java Chapter 5 Methods Test Questions and
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.

Written for

Institution
JAVA
Course
JAVA

Document information

Uploaded on
March 21, 2025
Number of pages
8
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$10.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


Also available in package deal

Thumbnail
Package deal
BUNDLE-::JAVA EXAMS WITH COMPLETE SOLUTIONS| LATEST UPDATE
-
44 2025
$ 436.56 More info

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Copilot Harvard University
View profile
Follow You need to be logged in order to follow users or courses
Sold
23
Member since
1 year
Number of followers
0
Documents
4415
Last sold
3 weeks ago
A+ GRADES

ON THIS PAGE YOU WILL FIND VERIFIED STUDY MATERIALS TO BOOST YOUR CAREERS. (EXAMS, STUDY GUIDES, TEST BANKS, PRACTICE TEST QUESTIONS, TEXT BOOKS &amp; CLASS NOTES FOR ALL COURSES) LETS WORK SMART TO EXCEL, WELCOME!!!

4.9

8 reviews

5
7
4
1
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions