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
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to programming with java a problem solving approach
Questions and Answers of
Introduction To Programming With Java A Problem Solving Approach
Complete the following VoterDriver class skeleton by replacing all six occurrences of insert code here> with appropriate code such that the program operates properly. For details, read the comments
The statement Car car; allocates space in memory for an object. (T / F)
Assigning one reference variable to another copies the right-side object’s instance variables into the left-side object’s instance variables. (T / F)
What is a memory leak?
Consider this code fragment: boolean same; Car carX = new Car(); Car carY carX; same (carX carY);
What is the return type of an equals method?
By convention, we use the name equals for methods that perform a certain kind of evaluation. What is the difference between the evaluation performed by an equals method and the == operator?
When you pass a reference to a method, you enable the method to modify the referenced object. (T / F)
What two things must be included in a method definition so that it may be called as part of a method-call-chaining statement?
What is it called when you have two or more methods with the same name in the same class?
If you want the current object to call a different method in the same class as the current class, the method call is easy—just call the method directly, with no reference variable dot prefix. (T /
What is the return type of a constructor?
The name of a constructor must be exactly the same as the name of its class. (T / F)
Standard coding conventions suggest that you put constructor definitions after the definitions of all methods. (T / F)
If a class’s source code contains a single one-parameter constructor, the constructor is overloaded because this one-parameter constructor has the same name as the default zero-parameter
Suppose you have a class with two constructors. What are the rules for calling one constructor from the other constructor?
Normally, you should use the private access modifier for static variables. (T / F)
When should you declare a variable to be a static variable, as opposed to an instance variable?
What are the default values for static variables?
What would be wrong with adding the following statement to Figure 7.24’s main method?PennyJar.addPenny();Figure 7.24 /****** * Penny Jar Driver.java *Dean & Dean * *This class drives the Penny Jar
Member access:a) It is OK to use this in a static method. (T / F)b) It is OK to use the class name as a prefix when calling a static method. (T / F)c) Within a main method, it is OK to omit the class
It is legal to access a class member from an instance method and also from a constructor. (T / F)
It is legal to directly access an instance member from a static method. (T / F)
What keyword converts a variable into a constant?
If you want a named constant used by instance methods to have the same value, regardless of which object accesses it, the declaration should include the static modifier. (T / F)
A static constant should be initialized within a constructor. (T / F)
Suppose you have a grading program that instantiates multiple exam objects from an Exam class. Provide a declaration for a constant minimum passing score. Assume the minimum passing score for all
Given a Car class with these two instance variables: int year;String make;Describe all the operations that occur when this statement executes:Car shyanCar = new Car();
Explain garbage collection.
Trace the Car program shown in Figures 7.2 and 7.3 using the following trace setup. The abbreviations in this suggested header keep the trace’s width as small as possible.Figures 7.2Figures 7.3
Suppose you have an updateAccount method with two parameters, an int variable named yearsAccumulatingInterest and a reference variable named bankAccount. The bankAccount variable’s object contains
Suppose you enhance the Person class in Figure 7.7 by adding another instance variable, jobDescription, and another method, switchJobs. Complete the following additional switchJobs method that swaps
In JavaFX CSS, you can form a color by specifying certain amounts of red, green, and blue, with each color’s amount ranging from 0% to 100%. For example, to specify purple, you could use this
Given the following main method, replace the item with code that reads two words and checks for the first one having 5 characters and the second one starting with z. You must use method-call chaining.
Overloaded Methodsa) In this chapter’s Height class modify the two-parameter setHeight method to see if the units value is one of the following: “in”, “ft”, “mm”, “cm”, or “m.”
Provide a standard three-parameter constructor for a class named CellPhone. The class contains three instance variables— manufacturer, model, and price. The constructor simply assigns its three
Overloaded Constructorsa) Implement a Weight class with a two-parameter setWeight method that initializes weight and units variables and a one-parameter setWeight method that uses a default “kg”
Assume that a BodyWeight class contains only one setWeight method—a two-parameter version with the parameters double weight and String units. Write two constructors for the BodyWeight class, one
Assume that the following two classes are compiled and run. What is the output?You don’t have to provide a formal trace—you just have to show the output. But to determine the output, you’ll
An object’s methods cannot alter the value of one of its class’s variables that has private static modifiers. (T / F)
Given a program that keeps track of automobiles in an Page 321 automobile dealer’s inventory, for each of the following program variables, specify whether it should be a local variable, an instance
In general, why should you prefer instance variables over static variables, and why should you prefer local variables over instance variables?
If a method accesses a static variable, the method:a) Must be a local methodb) Must be an instance methodc) Must be a static methodd) Can be either a static method or an instance method—it
If you attempt to directly access an instance method from within a static method, you’ll see an error message like this:Normally, how should you fix the bug? Non-static cannot be referenced from a
Consider the following program:Mark all of the lines of code that have a compilation error. For each compilation-error line, explain why it is incorrect.For each compilation error, just provide the
Write appropriate declarations for the following named constants. In each case, decide whether to include the keyword, static, and whether to include initialization in the declaration. Also, make
Why is it safe to declare named constants public?
One should avoid inserting blank lines between different code sections (because that leads to wasted paper when the program is printed). (T / F)
In order, list the seven items that we recommend you include in a file prologue.
When adding a comment to a variable declaration, always begin the comment one space after the end of the declaration. (T / F)
To get the most on each line of code, always break a long line at the point determined by your text editor or integrated development environment (IDE). (T / F)
For an if or while that has only one statement in its body, braces for the body are optional. The compiler does not require them, but proper style suggests that you should include them. Give at least
What’s wrong with the style of a class description that ends like this?What might you do to fix it? } 3 3
What should you use to separate large “chunks” of code?
For each, write “yes” or “no” to indicate whether it is good style to include a blank space• After the single asterisks in the prologue• Between a method call and its opening
Which of the following is a legitimate reason for creating a helper method?a) You want the method to be hidden from the outside world.b) You have a long and complicated method and would like to
Does a class’s interface include the names of private methods?
In the interest of encapsulation, use local variables instead of instance variables whenever possible. (T / F)
If a method modifies a particular instance variable, and if a program calls the same method two separate times, the value of the instance variable at the beginning of the second method call is
Because some of your preliminary code might change in the course of development, do not waste time testing until everything is done. (T / F)
When you are testing a program, it’s important to not have any preconceived expectations of what your output should look like. (T / F)
The top-down design methodology is good because:a) It keeps everyone focused on a common goal. (T / F)b) It avoids “reinventing the wheel.” (T / F)c) It keeps management informed. (T /
In a top-down design process, which do you decide on first—the classes or the public methods?
When should you use bottom-up design?
If a prototype is successful, what temptation should you resist?
Once you select a particular design methodology, keep using that same methodology throughout the entire design process, and do not allow other methodologies to “contaminate” the process
You can drive any class from a main method within that class, and you can retain that main method for future testing of that class even though that class is normally driven from another class in a
A utility class’s members normally should use the private and static modifiers. (T / F)
Evaluate these assertions about styling of variable declarations and associated comments:a) Defer all variable declaration until immediately before first use. (T / F)b) Use comments to describe
Correct the style of the following program. /*Resources.java This class evaluates resource use. It was written by Dean & Dean and it compiles. So it must be OK*/ public class Resources { // instance
Trace the Shirt program in Figures 8.6, 8.7a, and 8.7b, using either the short form or the long form. To help you get started, here’s the trace setup, including the input. If you use the long form,
This exercise demonstrates using a reference parameter to pass data back to the argument supplied in the method call. Suppose you want a Car5 class to include a method with this heading: public int
Whenever a programmer is asked to enhance existing program, there is risk of introducing a bug that breaks something that was not broken in the original program.a) What should the original programmer
Modify the Square class in Figures 8.13a and 8.13b so that it uses an instance variable to hold the printed symbol for either the border square or the solid square.Figures 8.13a:Figures 8.13b: Sample
Modify the draw method in the Square class in Figure 8.13a. Instead of prompting the user for border or solid, the draw method should prompt the user for an interior character and a border character.
Figure 8.2b has two if statement conditions that contain what are called regular expressions. As indicated, these are explained in the Java API Pattern class. This exercise is intended to help you
Top-Down Design:a) Helps managers control development of large software projects. (T / F)b) Maximizes use of prewritten software. (T / F)
Write stubs for all the constructors and methods in the Student class of Figures 8.2a and 8.2b. Each stub should print the constructor or method name followed by the passed-in values of all
Top-down design uses stubs to represent not-yet-implemented methods. Bottom-up design uses local main methods to test low-level methods that will eventually be called from other classes. The public
Write a prototype of the Square program, using just one class named SquarePrototype, and using only one method, main. Your program should generate the prescribed border output for the case of when
When you design software, you should always use the top- down methodology. (T / F)
For the Square class in Figure 8.13a, rewrite the Square constructor and the getArea method so that there’s no this prefix.Figure 8.13a: /******** * Square.java Dean & Dean * *This class manages
For the Square class in Figure 8.13a, rewrite the Square constructor and the getArea method so that there’s no this prefix.Figure 8.13a: /******** * Square.java Dean & Dean * *This class manages
Implement a utility class named Distribution, which contains the following two static methods.a) The exponential method returns an exponential distribution value calculated with this formula, where
The Java API Calendar class contains a method called getTimeInMillisec, which enables you to retrieve the absolute time (in milliseconds) at which any Calendar object was created. You can use this
It’s legal to store ints and also doubles in a single standard array. (T / F)
Given an array that’s named myArray, you access the first element in the array using myArray[0]. (T / F)
Provide a declaration for an array of strings called names.
Consider the heading for any main method: public static void main(String[] args) What kind of a thing is args?
Suppose you create an array with the following statement:int[] choices = new int[4];What is the default value in a typical element of this array? Is it garbage or something in particular?
The value of an array’s length equals the value of the array’s largest acceptable index. (T / F)
GivenWrite a for loop that initializes alphabet with the characters in letters. String letters char[] alphabet = new char[26]; = "abcdefghijklmnopqrstuvwxyz";
Write a single statement that copies all the elements into the last three elements of char[] arrl = ['x', 'y', 'Z'};
In Figure 9.7’s MovingAverage program, suppose you want to shift in the other direction. How would you write the inner for loop header, and how would you write the array assignment statement in the
What kind of value does a typical histogram “bin” contain?
It’s possible to search array ids for an element equal to id with nothing more than this:What is the that indicates that i has been found? int i; for (i=0; i
We elected to use static methods to implement our sort algorithm. What is an advantage of that?
Java’s API sort method is in what class?
We have said that a two-dimensional array is an array of arrays. Consider the following declaration:double[][] myArray = new double[5][8];In the context of the expression, array of arrays, what does
In creating an array of objects, you have to instantiate the array object, and you must also instantiate each element object that’s stored in the array. (T / F)
Showing 500 - 600
of 717
1
2
3
4
5
6
7
8