All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Hire a Tutor
AI Study Help
New
Search
Search
Sign In
Register
study help
computer science
starting out with java from control structures
Questions and Answers of
Starting Out With Java From Control Structures
Write a class named PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that
True or False: The values in an initialization list are stored in the array in the order that they appear in the list.
True or False: The Java compiler does not display an error message when it processes a statement that uses an invalid subscript.
How many times will the selection sort swap the smallest value in an array with another value?
True or False: When an array is passed to a method, the method has access to the original array.
Describe the difference between the sequential search and the binary search.
True or False: The first size declarator in the declaration of a two-dimensional array represents the number of columns. The second size declarator represents the number of rows.
On average, with an array of 20,000 elements, how many comparisons will the sequential search perform? (Assume the items being searched for are consistently found in the array.)
True or False: A two-dimensional array has multiple length fields.
If a sequential search is performed on an array, and it is known that some items are searched for more frequently than others, how can the contents of the array be reordered to improve the average
True or False: An ArrayList automatically expands in size to accommodate the items stored in it.
What import statement must you include in your code in order to use the ArrayList class?
Write a statement that creates an ArrayList object and assigns its address to a variable named frogs.
Write a statement that creates an ArrayList object and assigns its address to a variable named lizards. The ArrayList should be able to store String objects only.
How do you add items to an ArrayList object?
How do you remove an item from an ArrayList object?
How do you retrieve a specific item from an ArrayList object?
How do you insert an item at a specific location in an ArrayList object?
How do you determine an ArrayList object’s size?
What is the difference between an ArrayList object’s size and its capacity?
Write a class that has three overloaded static methods for calculating the areas of the following geometric shapes: • Circles• Rectangles• CylindersHere are the formulas for calculating
Describe one thing you cannot do with a static method.
What is the difference between an instance field and a static field?
This type of method cannot access any non-static member variables in its own class.a. Instanceb. Voidc. Staticd. Non-static
Why are static methods useful in creating utility classes?
Add a copy constructor to the BankAccount class. This constructor should accept a BankAccount object as an argument. It should assign to the balance field the value in the argument’s balance field.
What action is possible with a static method that isn’t possible with an instance method?
When an object is passed as an argument to a method, this is actually passed.a. A copy of the objectb. The name of the objectc. A reference to the objectd. None of these; you cannot pass an object
Describe the difference in the way variables and class objects are passed as arguments to a method.
Describe the limitation of static methods.
If you write this method for a class, Java will automatically call it any time you concatenate an object of the class with a string.a. ToStringb. PlusStringc. StringConvertd. ConcatString
Even if you do not write an equals method for a class, Java provides one. Describe the behavior of the equals method that Java automatically provides.
Make a LandTract class that has two fields: one for the tract’s length and one for the width. The class should have a method that returns the tract’s area, as well as an equals method and a
Look at the following code. (You might want to review the Stock class presented earlier in this chapter.) Stock stock1 = new Stock("XYZ", 9.65);Stock stock2 = new Stock("SUNW", 7.92);While the
Making an instance of one class a field in another class is called ___________.a. Nestingb. Class fieldingc. Aggregationd. Concatenation
A “has a” relationship can exist between classes. What does this mean?
Look at the following statement, which declares an enumerated data type: Enum Flower { ROSE, DAISY, PETUNIA }a) What is the name of the data type?b) What is the ordinal value for the enum
This is the name of a reference variable that is always available to an instance method and refers to the object that is calling the method.a. Calling Objectb. Thisc. Med. Instance
What happens if you attempt to call a method using a reference variable that is set to null?
This enum method returns the position of an enum constant in the declaration.a. Positionb. Locationc. Ordinald. ToString
Is it advisable or not advisable to write a method that returns a reference to an object that is a private field? What is the exception to this?
Assume that the following enumerated data type has been declared: Enum Letters { Z, Y, X }What will the following code display? If (Letters.Z.compareTo(Letters.X) >
Assuming the following declaration exists: Enum Seasons { SPRING, WINTER, SUMMER, FALL }What is the fully qualified name of the FALL constant?a. FALLb. Enum.FALLc. FALL.Seasonsd. Seasons.FALL
What is the this key word?
For this assignment you will design a set of classes that work together to simulate a police officer issuing a parking ticket. You should design the following classes: • The ParkedCar Class:
You cannot use the fully qualified name of an enum constant for this.a. A switch expressionb. A case expressionc. An argument to a methodd. All of these
Look at the following declaration: Enum Color { RED, ORANGE, GREEN, BLUE }a. What is the name of the data type declared by this statement?b. What are the enum constants for this type?c. Write a
The Java Virtual Machine periodically performs this process, which automatically removes unreferenced objects from memory.a. Memory cleansingb. Memory deallocationc. Garbage collectiond. Object
Assuming the following enum declaration exists: Enum Dog { POODLE, BOXER, TERRIER }What will the following statements display?a. System.out.println(Dog.POODLE + "\n" + Dog.BOXER + "\n"
For this assignment, you will design a set of classes that work together to simulate a car’s fuel gauge and odometer. The classes you will design are the following: • The FuelGauge Class:
If a class has this method, it is called automatically just before an instance of the class is destroyed by the Java Virtual Machine. a. Finalizeb. Destroyc. Removed. Housekeeper
Under what circumstances does an object become a candidate for garbage collection?
CRC stands fora. Class, Return value, Compositionb. Class, Responsibilities, Collaborationsc. Class, Responsibilities, Compositiond. Compare, Return, Continue
True or False: A static member method may refer to non-static member variables of the same class, but only after an instance of the class has been defined.
True or False: All static member variables are initialized to –1 by default.
True or False: When an object is passed as an argument to a method, the method can access the argument.
True or False: A method cannot return a reference to an object.
True or False: You can declare an enumerated data type inside a method.
True or False: Enumerated data types are actually special types of classes.
True or False: enum constants have a to String method.
True or False: Each instance of a class has its own set of instance fields.
Find the error in the following method definition: // This method has an error!public static double timesTwo(double num){ double result = num * 2;}
What is the difference between an argument and a parameter variable?
A method header can contain __________.a. Method modifiersb. The method return typec. The method named. A list of parameter declarationse. All of thesef. None of these
If a class has a private field, what has access to the field?
Design a Payroll class that has fields for an employee’s name, ID number, hourly pay rate, and number of hours worked. Write the appropriate accessor and mutator methods and a constructor that
Assume that r1 and r2 are variables that reference Rectangle objects, and the following statements are executed:R1.setLength(5.0);R2.setLength(10.0);R1.setWidth(20.0);R2.setWidth(15.0);Fill in the
True or False: When you write a constructor for a class, it still has the default constructor that Java automatically provides.
How is a constructor named?
True or False: A class may not have more than one constructor.
What is a constructor’s return type?
True or False: To find the classes needed for an object-oriented application, you identify all of the verbs in a description of the problem domain.
Assume that the following is a constructor, which appears in a class: ClassAct(int number){ item = number;}a) What is the name of the class that this constructor appears in?b) Write a
Is it required that overloaded methods have different return values, different parameter lists, or both?
What is a method’s signature?
Look at the following class: public class CheckPoint{ public void message(int x) { System.out.print("This is the first version "); System.out.println("of the
How many default constructors may a class have?
What is a problem domain?
When designing an object-oriented application, who should write a description of the problem domain?
How do you identify the potential classes in a problem domain description?
What are a class’s responsibilities?
What two questions should you ask to determine a class’s responsibilities?
Will all of a class’s actions always be directly mentioned in the problem domain description?
Find the error in the following method definition: // This method has an error!public static void sayHello();{ System.out.println("Hello");}
What is the “divide and conquer” approach to problem solving?
This appears at the beginning of a method definition. a. Semicolonb. Parenthesesc. Bodyd. Header
Look at the following method header: Public static void showValue(int x)The following code has a call to the showValue method. Find the error. int x = 8;showValue(int x); // Error!
Here is the code for the display Value method, shown earlier in this chapter:public static void displayValue(int num){ System.out.println("The value is " + num);}For each of the following code
The body of a method is enclosed in __________.a. Curly braces { }b. Square brackets []c. Parentheses ()d. Quotation marks ""
If you have downloaded the book’s source code from www.pearsonhighered.com/gaddis, you will find a partially written program named AreaRectangle.java in this chapter’s source code folder. Your
The formula for converting a temperature from Fahrenheit to Celsius is Where F is the Fahrenheit temperature and C is the Celsius temperature. Write a method named Celsius that accepts a
Find the error in the following method definition:// This method has an error!public static int half(double num){ double result = num / 2.0; return result;}
Where do you declare a parameter variable?
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: •
A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $18.00 per hour for labor. Write a
A value that is passed into a method when it is called is known as a(n) __________.a. Parameterb. Argumentc. Signald. Return value
Explain what is meant by the phrase “pass by value.”
A variable that receives a value that is passed into a method is known as a(n) __________.a. Parameterb. Argumentc. Signald. Return value
A program contains the following method: Public static void display(int arg1, double arg2, char arg3){ System.out.println("The values are " + arg1 + ", " + arg2 + ", and " +
Why do local variables lose their values between calls to the method in which they are declared?
Showing 700 - 800
of 1252
1
2
3
4
5
6
7
8
9
10
11
12
13