New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
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
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
starting out with java from control structures
Starting Out With Java From Control Structures Through Data Structures 6th Edition Tony Gaddis - Solutions
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 performance of the search?
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 the area of the shapes.Because the three methods are to be overloaded, they should each have the same
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. As a result, the new object will be a copy of the argument object.
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 toString method. Demonstrate the class in a program that asks the user to enter the dimensions for two
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 equals method is executing as a result of the following statement, what object does this reference?If
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 constant ROSE? For DAISY? For PETUNIA?c) What is the fully qualifed name of the enum constant ROSE? Of
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) > 0) System.out.println("Z is greater than X.");Else System.out.println("Z is not greater than 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: This class should simulate a parked car. The class’s responsibilities are as follows:– To know
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 statement that defines a variable of this type and initializes it with a valid value.
The Java Virtual Machine periodically performs this process, which automatically removes unreferenced objects from memory.a. Memory cleansingb. Memory deallocationc. Garbage collectiond. Object expungement
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" + Dog.TERRIER);b. System.out.println(Dog.POODLE.ordinal() + "\n” + Dog.BOXER.ordinal() +
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: This class will simulate a fuel gauge. Its responsibilities are as follows:• To know the car’s
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 accepts the employee’s name and ID number as arguments. The class should also have a method 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 boxes in Figure 6-21 that represent each object’s length and width fields.Data in Figure 6-21 rl
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 statement that creates an object from the class and passes the value 25 as an argument to the constructor.
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 method."); } public void message(String x) { System.out.print("This is the second version
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 segments, indicate whether it will successfully compile or cause an error:a. DisplayValue(100);b.
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 job is to complete the program. When it is complete, the program will ask the user to enter the width
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 Fahrenheit temperature as an argument. The method should return the temperature, converted to Celsius.
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: • CalcAverage—This method should accept five test scores as arguments and return the average of the
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 program that allows the user to enter the number of rooms to be painted and the price of the paint
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 " + arg3);}Write a statement that calls this method and passes the following variables as arguments: Char
Why do local variables lose their values between calls to the method in which they are declared?
This javadoc tag is used to document a parameter variable. a. @parameterb. @paramc. @paramvard. @arg
Showing 700 - 800
of 1251
1
2
3
4
5
6
7
8
9
10
11
12
13
Step by Step Answers