Java Software Solutions 8th Edition Lewis Test
Bank download pdf
https://testbankfan.com/product/java-software-solutions-8th-edition-
lewis-test-bank/
Visit testbankfan.com to explore and download the complete
collection of test banks or solution manuals!
We believe these products will be a great fit for you. Click
the link to download now, or visit testbankfan.com
to discover even more!
Java Software Solutions 8th Edition Lewis Solutions Manual
https://testbankfan.com/product/java-software-solutions-8th-edition-
lewis-solutions-manual/
Java Software Solutions 9th Edition Lewis Test Bank
https://testbankfan.com/product/java-software-solutions-9th-edition-
lewis-test-bank/
Java Software Solutions 9th Edition Lewis Solutions Manual
https://testbankfan.com/product/java-software-solutions-9th-edition-
lewis-solutions-manual/
Essentials of Psychiatric Mental Health Nursing 1st
Edition Varcarolis Test Bank
https://testbankfan.com/product/essentials-of-psychiatric-mental-
health-nursing-1st-edition-varcarolis-test-bank/
Discrete Mathematics with Applications 4th Edition Susanna
Solutions Manual
https://testbankfan.com/product/discrete-mathematics-with-
applications-4th-edition-susanna-solutions-manual/
Law for Business 11th Edition Barnes Test Bank
https://testbankfan.com/product/law-for-business-11th-edition-barnes-
test-bank/
Understanding Cross Cultural Management 2nd Edition
Browaeys Solutions Manual
https://testbankfan.com/product/understanding-cross-cultural-
management-2nd-edition-browaeys-solutions-manual/
Organizational Behavior A Critical Thinking Approach 1st
Edition Neck Solutions Manual
https://testbankfan.com/product/organizational-behavior-a-critical-
thinking-approach-1st-edition-neck-solutions-manual/
Principles of Leadership International 7th Edition DuBrin
Test Bank
https://testbankfan.com/product/principles-of-leadership-
international-edition-7th-edition-dubrin-test-bank/
Sociology in Our Times 9th Edition Diana Test Bank
https://testbankfan.com/product/sociology-in-our-times-9th-edition-
diana-test-bank/
1
Copyright © 2015 Pearson Education, Inc.
Java Software Solutions, 8e (Lewis/Loftus)
Chapter 7 Object-Oriented Design
7.1 Multiple-Choice Questions
1) During program development, software requirements specify
A) how the program will accomplish the task
B) what the task is that the program must perform
C) how to divide the task into subtasks
D) how to test the program when it is done
E) all of the above
Answer: B
Explanation: B) The specification phase is to understand the problem at hand so that the
programmer can determine what needs to be done to solve the problem. The other efforts listed
above are part of the design phase (A, C) and testing phase (D).
2) Once we have implemented the solution, we are not done with the problem because
A) the solution may not be the best (most efficient)
B) the solution may have errors and need testing and fixing before we are done
C) the solution may, at a later date, need revising to handle new specifications
D) the solution may, at a later date, need revising because of new programming language
features
E) all of the above
Answer: E
Explanation: E) A program should not be considered as a finished product until we are
reasonably assured that it is efficient and error-free. Further, it is common that programs require
modification in the future because of a change to specifications or a change to the language or
computer running the program.
3) Of the various phases in software development, which of the following is usually the
lengthiest?
A) specification
B) design
C) implementation
D) testing
E) maintenance
Answer: E
Explanation: E) The maintenance phase exists for as long as the software is in use. Software
requires modification (such as new requirements such as new features or I/O specifications) and
so the maintenance phase is on-going whereas the other phases end once the software has been
released and is in use.
2
Copyright © 2015 Pearson Education, Inc.
4) A bad programming habit is to build an initial program and then spend a great deal of time
modifying the code until it is acceptable. This is known as
A) the prototyping approach
B) the waterfall model
C) iterative development
D) the recursive approach
E) the build-and-fix approach
Answer: E
Explanation: E) Programmers who do not think things through will often build a program that
does not fit the original requirements. They then spend an inordinate amount of time trying to
repair the program to more properly fit. This is known as "build-and-fix" and is a poor
programming practice.
5) The activities of the development cycle are generally thought to
A) be strictly linear
B) be rigidly ordered
C) overlap
D) have optional steps
E) both A and B are true
Answer: C
Explanation: C) A flaw of the waterfall model is that it does not permit repetition or
backtracking through the development cycle. However, phases often need revisiting resulting in
a development cycle where the development activities overlap.
6) The idea of having programmers and developers meet in order to critique a software design or
implementation is known as
A) an interview
B) a walkthrough
C) prototyping
D) aggregation
E) evolutionary development
Answer: B
Explanation: B) Such meetings are very useful so that the various members can analyze the
solution to that point in time and offer suggestions to enhance the design and implementation.
This is called a walkthrough because it involves going step-by-step through the proposed or
implemented design.
3
Copyright © 2015 Pearson Education, Inc.
7) Modifying a program in order to eliminate deficiencies is done in the ________ phase of the
development cycle.
A) design
B) implementation
C) testing
D) use
E) maintenance
Answer: E
Explanation: E) While testing is used to find errors, deficiencies are more commonly identified
by the users of the system once the system has been released. After such deficiencies have been
identified, it is up to the software maintenance group to eliminate them in future versions of the
software.
8) It is easier to correct errors found in a program if
A) they are identified early in the development cycle
B) they are identified during testing
C) they are identified during program use
D) they are identified during maintenance
E) all of the above are equally true, errors are easily corrected in any of these stages
Answer: A
Explanation: A) Errors introduced early in the development cycle often cause tremendous
problems if not caught early on. Therefore, errors found in testing, use or maintenance phases
may be too embedded in the systems' design to be easily corrected. But if found early on, the
errors can be completely eliminated.
9) In general, spending more time in development to ensure better software will
A) shorten testing time
B) slightly reduce maintenance efforts
C) slightly increase maintenance efforts
D) greatly reduce maintenance efforts
E) not alter the time it takes for any other stage whatsoever
Answer: D
Explanation: D) Spending more time in development promises better software, which in turn
leads to less maintenance effort.
4
Copyright © 2015 Pearson Education, Inc.
10) The idea that an object can exist separate from the executing program that creates it is called
A) transience
B) static
C) persistence
D) serialization
E) finality
Answer: C
Explanation: C) Objects are stored in memory and are reclaimed by the garbage collector when
they are no longer referenced. When a Java program terminates, no object is referenced and so
all objects are reclaimed. It is desirable, however, to be able to save any given object for future
use. This trait is called persistence, and the ability to do this is by saving the instance data of the
object to a file. This can be done by writing each instance data to a data file, but is simplified
using Object Serialization.
11) In order to create a constant, you would use which of the following Java reserved words?
A) private
B) static
C) int
D) final
E) class
Answer: D
Explanation: D) The reserved word final indicates that this is the final value that will be stored
in this variable, thus making it unchangeable, or constant. While constants can be of type int,
constants can be of any other type as well. It is the final reserved word that makes the value
unchangeable.
12) Which of the following methods is a static method? The class in which the method is
defined is given in parentheses following the method name.
A) equals (String)
B) toUpperCase (String)
C) sqrt (Math)
D) format (DecimalFormat)
E) paint (Applet)
Answer: C
Explanation: C) The Math class defines all of its methods to be static. Invoking Math methods
is done by using Math rather than a variable of type Math. The other methods above are not
static.
5
Copyright © 2015 Pearson Education, Inc.
13) Static methods cannot
A) reference instance data
B) reference non-static instance data
C) reference other objects
D) invoke other static methods
E) invoke non-static methods
Answer: B
Explanation: B) A static method is a method that is part of the class itself, not an instantiated
object, and therefore the static method is shared among all instantiated objects of the class. Since
the static method is shared, it cannot access non-static instance data because all non-static
instance data are specific to instantiated objects. A static method can access static instance data
because, like the method, the instance data is shared among all objects of the class. A static
method can also access parameters passed to it.
14) An object that refers to part of itself within its own methods can use which of the following
reserved words to denote this relationship?
A) inner
B) i
C) private
D) this
E) static
Answer: D
Explanation: D) The reserved word this is used so that an object can refer to itself. For instance,
if an object has an instance data x, then this.x refers to the object's value x. While this is not
necessary, it can be useful if a local variable or parameter is named the same as an instance data.
The reserved word this is also used to refer to the class as a whole, for instance, if the class is
going to implement an interface class rather than import an implementation of an interface class.
15) An example of an aggregation relationship is
A) parent and child
B) animal and dog
C) teacher and computer
D) phone and fax machine
E) all of the above
Answer: C
Explanation: C) An aggregate relationship describes how one object accomplishes a task by
using another object. In the above list, the teacher uses the computer. The relationship in A is
one of lineage (possibly ownership), in B is an is-a relationship as a dog is a child class of
animal, and in D is one of similarity, phone and fax machine might be thought of as sibling
classes, related to each other in that they are both children of a more general communication
class.
6
Copyright © 2015 Pearson Education, Inc.
16) Inheritance through an extended (derived) class supports which of the following concepts?
A) interfaces
B) modulary
C) information hiding
D) code reuse
E) correctness
Answer: D
Explanation: D) By extending a class and inheriting from it, the new class does not have to
reimplement any of those inherited methods or instance data, thus saving the programmer an
effort. So, code reuse is the ability to reuse someone else's code for your benefit by extending it
for your need.
17) Java does not support multiple inheritance, but some of the abilities of multiple inheritance
are available by
A) importing classes
B) implementing interfaces
C) overriding parent class methods
D) creating aliases
E) using public rather than protected or private modifiers
Answer: B
Explanation: B) Since a class can implement any number of interfaces, that class is in essence
using the interface classes as if those interfaces were defined in this class. So, this class is
inheriting the methods and constants of the interfaces. Further, the class could extend another
class and thus inherit directly and indirectly from multiple classes. This is not the exact same as
multiple inheritance, but it is as close as Java comes to that concept.
18) Abstract methods are used when defining
A) interface classes
B) derived classes
C) classes that have no constructor
D) arrays
E) classes that have no methods
Answer: A
Explanation: A) An interface is a class that has defined some of its components, but leaves other
components (methods) for you to implement. So, these components (methods) are referred to as
abstract and defined in the interface class as abstract.
7
Copyright © 2015 Pearson Education, Inc.
19) Which of the following is not a method of the Object class?
A) clone
B) compareTo
C) equals
D) toString
E) all of the above are methods of the Object class
Answer: B
Explanation: B) The Object class defines clone to create a copy of any object, equals to
determine if two objects are the same object, and toString to translate an Object into a String.
However, compareTo is not implement by Object and must be explicitly implemented in any
class that wants to implement the Comparable interface.
20) Which of the following interfaces would be used to implement a class that represents a group
(or collection) of objects?
A) Iterator
B) Speaker
C) Comparable
D) MouseListener
E) KeyListener
Answer: A
Explanation: A) Iterator is an abstract class allowing the user to extend a given class that
implements Iterator by using the features defined there. These features include being able to
store a group of objects and iterate (step) through them.
21) In order to implement Comparable in a class, what method(s) must be defined in that class?
A) equals
B) compares
C) both lessThan and greaterThan
D) compareTo
E) both compares and equals
Answer: D
Explanation: D) The Comparable class requires the definition of a compareTo method that will
compare two objects and determine if one is equal to the other, or if one is less than or greater
than the other and respond with a negative int, 0 or a positive int. Since compareTo responds
with 0 if the two objects are equal, there is no need to also define an equals method.
For the questions below, consider a class called ChessPiece. This class has two instance data,
String type and int player. The variable type will store "King", "Queen", "Bishop", etc and the
int player will store 0 or 1 depending on whose piece it is. We wish to implement Comparable
for the ChessPiece class. Assume that, the current ChessPiece is compared to a ChessPiece
passed as a parameter. Pieces are ordered as follows: "Pawn" is a lesser piece to a "Knight"
and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to
a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King."
8
Copyright © 2015 Pearson Education, Inc.
22) Which of the following method headers would properly define the method needed to make
this class Comparable?
A) public boolean comparable(Object cp)
B) public int comparable(Object cp)
C) public int compareTo(Object cp)
D) public int compareTo( )
E) public boolean compareTo(Object cp)
Answer: C
Explanation: C) To implement Comparable, you must implement a method called compareTo
which returns an int. Further, since this class will compare this ChessPiece to another, we would
except the other ChessPiece to be passed in as a parameter (although compareTo is defined to
accept an Object, not a ChessPiece).
23) Which of the following pieces of logic could be used in the method that implements
Comparable? Assume that the method is passed Object a, which is really a ChessPiece. Also
assume that ChessPiece has a method called returnType which returns the type of the given
piece. Only one of these answers has correct logic.
A) if (this.type < a.returnType( )) return -1;
B) if (this.type = = a.returnType( )) return 0;
C) if (this.type.equals(a.returnType( )) return 0;
D) if (a.returnType( ).equals("King")) return -1;
E) if (a.returnType( ).equals("Pawn")) return 1;
Answer: C
Explanation: C) If the type of this piece and of a are the same type, then they are considered
equal and the method should return 0 to indicate this. Note that this does not cover the case
where this piece is a "Knight" and a is a "Bishop", so additional code would be required for the
"equal to" case. The answer in B is not correct because it compares two Strings to see if they are
the same String, not the same value. The logic in D and E are incorrect because neither of these
takes into account what the current piece is, only what the parameter's type is. In D, if a is a
"King", it will be greater than this piece if this piece is not a "King", but will be equal if this
piece is a "King" and similarly in E, it does not consider if this piece is a "Pawn" or not. Finally,
A would give a syntax error because two Strings cannot be compared using the "<" operator.
24) Which of the following would not be considered an algorithm?
A) a recipe
B) a computer program
C) pseudocode
D) a shopping list
E) travel directions
Answer: D
Explanation: D) An algorithm is a step-by-step description of how to solve a problem, written at
some level of specificity. The recipe and probably the pseudocode are written at a "high level"
whereas a program and perhaps travel directions are written in more detail. A shopping list is
not a step-by-step description, so it would not qualify as an algorithm.
9
Copyright © 2015 Pearson Education, Inc.
25) It is important to dissect a problem into manageable pieces before trying to solve the problem
because
A) most problems are too complex to be solved as a single, large activity
B) most problems are solved by multiple people and it is easy to assign each piece to a separate
person
C) it is easier to integrate small pieces of a program into one program than it is to integrate one
big chunk of code into one program
D) our first solution may not solve the problem correctly
E) all of the above
Answer: A
Explanation: A) Any interesting problem will be too complex to solve easily as a single activity.
By decomposing the problem, we can build small solutions to each piece and then integrate the
pieces. Answer D is true, but does is not the reason why we will break a problem down into
pieces.
26) Having multiple class methods of the same name where each method has a different number
of or type of parameters is known as
A) encapsulation
B) information hiding
C) tokenizing
D) importing
E) method overloading
Answer: E
Explanation: E) When methods share the same name, they are said to be overloaded. The
number and type of parameters passed in the message provides the information by which the
proper method is called.
27) The goal of testing is to
A) ensure that the software has no errors
B) find syntax errors
C) find logical and run-time errors
D) evaluate how well the software meets the original requirements
E) give out-of-work programmers something to do
Answer: C
Explanation: C) Testing is required because all software will have errors. Complex systems
especially need testing before they can be released. The types of errors sought are logical errors
and run-time errors. All syntax errors will have been identified and fixed during implementation.
10
Copyright © 2015 Pearson Education, Inc.
28) Arranging components in a GUI container is accomplished by using which of the following?
A) Layout manager
B) Listener interface
C) String array
D) Event generator
E) JComboBox
Answer: A
Explanation: A) There are several classes of Layout managers. A Layout manager is used to
add GUI components to the container in some manner. The type of Layout manager determines
how items are added.
29) Which Layout Manager type would you use if you want GUI components to be placed at the
North, South, East, West and Center of the container?
A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
E) TabbedPane
Answer: B
Explanation: B) The BorderLayout specifically allows you to specify the component's location
as one of NORTH, SOUTH, EAST, WEST or CENTER where the value (e.g., NORTH) is a
constant predefined in the class.
30) Which Layout Manager type would you use if you want GUI components to be placed in 2
columns over 5 rows?
A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
E) TabbedPane
Answer: D
Explanation: D) The GridLayout manager allows you to specify the number of rows and
columns and then add elements across the column on one row until it is filled, and then on to the
next row, until all of the rows are filled.
31) Which Layout Manager is used by default if you do not specify a Layout Manager for your
GUI container?
A) FlowLayout
B) BorderLayout
C) BoxLayout
D) GridLayout
E) TabbedPane
Answer: A
Explanation: A) The FlowLayout is the default manager. It places GUI items across in one row
only. Other Layout Managers are more sophisticated and lead to better designed containers.
32) Which of the following GUI classes requires that it have a LayoutManager before any GUI
11
Copyright © 2015 Pearson Education, Inc.
components are added to it?
A) JButton
B) JSlider
C) JPanel
D) JFrame
E) both C and D but not A or B
Answer: C
Explanation: C) The JPanel requires adding a LayoutManager to it before any components are
added to it. This allows the components added to be arranged on the JPanel as desired. Neither
the JButton nor JSlider have components added to them and so do not require a LayoutManager.
The JFrame does not use a LayoutManager but instead adds elements through getContentPane( ).
33) In using the BoxLayout, adding space between components in a container can be
accomplished by
A) including TabbedPanes
B) including JButtons that have no names and thus will appear invisible
C) adding invisible components
D) inserting IconImages of blank images
E) any of the above
Answer: C
Explanation: C) The BoxLayout manager allows for the inclusion of specially designated
"invisible" components to take up space between real components and thus provide spacing.
34) In order to display three components vertically in a container, you could use all but which of
the following layout managers?
A) FlowLayout
B) BoxLayout
C) GridLayout
D) BorderLayout
E) you could use any of the above
Answer: A
Explanation: A) FlowLayout puts components horizontally and you cannot change that.
BoxLayout can place items horizontally or vertically. GridLayout allows you to specify the
number of rows and columns and to place the three components vertically, you would use (3, 1)
that is, 3 rows, 1 column. BorderLayout can place three components vertically by placing them
in the NORTH, CENTER and SOUTH positions.
12
Copyright © 2015 Pearson Education, Inc.
35) What is wrong with the following message to create a BoxLayout for the JPanel jp?
jp.setLayout(new BoxLayout(BoxLayout.X_AXIS));
A) X_AXIS is not a valid constant for BoxLayout, it should instead be HORIZONTAL
B) Aside from X_AXIS, the constructor also requires a Dimension to determine the size of the
Box
C) Aside from X_AXIS, the constructor also needs a command regarding horizontal glue as in
createHorizontalGlue( )
D) The BoxLayout constructor is lacking a reference to the container that the BoxLayout
manager will govern
E) There is nothing wrong with it at all
Answer: D
Explanation: D) The BoxLayout manager constructor requires two parameters, a reference to the
container that the manager will govern, and an axis for the layout, (vertical or horizontal) as
specified by either X_AXIS or Y_AXIS.
36) In which phase of program development would you expect the programmer(s) to create the
pseudocode?
A) Software requirements
B) Software design
C) Software implementation
D) Software testing
E) Could occur in any of the above
Answer: B
Explanation: B) Pseudocode is a description of an algorithm written in an English-like way
rather than in a specific programming language. This is part of the program's design. In the
implementation phase, the programmer(s) translates the pseudocode into the programming
language being used.
37) Which of the following is considered a top-level container?
A) Panel
B) Frame
C) Box
D) Layout Manager
E) A, B, and C
Answer: B
Explanation: B) While the answers in A, B and C are all types of containers, the Box and Panel
are made available to contain other components and are themselves placed into other containers.
The Frame is a top-level container because a Frame will not store other Frames, but instead, the
Frame contains Panels which can contain Boxes, Panels and other components.
13
Copyright © 2015 Pearson Education, Inc.
38) The JFrame below has a JBorder created using which of the following BorderFactory
formats?
A) TitledBorder
B) MatteBorder
C) EtchedBorder
D) RaisedBevelBorder
E) LoweredBevelBorder
Answer: D
Explanation: D) The JFrame has a Bevel border which is raised. A TitledBorder has a title
running along the top of it. The MatteBorder is of a Color or contains an image of some kind.
The EtchedBorder is not raised, and the LoweredBevelBorder is lowered, not raised.
39) To take 2 borders and use one as an outer border and the other as an inner border, you would
create a
A) compound border
B) nested border
C) split border
D) border factory
E) matte border
Answer: A
Explanation: A) The compound border comprises two borders that are combined together, one
border being the outside border and the other being the inside border.
40) In which phase of program development would you expect the programmer(s) to determine
the classes and objects needed?
A) software requirements
B) software design
C) software implementation
D) software testing
E) could occur in any of the above
Answer: B
Explanation: B) Determining which classes and objects to use or create is part of the design.
14
Copyright © 2015 Pearson Education, Inc.
41) If a programmer follows the four phases of program development as intended, which of the
four phases should require the least amount of creativity?
A) software requirements
B) software design
C) software implementation
D) software testing
E) none of the above, all four levels would require equal creativity
Answer: C
Explanation: C) Once the implementation phase has been reached, the algorithm should have
already been specified, so the only effort involved in the implementation phase is of translating
from the design (which is probably in an English-like pseudocode) to the programming language,
and entering the code through an editor. The requirements and design phases require
understanding the problem and coming up with a solution respectively, requiring creativity, and
the testing phase will require diagnostic abilities usually forcing the programmer(s) to be creative
in how the errors are found and fixed.
7.2 True/False Questions
1) The most important decisions regarding the development of a system are made during the
implementation phase while code is actively being written.
Answer: FALSE
Explanation: All of the important decisions should be made during earlier phases of
development, particularly during the design phase. By the time the implementation phase is
reached, the entire system design should be available and this phase should only entail
translating the design into code.
2) Unlike the String class where you must pass a message to an object (instance) of the class, as
in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in
Math.abs( ) or Math.sqrt( ).
Answer: TRUE
Explanation: The Math class uses methods known as static methods (or class methods) which
are invoked by passing a message directly to the class name itself rather than to an object of the
class.
3) Assume that the class Bird has a static method fly( ). If b is a Bird, then to invoke fly, you
could do Bird.fly( );.
Answer: TRUE
Explanation: Static methods are invoked through the class and not an object of the class. This is
because the static method is shared among all instances. So, Bird.fly( ); will invoke fly. It
should be noted that fly can also be invoked through b, so b.fly( ); will also work.
4) Interface classes cannot be extended but classes that implement interfaces can be extended.
Answer: FALSE
Explanation: Any class can be extended whether it is an interface, implements an interface, or
neither. The only exception to this is if the class is explicitly modified with the word "final" in
which case it cannot be extended.
15
Copyright © 2015 Pearson Education, Inc.
5) If classes C1 and C2 both implement an interface Cint, which has a method whichIsIt, and if
C1 c = new C1( ); is performed at one point of the program, then a later instruction c.whichIsIt(
); will invoke the whichIsIt method defined in C1.
Answer: FALSE
Explanation: Because C1 and C2 implement the same interface, they both implement whichIsIt.
The variable c is known as a polymorphic variable, meaning that it can change from being an C1
to a C2. So, the message c.whichIsIt( ); may invoke C1's whichIsIt or C2's whichIsIt. There is
no way to tell until run-time.
6) Any class can implement an interface, but no classes can implement more than a single
interface.
Answer: FALSE
Explanation: Classes can implement any number of interfaces, 0, 1, or more.
7) All objects implement Comparable.
Answer: FALSE
Explanation: Comparable is an interface, and the class must define the compareTo method and
explicitly state that it implements Comparable to be considered an implementation of
Comparable. Most classes do not implement Comparable.
8) Formal parameters are those that appear in the method call and actual parameters are those
that appear in the method header.
Answer: FALSE
Explanation: The question has the two definitions reversed. Formal parameters are those that
appear in the method header, actual parameters are the parameters in the method call (those
being passed to the method).
9) Defining formal parameters requires including each parameters type.
Answer: TRUE
Explanation: In order for the compiler to check to see if a method call is correct, the compiler
needs to know the types for the parameters being passed. Therefore, all formal parameters (those
defined in the method header) must include their type. This is one element that makes Java a
Strongly Typed language.
10) It is not possible to test out any single method or class of a system until the entire system has
been developed, and so all testing is postponed until after the implementation phase.
Answer: FALSE
Explanation: While it is true that testing occurs after implementation, some testing can take
place during implementation. In Java, it is possible to test out single methods or classes by
creating stubs of other methods and classes that are simple placeholders. For instance, if one
method calls another method and the second method is not yet written, a stub of the second
method can be written that simply returns a value that would normally be expected so that the
first method can be tested.
16
Copyright © 2015 Pearson Education, Inc.
11) All parts of a container in BorderLayout must be used.
Answer: FALSE
Explanation: BorderLayout allows components to be inserted in any of North, South, East, West
and Center of the GUI, but as many or as few of these five sections can be used as needed.
12) A JPanel can itself contain JPanels.
Answer: TRUE
Explanation: It is common to place GUI components into a JPanel and then place several
JPanels into another JPanel. Each JPanel has its own layout manager allowing the programmer
to specify in detail how components should appear. For instance, one JPanel might use a
GridLayout and another a BoxLayout and then the two JPanels be placed in the NORTH and
EAST sections of a JPanel using BorderLayout.
13) If a GUI container is resized by the user, all components of the GUI are automatically
increased or decreased by the same fraction to fit in the newly sized container.
Answer: FALSE
Explanation: The layout manager will reposition the GUI items to fit in the newly sized
container.
14) The size and shape of a GUI container is based on the layout manager selected and the type
and number of items added to the container.
Answer: TRUE
Explanation: It is the layout manager's task to arrange the components in the container. Based
on the order that the items are entered and the type of layout manager, the size and shape are
determined.
15) A border can be put around any Swing component with the exception of a JButton and
JScrollPane component.
Answer: FALSE
Explanation: A border can be up around any Swing component no matter the type.
16) The term "test case" is used to express a set of inputs (or user actions) and the expected
outputs to be used in testing out software.
Answer: TRUE
Explanation: In order to test software to see if it is working correctly, a tester will often start
with a series of inputs and the expected outputs. If, when running the program on the inputs, the
outputs are not the expected results, then errors are assumed to exist. These input/output pairs
are known as test cases.
17
Copyright © 2015 Pearson Education, Inc.
17) In black-box testing, the tester should already know something about how the program is
implemented so that he/she can more carefully identify what portion(s) of the software are
leading to errors.
Answer: FALSE
Explanation: In black-box testing, the tester should know nothing about how the software is
implemented. In essence, the software is a black-box which has an input and an output and the
mechanisms of the program are opaque. If the tester does know something about how the
program works, then the tester's test cases might be biased. If the tester knows how the program
works, then testing is known as glass-box testing.
7.3 Free-Form Questions
1) Provide a reason why an instance data would be declared static.
Answer: If an instance data is to be shared among all objects of the class, the instance data
would be static. As an example, an instance data that counts the number of times something has
happened across all objects of the class would be made static. If we are writing a chess game
and have a ChessPiece class that includes a method called movePiece, we would want to know
how many moves a player has made, but not necessarily how many times a single piece has been
moved. So, all of the ChessPieces share a numberOfTimesMoved instance data that is
incremented by any ChessPiece whenever it is moved.
2) Provide a reason why a method would be declared static.
Answer: A method is declared static if it might be used, not by the current object, but by any
objects of the class. That is, the method does not require access to any single object's instance
data. Consider a class called Point that consists of an x and y coordinate. To determine the
distance between two Points, we could make a static computeDistance method. It is passed two
Points as parameters and computes the distance. Another example is the Keyboard class from
the textbook, which does not itself have any instance data.
3) Write a static method that is passed two ChessPieces and determines if the two pieces are
owned by the same player. It should return true or false.
Answer: public static boolean samePlayer(ChessPiece p1, ChessPiece p2)
{
return (p1.returnPlayer( ) = = p2.returnPlayer( ));
}
4) Explain the difference between implementing an interface and a derived class.
Answer: Implementing an interface means that you are adding to your class any mechanisms
defined in an abstract class. Your class essentially is expanded to contain those items defined in
the interface class but you have to implement any of those items that are abstract. The appeal is
that other objects might call upon your class to use the interface methods without knowing
anything else about your class. The derived class is similar in that you are gaining items
previously defined, although in this case, those items are defined in the parent class (as long as
those items are protected or public) and you do not have to implement any of them unless you
want to redefine them. One difference between the two is that the interface cannot be
instantiated directly. Another difference is that your class "inherits" abstract methods from the
interface class as opposed to implemented methods from a super class.
18
Copyright © 2015 Pearson Education, Inc.
5) Define an interface class that contains two int constants, X = 5 and Y = 10 and one int method
called useXY which receives no parameters. Call your interface class XYClass
Answer: public interface XYClass
{
public final int X = 5;
public final int Y = 10;
public int useXY( );
}
6) Assume a class Foo implements Comparable. Without knowing anything else about the Foo
class, write an equal method that returns true if the Foo parameter passed to this Foo is equal to
this Foo as determined by using the implementation of Comparable.
Answer: public boolean equals(Foo a)
{
if(compareTo(a)) = = 0)
return true;
else
return false;
}
19
Copyright © 2015 Pearson Education, Inc.
7) To implement Comparable for the ChessPiece class, the current ChessPiece's type is
compared to a ChessPiece passed as a parameter. The method should return 0 if the types are
equal, -1 if this piece's type is a lesser piece than the parameter's type, and 1 if this piece's type is
a greater piece than the parameter's type. Pieces are ordered as follows: "Pawn" is a lesser piece
to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are
lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King."
Write the proper method to implement Comparable for this class.
Answer: public int compareTo(ChessPiece a)
{
if (this.type.equals(a.returnType( )) | |
(this.type.equals("Knight") && a.returnType( ).equals("Bishop")) | |
(this.type.equals("Bishop") && a.returnType( ).equals("Knight")))
return 0;
else if (this.type.equals("King"))
return 1;
else if (a.returnType( ).equals("King"))
return-1;
else if (this.type.equals("Queen"))
return 1;
else if (a.returnType( ).equals("Queen"))
return -1;
else if (this.type.equals("Rook"))
return 1;
else if (a.returnType( ).equals("Rook"))
return -1;
else if (this.type.equals("Knight") | | (this.type.equals("Bishop"))
return 1;
else if (a.returnType( ).equals("Knight") | | (a.returnType( ).equals("Bishop"))
return -1;
}
8) Why was the Y2K problem a problem of software maintenance and not a problem of software
testing?
Answer: The Y2K problem was caused by older software that stored the year as a 2-digit value
instead of a 4-digit value (older software attempted to save memory space in any way possible,
this was a common way to save 2 bytes). Since the 2-digit year was not a logical or run-time
error, but instead, a flaw in the design, this problem was not detected during software testing.
Instead, it was not until the late 1990s, when people began to realize that a 2-digit year would
cause a problem starting in 2000, that the Y2K problem was identified and solutions sought, so
the problem was one of software maintenance how to maintain this older software so that it still
functions starting in the year 2000.
20
Copyright © 2015 Pearson Education, Inc.
9) In what way is black-box testing better than glass-box testing? In what way is glass-box
testing better than black-box testing?
Answer: Black-box testing is superior because the tester knows nothing of the software and so
will test the software without preconceived ideas of where errors might exist. The tester is
testing the software blindly, much as a user will use the software–without intimate knowledge of
how the software works. The result should be that if errors exist that a user might stumble
across, the tester should find them. While black-box testing of software has the advantage that
the tester operates much like the users are expected to, the disadvantage is that it is a blind test
and knowledge of how the software functions could be useful. If programmers suspect that some
awkward or difficult implementation may be buggy, then spending more time testing that portion
of the software is advantageous. This form of testing requires knowledge of how the software
works. So, both black-box and glass-box testing have their own advantages and disadvantages.
10) Write a set of code that will allow a user to select an input image and then place this image in
a JLabel lab1 and add lab1 to a JPanel as the northern component in a JFrame using
BorderLayout. The JFrame has already been instantiated as jf and the BorderLayout already
established. Hint: a JFileChooser returns a File and JLabel requires the String name of a file as
an argument. A File can return its name using File class' method getAbsolutePath( )
Answer: JFileChooser jfc = new JFileChooser( );
jfc.showOpenDialog(null);
File f = jfc.getSelectedFile( );
ImageIcon im = new ImageIcon(f. getAbsoluteFile( ));
JLabel lab1 = new JLabel(im);
jp.add(lab1, BorderLayout.NORTH);
jf.getContentPane( ).add(jp);
jf.pack( );
jf.setVisible(true);
21
Copyright © 2015 Pearson Education, Inc.
11) Write code to create a JPanel with 4 JCheckBox GUI components and two JLabels for
output, one that says "Current cost is" and the other that outputs the computed cost based on
which of the food items has been selected.
Answer: FoodListener fl = new FoodListener( );
JPanel jp = new JPanel(new GridLayout(3, 2));
jcb1 = new JCheckBox("Burger");
jcb2 = new JCheckBox("Fries");
jcb3 = new JCheckBox("Soda");
jcb4 = new JCheckBox("Cookie");
jcb1.addItemListener(fl);
jcb2.addItemListener(fl);
jcb3.addItemListener(fl);
jcb4.addItemListener(fl);
jl1 = new JLabel("Current cost is");
jl2 = new JLabel(" ");
jp.add(jcb1);
jp.add(jcb2);
jp.add(jcb3);
jp.add(jcb4);
jp.add(jl1)
jpadd(jl2);
add(jp);
22
Copyright © 2015 Pearson Education, Inc.
12) Provide code to generate the following JFrame. Each lettered item is a JButton. Hint:
Create several JPanels, each one having two or more JButtons and taken up a portion of the
JFrame.
Answer: JFrame jf = new JFrame( );
JPanel jp1 = new JPanel(new BorderLayout( ));
JPanel jp2 = new JPanel(new FlowLayout( ));
JPanel jp3 = new JPanel(new GridLayout(2, 3));
JButton lab1 = new JButton("A");
JButton lab2 = new JButton("B");
JButton lab3 = new JButton("C");
JButton lab4 = new JButton("D");
JButton lab5 = new JButton("E");
JButton lab6 = new JButton("F");
JButton lab7 = new JButton("G");
JButton lab8 = new JButton("H");
JButton lab9 = new JButton("I");
JButton lab10 = new JButton("J");
JButton lab11 = new JButton("K");
JButton lab12 = new JButton("L");
JButton lab13 = new JButton("M");
jp1.add(lab1, BorderLayout.NORTH);
jp1.add(lab2, BorderLayout.WEST);
jp1.add(lab3, BorderLayout.CENTER);
jp1.add(lab4, BorderLayout.EAST);
jp1.add(lab5, BorderLayout.SOUTH);
jp2.add(lab6);
jp2.add(lab7);
jp3.add(lab8);
jp3.add(lab9);
jp3.add(lab10);
jp3.add(lab11);
23
Copyright © 2015 Pearson Education, Inc.
jp3.add(lab12);
jp3.add(lab13);
JPanel jp4 = new JPanel(new GridLayout(3, 1));
jp4.add(jp1);
jp4.add(jp2);
jp4.add(jp3);
jf.getContentPane( ).add(jp4);
jf.pack( );
jf.setVisible(true);
24
Copyright © 2015 Pearson Education, Inc.
13) Provide code to generate the following JFrame. Each lettered item is a JButton. Hint:
Create several JPanels, each one having two or more JButtons and taken up a portion of the
JFrame.
Answer: JFrame jf = new JFrame( );
JPanel jp1 = new JPanel(new GridLayout(1, 3));
JPanel jp2 = new JPanel(new GridLayout(3, 1));
JPanel jp3 = new JPanel(new GridLayout(3, 1));
JPanel jp4 = new JPanel(new GridLayout(1, 3));
JPanel jp5 = new JPanel(new BorderLayout( ));
JButton lab1 = new JButton("A");
JButton lab2 = new JButton("B");
JButton lab3 = new JButton("C");
JButton lab4 = new JButton("D");
JButton lab5 = new JButton("E");
JButton lab6 = new JButton("F");
JButton lab7 = new JButton("G");
JButton lab8 = new JButton("H");
JButton lab9 = new JButton("I");
JButton lab10 = new JButton("J");
JButton lab11 = new JButton("K");
JButton lab12 = new JButton("L");
JButton lab13 = new JButton("M");
jp1.add(lab1);
jp1.add(lab2);
jp1.add(lab3);
jp2.add(lab4);
jp2.add(lab5);
jp2.add(lab6);
jp3.add(lab7);
jp3.add(lab8);
jp3.add(lab9);
jp4.add(lab11);
jp4.add(lab12);
jp4.add(lab13);
jp5.add(jp1, BorderLayout.NORTH);
jp5.add(jp2, BorderLayout.WEST);
jp5.add(lab10, BorderLayout.CENTER);
25
Copyright © 2015 Pearson Education, Inc.
jp5.add(jp3, BorderLayout.EAST);
jp5.add(jp4, BorderLayout.SOUTH);
jf.getContentPane( ).add(jp5);
jf.pack( );
jf.setVisible(true);
14) Provide code to generate the following JFrame. Each lettered item is a JButton. Hint:
Create several JPanels, each one having two or more JButtons and taken up a portion of the
JFrame.
Answer: JFrame jf = new JFrame( );
JPanel jp1 = new JPanel(new GridLayout(2, 2));
JPanel jp2 = new JPanel(new GridLayout(2, 2));
JPanel jp3 = new JPanel(new FlowLayout( ));
JPanel jp4 = new JPanel(new BorderLayout( ));
JPanel jp5 = new JPanel(new GridLayout(2, 2));
JButton lab1 = new JButton("A");
JButton lab2 = new JButton("B");
JButton lab3 = new JButton("C");
JButton lab4 = new JButton("D");
JButton lab5 = new JButton("E");
JButton lab6 = new JButton("F");
JButton lab7 = new JButton("G");
JButton lab8 = new JButton("H");
JButton lab9 = new JButton("I");
JButton lab10 = new JButton("J");
JButton lab11 = new JButton("K");
JButton lab12 = new JButton("L");
JButton lab13 = new JButton("M");
JButton lab14 = new JButton("N");
JButton lab15 = new JButton("O");
JButton lab16 = new JButton("P");
jp1.add(lab1);
jp1.add(lab2);
jp1.add(lab3);
26
Copyright © 2015 Pearson Education, Inc.
jp1.add(lab4);
jp2.add(lab5);
jp2.add(lab6);
jp2.add(lab7);
jp2.add(lab8);
jp3.add(lab9);
jp3.add(lab10);
jp3.add(lab11);
jp4.add(lab12, BorderLayout.WEST);
jp4.add(lab13, BorderLayout.NORTH);
jp4.add(lab14, BorderLayout.CENTER);
jp4.add(lab15, BorderLayout.EAST);
jp4.add(lab16, BorderLayout.SOUTH);
jp5.add(jp1);
jp5.add(jp2);
jp5.add(jp3);
jp5.add(jp4);
jf.getContentPane( ).add(jp5);
jf.pack( );
jf.setVisible(true);
27
Copyright © 2015 Pearson Education, Inc.
15) Draw the JFrame as you think it would appear given the following set of code:
JButton jb1 = new JButton("A");
JButton jb2 = new JButton("B");
JButton jb3 = new JButton("C");
JButton jb4 = new JButton("D");
JButton jb5 = new JButton("E");
JButton jb6 = new JButton("F");
JButton jb7 = new JButton("G");
JButton jb8 = new JButton("H");
JButton jb9 = new JButton("I");
JButton jb10 = new JButton("J");
JButton jb11 = new JButton("K");
JButton jb12 = new JButton("L");
JPanel jp1 = new JPanel( );
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jp1.add(jb4);
JPanel jp2 = new JPanel(new GridLayout(4, 1));
jp2.add(jb5);
jp2.add(jb6);
jp2.add(jb7);
jp2.add(jb8);
JPanel jp3 = new JPanel(new GridLayout(2, 2));
jp3.add(jb9);
jp3.add(jb10);
jp3.add(jb11);
jp3.add(jb12);
JPanel jp4 = new JPanel(new BorderLayout( ));
jp4.add(jp1, BorderLayout.NORTH);
jp4.add(jp2, BorderLayout.EAST);
jp4.add(jp3, BorderLayout.WEST);
JFrame jf = new JFrame( );
jf.getContentPane( ).add(jp4);
jf.pack( );
jf.setVisible(true);
28
Copyright © 2015 Pearson Education, Inc.
Answer:
16) Draw the JFrame as you think it would appear given the following set of code:
JButton jb1 = new JButton("A");
JButton jb2 = new JButton("B");
JButton jb3 = new JButton("C");
JButton jb4 = new JButton("D");
JButton jb5 = new JButton("E");
JButton jb6 = new JButton("F");
JButton jb7 = new JButton("G");
JPanel jp1 = new JPanel(new GridLayout(3, 3));
jp1.add(jb1);
jp1.add(jb2);
jp1.add(jb3);
jp1.add(jb4);
jp1.add(jb5);
jp1.add(jb6);
jp1.add(jb7);
JFrame jf = new JFrame( );
jf.getContentPane( ).add(jp1);
jf.pack( );
jf.setVisible(true);
Answer:
29
Copyright © 2015 Pearson Education, Inc.
17) Draw the JFrame as you think it would appear given the following set of code:
JButton jb1 = new JButton("A");
JButton jb2 = new JButton("B");
JButton jb3 = new JButton("C");
JButton jb4 = new JButton("D");
JButton jb5 = new JButton("E");
JButton jb6 = new JButton("F");
JButton jb7 = new JButton("G");
JButton jb8 = new JButton("H");
JButton jb9 = new JButton("I");
JPanel jp1 = new JPanel(new BorderLayout( ));
jp1.add(jb1, BorderLayout.NORTH);
jp1.add(jb2, BorderLayout.WEST);
jp1.add(jb3, BorderLayout.EAST);
JPanel jp2 = new JPanel(new BorderLayout( ));
jp2.add(jb4, BorderLayout.WEST);
jp2.add(jb5, BorderLayout.SOUTH);
jp2.add(jb6, BorderLayout.EAST);
JPanel jp3 = new JPanel(new BorderLayout( ));
jp3.add(jb7, BorderLayout.WEST);
jp3.add(jb8, BorderLayout.NORTH);
jp3.add(jb9, BorderLayout.EAST);
JPanel jp4 = new JPanel(new BorderLayout( ));
jp4.add(jp1, BorderLayout.NORTH);
jp4.add(jp2, BorderLayout.EAST);
jp4.add(jp3, BorderLayout.SOUTH);
JFrame jf = new JFrame( );
jf.getContentPane( ).add(jp4);
jf.pack( );
jf.setVisible(true );
Answer:
30
Copyright © 2015 Pearson Education, Inc.
18) Why should the add( ), subtract( ), multiply( ), divide( ) methods in the RationalNumber
class in the textbook be declared to be public, while the gcd( ) method is declared to be private?
Answer: The numeric operations must be public because they must be accessible to users of the
RationalNumber class. Declaring them private or protected don't accomplish this. The gcd( )
method is declared private because it is a "utility" method within the class. It should only be
used by class members because it has access to the internal structure of the class. One might
want to declare a static gcd( ) method one that just accepts a pair of ints, or longs, or whatever.
This static method would be similar to those in the Math class, like abs( ), sqrt( ), max( ), etc.
Exploring the Variety of Random
Documents with Different Content
*** END OF THE PROJECT GUTENBERG EBOOK OLIVER CROMWELL
***
Updated editions will replace the previous one—the old editions
will be renamed.
Creating the works from print editions not protected by U.S.
copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.
START: FULL LICENSE
THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
To protect the Project Gutenberg™ mission of promoting the
free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.
Section 1. General Terms of Use and
Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.
1.B. “Project Gutenberg” is a registered trademark. It may only
be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E. Unless you have removed all references to Project
Gutenberg:
1.E.1. The following sentence, with active links to, or other
immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.
1.E.2. If an individual Project Gutenberg™ electronic work is
derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.
1.E.3. If an individual Project Gutenberg™ electronic work is
posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.
1.E.4. Do not unlink or detach or remove the full Project
Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
1.E.7. Do not charge a fee for access to, viewing, displaying,
performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.
1.E.8. You may charge a reasonable fee for copies of or
providing access to or distributing Project Gutenberg™
electronic works provided that:
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You provide a full refund of any money paid by a user who
notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.
• You provide, in accordance with paragraph 1.F.3, a full refund of
any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.E.9. If you wish to charge a fee or distribute a Project
Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.
1.F.
1.F.1. Project Gutenberg volunteers and employees expend
considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.
1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except
for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.
1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you
discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.
1.F.4. Except for the limited right of replacement or refund set
forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
1.F.5. Some states do not allow disclaimers of certain implied
warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.
1.F.6. INDEMNITY - You agree to indemnify and hold the
Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.
Section 2. Information about the Mission
of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.
Volunteers and financial support to provide volunteers with the
assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.
Section 3. Information about the Project
Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.
The Foundation’s business office is located at 809 North 1500
West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.
The Foundation is committed to complying with the laws
regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.
While we cannot and do not solicit contributions from states
where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.
International donations are gratefully accepted, but we cannot
make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.
Please check the Project Gutenberg web pages for current
donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.
Section 5. General Information About
Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.
Project Gutenberg™ eBooks are often created from several
printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
This website includes information about Project Gutenberg™,
including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
testbankfan.com

Java Software Solutions 8th Edition Lewis Test Bank

  • 1.
    Java Software Solutions8th Edition Lewis Test Bank download pdf https://testbankfan.com/product/java-software-solutions-8th-edition- lewis-test-bank/ Visit testbankfan.com to explore and download the complete collection of test banks or solution manuals!
  • 2.
    We believe theseproducts will be a great fit for you. Click the link to download now, or visit testbankfan.com to discover even more! Java Software Solutions 8th Edition Lewis Solutions Manual https://testbankfan.com/product/java-software-solutions-8th-edition- lewis-solutions-manual/ Java Software Solutions 9th Edition Lewis Test Bank https://testbankfan.com/product/java-software-solutions-9th-edition- lewis-test-bank/ Java Software Solutions 9th Edition Lewis Solutions Manual https://testbankfan.com/product/java-software-solutions-9th-edition- lewis-solutions-manual/ Essentials of Psychiatric Mental Health Nursing 1st Edition Varcarolis Test Bank https://testbankfan.com/product/essentials-of-psychiatric-mental- health-nursing-1st-edition-varcarolis-test-bank/
  • 3.
    Discrete Mathematics withApplications 4th Edition Susanna Solutions Manual https://testbankfan.com/product/discrete-mathematics-with- applications-4th-edition-susanna-solutions-manual/ Law for Business 11th Edition Barnes Test Bank https://testbankfan.com/product/law-for-business-11th-edition-barnes- test-bank/ Understanding Cross Cultural Management 2nd Edition Browaeys Solutions Manual https://testbankfan.com/product/understanding-cross-cultural- management-2nd-edition-browaeys-solutions-manual/ Organizational Behavior A Critical Thinking Approach 1st Edition Neck Solutions Manual https://testbankfan.com/product/organizational-behavior-a-critical- thinking-approach-1st-edition-neck-solutions-manual/ Principles of Leadership International 7th Edition DuBrin Test Bank https://testbankfan.com/product/principles-of-leadership- international-edition-7th-edition-dubrin-test-bank/
  • 4.
    Sociology in OurTimes 9th Edition Diana Test Bank https://testbankfan.com/product/sociology-in-our-times-9th-edition- diana-test-bank/
  • 5.
    1 Copyright © 2015Pearson Education, Inc. Java Software Solutions, 8e (Lewis/Loftus) Chapter 7 Object-Oriented Design 7.1 Multiple-Choice Questions 1) During program development, software requirements specify A) how the program will accomplish the task B) what the task is that the program must perform C) how to divide the task into subtasks D) how to test the program when it is done E) all of the above Answer: B Explanation: B) The specification phase is to understand the problem at hand so that the programmer can determine what needs to be done to solve the problem. The other efforts listed above are part of the design phase (A, C) and testing phase (D). 2) Once we have implemented the solution, we are not done with the problem because A) the solution may not be the best (most efficient) B) the solution may have errors and need testing and fixing before we are done C) the solution may, at a later date, need revising to handle new specifications D) the solution may, at a later date, need revising because of new programming language features E) all of the above Answer: E Explanation: E) A program should not be considered as a finished product until we are reasonably assured that it is efficient and error-free. Further, it is common that programs require modification in the future because of a change to specifications or a change to the language or computer running the program. 3) Of the various phases in software development, which of the following is usually the lengthiest? A) specification B) design C) implementation D) testing E) maintenance Answer: E Explanation: E) The maintenance phase exists for as long as the software is in use. Software requires modification (such as new requirements such as new features or I/O specifications) and so the maintenance phase is on-going whereas the other phases end once the software has been released and is in use.
  • 6.
    2 Copyright © 2015Pearson Education, Inc. 4) A bad programming habit is to build an initial program and then spend a great deal of time modifying the code until it is acceptable. This is known as A) the prototyping approach B) the waterfall model C) iterative development D) the recursive approach E) the build-and-fix approach Answer: E Explanation: E) Programmers who do not think things through will often build a program that does not fit the original requirements. They then spend an inordinate amount of time trying to repair the program to more properly fit. This is known as "build-and-fix" and is a poor programming practice. 5) The activities of the development cycle are generally thought to A) be strictly linear B) be rigidly ordered C) overlap D) have optional steps E) both A and B are true Answer: C Explanation: C) A flaw of the waterfall model is that it does not permit repetition or backtracking through the development cycle. However, phases often need revisiting resulting in a development cycle where the development activities overlap. 6) The idea of having programmers and developers meet in order to critique a software design or implementation is known as A) an interview B) a walkthrough C) prototyping D) aggregation E) evolutionary development Answer: B Explanation: B) Such meetings are very useful so that the various members can analyze the solution to that point in time and offer suggestions to enhance the design and implementation. This is called a walkthrough because it involves going step-by-step through the proposed or implemented design.
  • 7.
    3 Copyright © 2015Pearson Education, Inc. 7) Modifying a program in order to eliminate deficiencies is done in the ________ phase of the development cycle. A) design B) implementation C) testing D) use E) maintenance Answer: E Explanation: E) While testing is used to find errors, deficiencies are more commonly identified by the users of the system once the system has been released. After such deficiencies have been identified, it is up to the software maintenance group to eliminate them in future versions of the software. 8) It is easier to correct errors found in a program if A) they are identified early in the development cycle B) they are identified during testing C) they are identified during program use D) they are identified during maintenance E) all of the above are equally true, errors are easily corrected in any of these stages Answer: A Explanation: A) Errors introduced early in the development cycle often cause tremendous problems if not caught early on. Therefore, errors found in testing, use or maintenance phases may be too embedded in the systems' design to be easily corrected. But if found early on, the errors can be completely eliminated. 9) In general, spending more time in development to ensure better software will A) shorten testing time B) slightly reduce maintenance efforts C) slightly increase maintenance efforts D) greatly reduce maintenance efforts E) not alter the time it takes for any other stage whatsoever Answer: D Explanation: D) Spending more time in development promises better software, which in turn leads to less maintenance effort.
  • 8.
    4 Copyright © 2015Pearson Education, Inc. 10) The idea that an object can exist separate from the executing program that creates it is called A) transience B) static C) persistence D) serialization E) finality Answer: C Explanation: C) Objects are stored in memory and are reclaimed by the garbage collector when they are no longer referenced. When a Java program terminates, no object is referenced and so all objects are reclaimed. It is desirable, however, to be able to save any given object for future use. This trait is called persistence, and the ability to do this is by saving the instance data of the object to a file. This can be done by writing each instance data to a data file, but is simplified using Object Serialization. 11) In order to create a constant, you would use which of the following Java reserved words? A) private B) static C) int D) final E) class Answer: D Explanation: D) The reserved word final indicates that this is the final value that will be stored in this variable, thus making it unchangeable, or constant. While constants can be of type int, constants can be of any other type as well. It is the final reserved word that makes the value unchangeable. 12) Which of the following methods is a static method? The class in which the method is defined is given in parentheses following the method name. A) equals (String) B) toUpperCase (String) C) sqrt (Math) D) format (DecimalFormat) E) paint (Applet) Answer: C Explanation: C) The Math class defines all of its methods to be static. Invoking Math methods is done by using Math rather than a variable of type Math. The other methods above are not static.
  • 9.
    5 Copyright © 2015Pearson Education, Inc. 13) Static methods cannot A) reference instance data B) reference non-static instance data C) reference other objects D) invoke other static methods E) invoke non-static methods Answer: B Explanation: B) A static method is a method that is part of the class itself, not an instantiated object, and therefore the static method is shared among all instantiated objects of the class. Since the static method is shared, it cannot access non-static instance data because all non-static instance data are specific to instantiated objects. A static method can access static instance data because, like the method, the instance data is shared among all objects of the class. A static method can also access parameters passed to it. 14) An object that refers to part of itself within its own methods can use which of the following reserved words to denote this relationship? A) inner B) i C) private D) this E) static Answer: D Explanation: D) The reserved word this is used so that an object can refer to itself. For instance, if an object has an instance data x, then this.x refers to the object's value x. While this is not necessary, it can be useful if a local variable or parameter is named the same as an instance data. The reserved word this is also used to refer to the class as a whole, for instance, if the class is going to implement an interface class rather than import an implementation of an interface class. 15) An example of an aggregation relationship is A) parent and child B) animal and dog C) teacher and computer D) phone and fax machine E) all of the above Answer: C Explanation: C) An aggregate relationship describes how one object accomplishes a task by using another object. In the above list, the teacher uses the computer. The relationship in A is one of lineage (possibly ownership), in B is an is-a relationship as a dog is a child class of animal, and in D is one of similarity, phone and fax machine might be thought of as sibling classes, related to each other in that they are both children of a more general communication class.
  • 10.
    6 Copyright © 2015Pearson Education, Inc. 16) Inheritance through an extended (derived) class supports which of the following concepts? A) interfaces B) modulary C) information hiding D) code reuse E) correctness Answer: D Explanation: D) By extending a class and inheriting from it, the new class does not have to reimplement any of those inherited methods or instance data, thus saving the programmer an effort. So, code reuse is the ability to reuse someone else's code for your benefit by extending it for your need. 17) Java does not support multiple inheritance, but some of the abilities of multiple inheritance are available by A) importing classes B) implementing interfaces C) overriding parent class methods D) creating aliases E) using public rather than protected or private modifiers Answer: B Explanation: B) Since a class can implement any number of interfaces, that class is in essence using the interface classes as if those interfaces were defined in this class. So, this class is inheriting the methods and constants of the interfaces. Further, the class could extend another class and thus inherit directly and indirectly from multiple classes. This is not the exact same as multiple inheritance, but it is as close as Java comes to that concept. 18) Abstract methods are used when defining A) interface classes B) derived classes C) classes that have no constructor D) arrays E) classes that have no methods Answer: A Explanation: A) An interface is a class that has defined some of its components, but leaves other components (methods) for you to implement. So, these components (methods) are referred to as abstract and defined in the interface class as abstract.
  • 11.
    7 Copyright © 2015Pearson Education, Inc. 19) Which of the following is not a method of the Object class? A) clone B) compareTo C) equals D) toString E) all of the above are methods of the Object class Answer: B Explanation: B) The Object class defines clone to create a copy of any object, equals to determine if two objects are the same object, and toString to translate an Object into a String. However, compareTo is not implement by Object and must be explicitly implemented in any class that wants to implement the Comparable interface. 20) Which of the following interfaces would be used to implement a class that represents a group (or collection) of objects? A) Iterator B) Speaker C) Comparable D) MouseListener E) KeyListener Answer: A Explanation: A) Iterator is an abstract class allowing the user to extend a given class that implements Iterator by using the features defined there. These features include being able to store a group of objects and iterate (step) through them. 21) In order to implement Comparable in a class, what method(s) must be defined in that class? A) equals B) compares C) both lessThan and greaterThan D) compareTo E) both compares and equals Answer: D Explanation: D) The Comparable class requires the definition of a compareTo method that will compare two objects and determine if one is equal to the other, or if one is less than or greater than the other and respond with a negative int, 0 or a positive int. Since compareTo responds with 0 if the two objects are equal, there is no need to also define an equals method. For the questions below, consider a class called ChessPiece. This class has two instance data, String type and int player. The variable type will store "King", "Queen", "Bishop", etc and the int player will store 0 or 1 depending on whose piece it is. We wish to implement Comparable for the ChessPiece class. Assume that, the current ChessPiece is compared to a ChessPiece passed as a parameter. Pieces are ordered as follows: "Pawn" is a lesser piece to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King."
  • 12.
    8 Copyright © 2015Pearson Education, Inc. 22) Which of the following method headers would properly define the method needed to make this class Comparable? A) public boolean comparable(Object cp) B) public int comparable(Object cp) C) public int compareTo(Object cp) D) public int compareTo( ) E) public boolean compareTo(Object cp) Answer: C Explanation: C) To implement Comparable, you must implement a method called compareTo which returns an int. Further, since this class will compare this ChessPiece to another, we would except the other ChessPiece to be passed in as a parameter (although compareTo is defined to accept an Object, not a ChessPiece). 23) Which of the following pieces of logic could be used in the method that implements Comparable? Assume that the method is passed Object a, which is really a ChessPiece. Also assume that ChessPiece has a method called returnType which returns the type of the given piece. Only one of these answers has correct logic. A) if (this.type < a.returnType( )) return -1; B) if (this.type = = a.returnType( )) return 0; C) if (this.type.equals(a.returnType( )) return 0; D) if (a.returnType( ).equals("King")) return -1; E) if (a.returnType( ).equals("Pawn")) return 1; Answer: C Explanation: C) If the type of this piece and of a are the same type, then they are considered equal and the method should return 0 to indicate this. Note that this does not cover the case where this piece is a "Knight" and a is a "Bishop", so additional code would be required for the "equal to" case. The answer in B is not correct because it compares two Strings to see if they are the same String, not the same value. The logic in D and E are incorrect because neither of these takes into account what the current piece is, only what the parameter's type is. In D, if a is a "King", it will be greater than this piece if this piece is not a "King", but will be equal if this piece is a "King" and similarly in E, it does not consider if this piece is a "Pawn" or not. Finally, A would give a syntax error because two Strings cannot be compared using the "<" operator. 24) Which of the following would not be considered an algorithm? A) a recipe B) a computer program C) pseudocode D) a shopping list E) travel directions Answer: D Explanation: D) An algorithm is a step-by-step description of how to solve a problem, written at some level of specificity. The recipe and probably the pseudocode are written at a "high level" whereas a program and perhaps travel directions are written in more detail. A shopping list is not a step-by-step description, so it would not qualify as an algorithm.
  • 13.
    9 Copyright © 2015Pearson Education, Inc. 25) It is important to dissect a problem into manageable pieces before trying to solve the problem because A) most problems are too complex to be solved as a single, large activity B) most problems are solved by multiple people and it is easy to assign each piece to a separate person C) it is easier to integrate small pieces of a program into one program than it is to integrate one big chunk of code into one program D) our first solution may not solve the problem correctly E) all of the above Answer: A Explanation: A) Any interesting problem will be too complex to solve easily as a single activity. By decomposing the problem, we can build small solutions to each piece and then integrate the pieces. Answer D is true, but does is not the reason why we will break a problem down into pieces. 26) Having multiple class methods of the same name where each method has a different number of or type of parameters is known as A) encapsulation B) information hiding C) tokenizing D) importing E) method overloading Answer: E Explanation: E) When methods share the same name, they are said to be overloaded. The number and type of parameters passed in the message provides the information by which the proper method is called. 27) The goal of testing is to A) ensure that the software has no errors B) find syntax errors C) find logical and run-time errors D) evaluate how well the software meets the original requirements E) give out-of-work programmers something to do Answer: C Explanation: C) Testing is required because all software will have errors. Complex systems especially need testing before they can be released. The types of errors sought are logical errors and run-time errors. All syntax errors will have been identified and fixed during implementation.
  • 14.
    10 Copyright © 2015Pearson Education, Inc. 28) Arranging components in a GUI container is accomplished by using which of the following? A) Layout manager B) Listener interface C) String array D) Event generator E) JComboBox Answer: A Explanation: A) There are several classes of Layout managers. A Layout manager is used to add GUI components to the container in some manner. The type of Layout manager determines how items are added. 29) Which Layout Manager type would you use if you want GUI components to be placed at the North, South, East, West and Center of the container? A) FlowLayout B) BorderLayout C) BoxLayout D) GridLayout E) TabbedPane Answer: B Explanation: B) The BorderLayout specifically allows you to specify the component's location as one of NORTH, SOUTH, EAST, WEST or CENTER where the value (e.g., NORTH) is a constant predefined in the class. 30) Which Layout Manager type would you use if you want GUI components to be placed in 2 columns over 5 rows? A) FlowLayout B) BorderLayout C) BoxLayout D) GridLayout E) TabbedPane Answer: D Explanation: D) The GridLayout manager allows you to specify the number of rows and columns and then add elements across the column on one row until it is filled, and then on to the next row, until all of the rows are filled. 31) Which Layout Manager is used by default if you do not specify a Layout Manager for your GUI container? A) FlowLayout B) BorderLayout C) BoxLayout D) GridLayout E) TabbedPane Answer: A Explanation: A) The FlowLayout is the default manager. It places GUI items across in one row only. Other Layout Managers are more sophisticated and lead to better designed containers. 32) Which of the following GUI classes requires that it have a LayoutManager before any GUI
  • 15.
    11 Copyright © 2015Pearson Education, Inc. components are added to it? A) JButton B) JSlider C) JPanel D) JFrame E) both C and D but not A or B Answer: C Explanation: C) The JPanel requires adding a LayoutManager to it before any components are added to it. This allows the components added to be arranged on the JPanel as desired. Neither the JButton nor JSlider have components added to them and so do not require a LayoutManager. The JFrame does not use a LayoutManager but instead adds elements through getContentPane( ). 33) In using the BoxLayout, adding space between components in a container can be accomplished by A) including TabbedPanes B) including JButtons that have no names and thus will appear invisible C) adding invisible components D) inserting IconImages of blank images E) any of the above Answer: C Explanation: C) The BoxLayout manager allows for the inclusion of specially designated "invisible" components to take up space between real components and thus provide spacing. 34) In order to display three components vertically in a container, you could use all but which of the following layout managers? A) FlowLayout B) BoxLayout C) GridLayout D) BorderLayout E) you could use any of the above Answer: A Explanation: A) FlowLayout puts components horizontally and you cannot change that. BoxLayout can place items horizontally or vertically. GridLayout allows you to specify the number of rows and columns and to place the three components vertically, you would use (3, 1) that is, 3 rows, 1 column. BorderLayout can place three components vertically by placing them in the NORTH, CENTER and SOUTH positions.
  • 16.
    12 Copyright © 2015Pearson Education, Inc. 35) What is wrong with the following message to create a BoxLayout for the JPanel jp? jp.setLayout(new BoxLayout(BoxLayout.X_AXIS)); A) X_AXIS is not a valid constant for BoxLayout, it should instead be HORIZONTAL B) Aside from X_AXIS, the constructor also requires a Dimension to determine the size of the Box C) Aside from X_AXIS, the constructor also needs a command regarding horizontal glue as in createHorizontalGlue( ) D) The BoxLayout constructor is lacking a reference to the container that the BoxLayout manager will govern E) There is nothing wrong with it at all Answer: D Explanation: D) The BoxLayout manager constructor requires two parameters, a reference to the container that the manager will govern, and an axis for the layout, (vertical or horizontal) as specified by either X_AXIS or Y_AXIS. 36) In which phase of program development would you expect the programmer(s) to create the pseudocode? A) Software requirements B) Software design C) Software implementation D) Software testing E) Could occur in any of the above Answer: B Explanation: B) Pseudocode is a description of an algorithm written in an English-like way rather than in a specific programming language. This is part of the program's design. In the implementation phase, the programmer(s) translates the pseudocode into the programming language being used. 37) Which of the following is considered a top-level container? A) Panel B) Frame C) Box D) Layout Manager E) A, B, and C Answer: B Explanation: B) While the answers in A, B and C are all types of containers, the Box and Panel are made available to contain other components and are themselves placed into other containers. The Frame is a top-level container because a Frame will not store other Frames, but instead, the Frame contains Panels which can contain Boxes, Panels and other components.
  • 17.
    13 Copyright © 2015Pearson Education, Inc. 38) The JFrame below has a JBorder created using which of the following BorderFactory formats? A) TitledBorder B) MatteBorder C) EtchedBorder D) RaisedBevelBorder E) LoweredBevelBorder Answer: D Explanation: D) The JFrame has a Bevel border which is raised. A TitledBorder has a title running along the top of it. The MatteBorder is of a Color or contains an image of some kind. The EtchedBorder is not raised, and the LoweredBevelBorder is lowered, not raised. 39) To take 2 borders and use one as an outer border and the other as an inner border, you would create a A) compound border B) nested border C) split border D) border factory E) matte border Answer: A Explanation: A) The compound border comprises two borders that are combined together, one border being the outside border and the other being the inside border. 40) In which phase of program development would you expect the programmer(s) to determine the classes and objects needed? A) software requirements B) software design C) software implementation D) software testing E) could occur in any of the above Answer: B Explanation: B) Determining which classes and objects to use or create is part of the design.
  • 18.
    14 Copyright © 2015Pearson Education, Inc. 41) If a programmer follows the four phases of program development as intended, which of the four phases should require the least amount of creativity? A) software requirements B) software design C) software implementation D) software testing E) none of the above, all four levels would require equal creativity Answer: C Explanation: C) Once the implementation phase has been reached, the algorithm should have already been specified, so the only effort involved in the implementation phase is of translating from the design (which is probably in an English-like pseudocode) to the programming language, and entering the code through an editor. The requirements and design phases require understanding the problem and coming up with a solution respectively, requiring creativity, and the testing phase will require diagnostic abilities usually forcing the programmer(s) to be creative in how the errors are found and fixed. 7.2 True/False Questions 1) The most important decisions regarding the development of a system are made during the implementation phase while code is actively being written. Answer: FALSE Explanation: All of the important decisions should be made during earlier phases of development, particularly during the design phase. By the time the implementation phase is reached, the entire system design should be available and this phase should only entail translating the design into code. 2) Unlike the String class where you must pass a message to an object (instance) of the class, as in x.length( ), in order to use the Math class, you pass messages directly to the class name, as in Math.abs( ) or Math.sqrt( ). Answer: TRUE Explanation: The Math class uses methods known as static methods (or class methods) which are invoked by passing a message directly to the class name itself rather than to an object of the class. 3) Assume that the class Bird has a static method fly( ). If b is a Bird, then to invoke fly, you could do Bird.fly( );. Answer: TRUE Explanation: Static methods are invoked through the class and not an object of the class. This is because the static method is shared among all instances. So, Bird.fly( ); will invoke fly. It should be noted that fly can also be invoked through b, so b.fly( ); will also work. 4) Interface classes cannot be extended but classes that implement interfaces can be extended. Answer: FALSE Explanation: Any class can be extended whether it is an interface, implements an interface, or neither. The only exception to this is if the class is explicitly modified with the word "final" in which case it cannot be extended.
  • 19.
    15 Copyright © 2015Pearson Education, Inc. 5) If classes C1 and C2 both implement an interface Cint, which has a method whichIsIt, and if C1 c = new C1( ); is performed at one point of the program, then a later instruction c.whichIsIt( ); will invoke the whichIsIt method defined in C1. Answer: FALSE Explanation: Because C1 and C2 implement the same interface, they both implement whichIsIt. The variable c is known as a polymorphic variable, meaning that it can change from being an C1 to a C2. So, the message c.whichIsIt( ); may invoke C1's whichIsIt or C2's whichIsIt. There is no way to tell until run-time. 6) Any class can implement an interface, but no classes can implement more than a single interface. Answer: FALSE Explanation: Classes can implement any number of interfaces, 0, 1, or more. 7) All objects implement Comparable. Answer: FALSE Explanation: Comparable is an interface, and the class must define the compareTo method and explicitly state that it implements Comparable to be considered an implementation of Comparable. Most classes do not implement Comparable. 8) Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header. Answer: FALSE Explanation: The question has the two definitions reversed. Formal parameters are those that appear in the method header, actual parameters are the parameters in the method call (those being passed to the method). 9) Defining formal parameters requires including each parameters type. Answer: TRUE Explanation: In order for the compiler to check to see if a method call is correct, the compiler needs to know the types for the parameters being passed. Therefore, all formal parameters (those defined in the method header) must include their type. This is one element that makes Java a Strongly Typed language. 10) It is not possible to test out any single method or class of a system until the entire system has been developed, and so all testing is postponed until after the implementation phase. Answer: FALSE Explanation: While it is true that testing occurs after implementation, some testing can take place during implementation. In Java, it is possible to test out single methods or classes by creating stubs of other methods and classes that are simple placeholders. For instance, if one method calls another method and the second method is not yet written, a stub of the second method can be written that simply returns a value that would normally be expected so that the first method can be tested.
  • 20.
    16 Copyright © 2015Pearson Education, Inc. 11) All parts of a container in BorderLayout must be used. Answer: FALSE Explanation: BorderLayout allows components to be inserted in any of North, South, East, West and Center of the GUI, but as many or as few of these five sections can be used as needed. 12) A JPanel can itself contain JPanels. Answer: TRUE Explanation: It is common to place GUI components into a JPanel and then place several JPanels into another JPanel. Each JPanel has its own layout manager allowing the programmer to specify in detail how components should appear. For instance, one JPanel might use a GridLayout and another a BoxLayout and then the two JPanels be placed in the NORTH and EAST sections of a JPanel using BorderLayout. 13) If a GUI container is resized by the user, all components of the GUI are automatically increased or decreased by the same fraction to fit in the newly sized container. Answer: FALSE Explanation: The layout manager will reposition the GUI items to fit in the newly sized container. 14) The size and shape of a GUI container is based on the layout manager selected and the type and number of items added to the container. Answer: TRUE Explanation: It is the layout manager's task to arrange the components in the container. Based on the order that the items are entered and the type of layout manager, the size and shape are determined. 15) A border can be put around any Swing component with the exception of a JButton and JScrollPane component. Answer: FALSE Explanation: A border can be up around any Swing component no matter the type. 16) The term "test case" is used to express a set of inputs (or user actions) and the expected outputs to be used in testing out software. Answer: TRUE Explanation: In order to test software to see if it is working correctly, a tester will often start with a series of inputs and the expected outputs. If, when running the program on the inputs, the outputs are not the expected results, then errors are assumed to exist. These input/output pairs are known as test cases.
  • 21.
    17 Copyright © 2015Pearson Education, Inc. 17) In black-box testing, the tester should already know something about how the program is implemented so that he/she can more carefully identify what portion(s) of the software are leading to errors. Answer: FALSE Explanation: In black-box testing, the tester should know nothing about how the software is implemented. In essence, the software is a black-box which has an input and an output and the mechanisms of the program are opaque. If the tester does know something about how the program works, then the tester's test cases might be biased. If the tester knows how the program works, then testing is known as glass-box testing. 7.3 Free-Form Questions 1) Provide a reason why an instance data would be declared static. Answer: If an instance data is to be shared among all objects of the class, the instance data would be static. As an example, an instance data that counts the number of times something has happened across all objects of the class would be made static. If we are writing a chess game and have a ChessPiece class that includes a method called movePiece, we would want to know how many moves a player has made, but not necessarily how many times a single piece has been moved. So, all of the ChessPieces share a numberOfTimesMoved instance data that is incremented by any ChessPiece whenever it is moved. 2) Provide a reason why a method would be declared static. Answer: A method is declared static if it might be used, not by the current object, but by any objects of the class. That is, the method does not require access to any single object's instance data. Consider a class called Point that consists of an x and y coordinate. To determine the distance between two Points, we could make a static computeDistance method. It is passed two Points as parameters and computes the distance. Another example is the Keyboard class from the textbook, which does not itself have any instance data. 3) Write a static method that is passed two ChessPieces and determines if the two pieces are owned by the same player. It should return true or false. Answer: public static boolean samePlayer(ChessPiece p1, ChessPiece p2) { return (p1.returnPlayer( ) = = p2.returnPlayer( )); } 4) Explain the difference between implementing an interface and a derived class. Answer: Implementing an interface means that you are adding to your class any mechanisms defined in an abstract class. Your class essentially is expanded to contain those items defined in the interface class but you have to implement any of those items that are abstract. The appeal is that other objects might call upon your class to use the interface methods without knowing anything else about your class. The derived class is similar in that you are gaining items previously defined, although in this case, those items are defined in the parent class (as long as those items are protected or public) and you do not have to implement any of them unless you want to redefine them. One difference between the two is that the interface cannot be instantiated directly. Another difference is that your class "inherits" abstract methods from the interface class as opposed to implemented methods from a super class.
  • 22.
    18 Copyright © 2015Pearson Education, Inc. 5) Define an interface class that contains two int constants, X = 5 and Y = 10 and one int method called useXY which receives no parameters. Call your interface class XYClass Answer: public interface XYClass { public final int X = 5; public final int Y = 10; public int useXY( ); } 6) Assume a class Foo implements Comparable. Without knowing anything else about the Foo class, write an equal method that returns true if the Foo parameter passed to this Foo is equal to this Foo as determined by using the implementation of Comparable. Answer: public boolean equals(Foo a) { if(compareTo(a)) = = 0) return true; else return false; }
  • 23.
    19 Copyright © 2015Pearson Education, Inc. 7) To implement Comparable for the ChessPiece class, the current ChessPiece's type is compared to a ChessPiece passed as a parameter. The method should return 0 if the types are equal, -1 if this piece's type is a lesser piece than the parameter's type, and 1 if this piece's type is a greater piece than the parameter's type. Pieces are ordered as follows: "Pawn" is a lesser piece to a "Knight" and a "Bishop", "Knight" and "Bishop" are equivalent for this example, both are lesser pieces to a "Rook" which is a lesser piece to a "Queen" which is a lesser piece to a "King." Write the proper method to implement Comparable for this class. Answer: public int compareTo(ChessPiece a) { if (this.type.equals(a.returnType( )) | | (this.type.equals("Knight") && a.returnType( ).equals("Bishop")) | | (this.type.equals("Bishop") && a.returnType( ).equals("Knight"))) return 0; else if (this.type.equals("King")) return 1; else if (a.returnType( ).equals("King")) return-1; else if (this.type.equals("Queen")) return 1; else if (a.returnType( ).equals("Queen")) return -1; else if (this.type.equals("Rook")) return 1; else if (a.returnType( ).equals("Rook")) return -1; else if (this.type.equals("Knight") | | (this.type.equals("Bishop")) return 1; else if (a.returnType( ).equals("Knight") | | (a.returnType( ).equals("Bishop")) return -1; } 8) Why was the Y2K problem a problem of software maintenance and not a problem of software testing? Answer: The Y2K problem was caused by older software that stored the year as a 2-digit value instead of a 4-digit value (older software attempted to save memory space in any way possible, this was a common way to save 2 bytes). Since the 2-digit year was not a logical or run-time error, but instead, a flaw in the design, this problem was not detected during software testing. Instead, it was not until the late 1990s, when people began to realize that a 2-digit year would cause a problem starting in 2000, that the Y2K problem was identified and solutions sought, so the problem was one of software maintenance how to maintain this older software so that it still functions starting in the year 2000.
  • 24.
    20 Copyright © 2015Pearson Education, Inc. 9) In what way is black-box testing better than glass-box testing? In what way is glass-box testing better than black-box testing? Answer: Black-box testing is superior because the tester knows nothing of the software and so will test the software without preconceived ideas of where errors might exist. The tester is testing the software blindly, much as a user will use the software–without intimate knowledge of how the software works. The result should be that if errors exist that a user might stumble across, the tester should find them. While black-box testing of software has the advantage that the tester operates much like the users are expected to, the disadvantage is that it is a blind test and knowledge of how the software functions could be useful. If programmers suspect that some awkward or difficult implementation may be buggy, then spending more time testing that portion of the software is advantageous. This form of testing requires knowledge of how the software works. So, both black-box and glass-box testing have their own advantages and disadvantages. 10) Write a set of code that will allow a user to select an input image and then place this image in a JLabel lab1 and add lab1 to a JPanel as the northern component in a JFrame using BorderLayout. The JFrame has already been instantiated as jf and the BorderLayout already established. Hint: a JFileChooser returns a File and JLabel requires the String name of a file as an argument. A File can return its name using File class' method getAbsolutePath( ) Answer: JFileChooser jfc = new JFileChooser( ); jfc.showOpenDialog(null); File f = jfc.getSelectedFile( ); ImageIcon im = new ImageIcon(f. getAbsoluteFile( )); JLabel lab1 = new JLabel(im); jp.add(lab1, BorderLayout.NORTH); jf.getContentPane( ).add(jp); jf.pack( ); jf.setVisible(true);
  • 25.
    21 Copyright © 2015Pearson Education, Inc. 11) Write code to create a JPanel with 4 JCheckBox GUI components and two JLabels for output, one that says "Current cost is" and the other that outputs the computed cost based on which of the food items has been selected. Answer: FoodListener fl = new FoodListener( ); JPanel jp = new JPanel(new GridLayout(3, 2)); jcb1 = new JCheckBox("Burger"); jcb2 = new JCheckBox("Fries"); jcb3 = new JCheckBox("Soda"); jcb4 = new JCheckBox("Cookie"); jcb1.addItemListener(fl); jcb2.addItemListener(fl); jcb3.addItemListener(fl); jcb4.addItemListener(fl); jl1 = new JLabel("Current cost is"); jl2 = new JLabel(" "); jp.add(jcb1); jp.add(jcb2); jp.add(jcb3); jp.add(jcb4); jp.add(jl1) jpadd(jl2); add(jp);
  • 26.
    22 Copyright © 2015Pearson Education, Inc. 12) Provide code to generate the following JFrame. Each lettered item is a JButton. Hint: Create several JPanels, each one having two or more JButtons and taken up a portion of the JFrame. Answer: JFrame jf = new JFrame( ); JPanel jp1 = new JPanel(new BorderLayout( )); JPanel jp2 = new JPanel(new FlowLayout( )); JPanel jp3 = new JPanel(new GridLayout(2, 3)); JButton lab1 = new JButton("A"); JButton lab2 = new JButton("B"); JButton lab3 = new JButton("C"); JButton lab4 = new JButton("D"); JButton lab5 = new JButton("E"); JButton lab6 = new JButton("F"); JButton lab7 = new JButton("G"); JButton lab8 = new JButton("H"); JButton lab9 = new JButton("I"); JButton lab10 = new JButton("J"); JButton lab11 = new JButton("K"); JButton lab12 = new JButton("L"); JButton lab13 = new JButton("M"); jp1.add(lab1, BorderLayout.NORTH); jp1.add(lab2, BorderLayout.WEST); jp1.add(lab3, BorderLayout.CENTER); jp1.add(lab4, BorderLayout.EAST); jp1.add(lab5, BorderLayout.SOUTH); jp2.add(lab6); jp2.add(lab7); jp3.add(lab8); jp3.add(lab9); jp3.add(lab10); jp3.add(lab11);
  • 27.
    23 Copyright © 2015Pearson Education, Inc. jp3.add(lab12); jp3.add(lab13); JPanel jp4 = new JPanel(new GridLayout(3, 1)); jp4.add(jp1); jp4.add(jp2); jp4.add(jp3); jf.getContentPane( ).add(jp4); jf.pack( ); jf.setVisible(true);
  • 28.
    24 Copyright © 2015Pearson Education, Inc. 13) Provide code to generate the following JFrame. Each lettered item is a JButton. Hint: Create several JPanels, each one having two or more JButtons and taken up a portion of the JFrame. Answer: JFrame jf = new JFrame( ); JPanel jp1 = new JPanel(new GridLayout(1, 3)); JPanel jp2 = new JPanel(new GridLayout(3, 1)); JPanel jp3 = new JPanel(new GridLayout(3, 1)); JPanel jp4 = new JPanel(new GridLayout(1, 3)); JPanel jp5 = new JPanel(new BorderLayout( )); JButton lab1 = new JButton("A"); JButton lab2 = new JButton("B"); JButton lab3 = new JButton("C"); JButton lab4 = new JButton("D"); JButton lab5 = new JButton("E"); JButton lab6 = new JButton("F"); JButton lab7 = new JButton("G"); JButton lab8 = new JButton("H"); JButton lab9 = new JButton("I"); JButton lab10 = new JButton("J"); JButton lab11 = new JButton("K"); JButton lab12 = new JButton("L"); JButton lab13 = new JButton("M"); jp1.add(lab1); jp1.add(lab2); jp1.add(lab3); jp2.add(lab4); jp2.add(lab5); jp2.add(lab6); jp3.add(lab7); jp3.add(lab8); jp3.add(lab9); jp4.add(lab11); jp4.add(lab12); jp4.add(lab13); jp5.add(jp1, BorderLayout.NORTH); jp5.add(jp2, BorderLayout.WEST); jp5.add(lab10, BorderLayout.CENTER);
  • 29.
    25 Copyright © 2015Pearson Education, Inc. jp5.add(jp3, BorderLayout.EAST); jp5.add(jp4, BorderLayout.SOUTH); jf.getContentPane( ).add(jp5); jf.pack( ); jf.setVisible(true); 14) Provide code to generate the following JFrame. Each lettered item is a JButton. Hint: Create several JPanels, each one having two or more JButtons and taken up a portion of the JFrame. Answer: JFrame jf = new JFrame( ); JPanel jp1 = new JPanel(new GridLayout(2, 2)); JPanel jp2 = new JPanel(new GridLayout(2, 2)); JPanel jp3 = new JPanel(new FlowLayout( )); JPanel jp4 = new JPanel(new BorderLayout( )); JPanel jp5 = new JPanel(new GridLayout(2, 2)); JButton lab1 = new JButton("A"); JButton lab2 = new JButton("B"); JButton lab3 = new JButton("C"); JButton lab4 = new JButton("D"); JButton lab5 = new JButton("E"); JButton lab6 = new JButton("F"); JButton lab7 = new JButton("G"); JButton lab8 = new JButton("H"); JButton lab9 = new JButton("I"); JButton lab10 = new JButton("J"); JButton lab11 = new JButton("K"); JButton lab12 = new JButton("L"); JButton lab13 = new JButton("M"); JButton lab14 = new JButton("N"); JButton lab15 = new JButton("O"); JButton lab16 = new JButton("P"); jp1.add(lab1); jp1.add(lab2); jp1.add(lab3);
  • 30.
    26 Copyright © 2015Pearson Education, Inc. jp1.add(lab4); jp2.add(lab5); jp2.add(lab6); jp2.add(lab7); jp2.add(lab8); jp3.add(lab9); jp3.add(lab10); jp3.add(lab11); jp4.add(lab12, BorderLayout.WEST); jp4.add(lab13, BorderLayout.NORTH); jp4.add(lab14, BorderLayout.CENTER); jp4.add(lab15, BorderLayout.EAST); jp4.add(lab16, BorderLayout.SOUTH); jp5.add(jp1); jp5.add(jp2); jp5.add(jp3); jp5.add(jp4); jf.getContentPane( ).add(jp5); jf.pack( ); jf.setVisible(true);
  • 31.
    27 Copyright © 2015Pearson Education, Inc. 15) Draw the JFrame as you think it would appear given the following set of code: JButton jb1 = new JButton("A"); JButton jb2 = new JButton("B"); JButton jb3 = new JButton("C"); JButton jb4 = new JButton("D"); JButton jb5 = new JButton("E"); JButton jb6 = new JButton("F"); JButton jb7 = new JButton("G"); JButton jb8 = new JButton("H"); JButton jb9 = new JButton("I"); JButton jb10 = new JButton("J"); JButton jb11 = new JButton("K"); JButton jb12 = new JButton("L"); JPanel jp1 = new JPanel( ); jp1.add(jb1); jp1.add(jb2); jp1.add(jb3); jp1.add(jb4); JPanel jp2 = new JPanel(new GridLayout(4, 1)); jp2.add(jb5); jp2.add(jb6); jp2.add(jb7); jp2.add(jb8); JPanel jp3 = new JPanel(new GridLayout(2, 2)); jp3.add(jb9); jp3.add(jb10); jp3.add(jb11); jp3.add(jb12); JPanel jp4 = new JPanel(new BorderLayout( )); jp4.add(jp1, BorderLayout.NORTH); jp4.add(jp2, BorderLayout.EAST); jp4.add(jp3, BorderLayout.WEST); JFrame jf = new JFrame( ); jf.getContentPane( ).add(jp4); jf.pack( ); jf.setVisible(true);
  • 32.
    28 Copyright © 2015Pearson Education, Inc. Answer: 16) Draw the JFrame as you think it would appear given the following set of code: JButton jb1 = new JButton("A"); JButton jb2 = new JButton("B"); JButton jb3 = new JButton("C"); JButton jb4 = new JButton("D"); JButton jb5 = new JButton("E"); JButton jb6 = new JButton("F"); JButton jb7 = new JButton("G"); JPanel jp1 = new JPanel(new GridLayout(3, 3)); jp1.add(jb1); jp1.add(jb2); jp1.add(jb3); jp1.add(jb4); jp1.add(jb5); jp1.add(jb6); jp1.add(jb7); JFrame jf = new JFrame( ); jf.getContentPane( ).add(jp1); jf.pack( ); jf.setVisible(true); Answer:
  • 33.
    29 Copyright © 2015Pearson Education, Inc. 17) Draw the JFrame as you think it would appear given the following set of code: JButton jb1 = new JButton("A"); JButton jb2 = new JButton("B"); JButton jb3 = new JButton("C"); JButton jb4 = new JButton("D"); JButton jb5 = new JButton("E"); JButton jb6 = new JButton("F"); JButton jb7 = new JButton("G"); JButton jb8 = new JButton("H"); JButton jb9 = new JButton("I"); JPanel jp1 = new JPanel(new BorderLayout( )); jp1.add(jb1, BorderLayout.NORTH); jp1.add(jb2, BorderLayout.WEST); jp1.add(jb3, BorderLayout.EAST); JPanel jp2 = new JPanel(new BorderLayout( )); jp2.add(jb4, BorderLayout.WEST); jp2.add(jb5, BorderLayout.SOUTH); jp2.add(jb6, BorderLayout.EAST); JPanel jp3 = new JPanel(new BorderLayout( )); jp3.add(jb7, BorderLayout.WEST); jp3.add(jb8, BorderLayout.NORTH); jp3.add(jb9, BorderLayout.EAST); JPanel jp4 = new JPanel(new BorderLayout( )); jp4.add(jp1, BorderLayout.NORTH); jp4.add(jp2, BorderLayout.EAST); jp4.add(jp3, BorderLayout.SOUTH); JFrame jf = new JFrame( ); jf.getContentPane( ).add(jp4); jf.pack( ); jf.setVisible(true ); Answer:
  • 34.
    30 Copyright © 2015Pearson Education, Inc. 18) Why should the add( ), subtract( ), multiply( ), divide( ) methods in the RationalNumber class in the textbook be declared to be public, while the gcd( ) method is declared to be private? Answer: The numeric operations must be public because they must be accessible to users of the RationalNumber class. Declaring them private or protected don't accomplish this. The gcd( ) method is declared private because it is a "utility" method within the class. It should only be used by class members because it has access to the internal structure of the class. One might want to declare a static gcd( ) method one that just accepts a pair of ints, or longs, or whatever. This static method would be similar to those in the Math class, like abs( ), sqrt( ), max( ), etc.
  • 35.
    Exploring the Varietyof Random Documents with Different Content
  • 36.
    *** END OFTHE PROJECT GUTENBERG EBOOK OLIVER CROMWELL *** Updated editions will replace the previous one—the old editions will be renamed. Creating the works from print editions not protected by U.S. copyright law means that no one owns a United States copyright in these works, so the Foundation (and you!) can copy and distribute it in the United States without permission and without paying copyright royalties. Special rules, set forth in the General Terms of Use part of this license, apply to copying and distributing Project Gutenberg™ electronic works to protect the PROJECT GUTENBERG™ concept and trademark. Project Gutenberg is a registered trademark, and may not be used if you charge for an eBook, except by following the terms of the trademark license, including paying royalties for use of the Project Gutenberg trademark. If you do not charge anything for copies of this eBook, complying with the trademark license is very easy. You may use this eBook for nearly any purpose such as creation of derivative works, reports, performances and research. Project Gutenberg eBooks may be modified and printed and given away—you may do practically ANYTHING in the United States with eBooks not protected by U.S. copyright law. Redistribution is subject to the trademark license, especially commercial redistribution. START: FULL LICENSE
  • 37.
    THE FULL PROJECTGUTENBERG LICENSE
  • 38.
    PLEASE READ THISBEFORE YOU DISTRIBUTE OR USE THIS WORK To protect the Project Gutenberg™ mission of promoting the free distribution of electronic works, by using or distributing this work (or any other work associated in any way with the phrase “Project Gutenberg”), you agree to comply with all the terms of the Full Project Gutenberg™ License available with this file or online at www.gutenberg.org/license. Section 1. General Terms of Use and Redistributing Project Gutenberg™ electronic works 1.A. By reading or using any part of this Project Gutenberg™ electronic work, you indicate that you have read, understand, agree to and accept all the terms of this license and intellectual property (trademark/copyright) agreement. If you do not agree to abide by all the terms of this agreement, you must cease using and return or destroy all copies of Project Gutenberg™ electronic works in your possession. If you paid a fee for obtaining a copy of or access to a Project Gutenberg™ electronic work and you do not agree to be bound by the terms of this agreement, you may obtain a refund from the person or entity to whom you paid the fee as set forth in paragraph 1.E.8. 1.B. “Project Gutenberg” is a registered trademark. It may only be used on or associated in any way with an electronic work by people who agree to be bound by the terms of this agreement. There are a few things that you can do with most Project Gutenberg™ electronic works even without complying with the full terms of this agreement. See paragraph 1.C below. There are a lot of things you can do with Project Gutenberg™ electronic works if you follow the terms of this agreement and help preserve free future access to Project Gutenberg™ electronic works. See paragraph 1.E below.
  • 39.
    1.C. The ProjectGutenberg Literary Archive Foundation (“the Foundation” or PGLAF), owns a compilation copyright in the collection of Project Gutenberg™ electronic works. Nearly all the individual works in the collection are in the public domain in the United States. If an individual work is unprotected by copyright law in the United States and you are located in the United States, we do not claim a right to prevent you from copying, distributing, performing, displaying or creating derivative works based on the work as long as all references to Project Gutenberg are removed. Of course, we hope that you will support the Project Gutenberg™ mission of promoting free access to electronic works by freely sharing Project Gutenberg™ works in compliance with the terms of this agreement for keeping the Project Gutenberg™ name associated with the work. You can easily comply with the terms of this agreement by keeping this work in the same format with its attached full Project Gutenberg™ License when you share it without charge with others. 1.D. The copyright laws of the place where you are located also govern what you can do with this work. Copyright laws in most countries are in a constant state of change. If you are outside the United States, check the laws of your country in addition to the terms of this agreement before downloading, copying, displaying, performing, distributing or creating derivative works based on this work or any other Project Gutenberg™ work. The Foundation makes no representations concerning the copyright status of any work in any country other than the United States. 1.E. Unless you have removed all references to Project Gutenberg: 1.E.1. The following sentence, with active links to, or other immediate access to, the full Project Gutenberg™ License must appear prominently whenever any copy of a Project Gutenberg™ work (any work on which the phrase “Project
  • 40.
    Gutenberg” appears, orwith which the phrase “Project Gutenberg” is associated) is accessed, displayed, performed, viewed, copied or distributed: This eBook is for the use of anyone anywhere in the United States and most other parts of the world at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org. If you are not located in the United States, you will have to check the laws of the country where you are located before using this eBook. 1.E.2. If an individual Project Gutenberg™ electronic work is derived from texts not protected by U.S. copyright law (does not contain a notice indicating that it is posted with permission of the copyright holder), the work can be copied and distributed to anyone in the United States without paying any fees or charges. If you are redistributing or providing access to a work with the phrase “Project Gutenberg” associated with or appearing on the work, you must comply either with the requirements of paragraphs 1.E.1 through 1.E.7 or obtain permission for the use of the work and the Project Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9. 1.E.3. If an individual Project Gutenberg™ electronic work is posted with the permission of the copyright holder, your use and distribution must comply with both paragraphs 1.E.1 through 1.E.7 and any additional terms imposed by the copyright holder. Additional terms will be linked to the Project Gutenberg™ License for all works posted with the permission of the copyright holder found at the beginning of this work. 1.E.4. Do not unlink or detach or remove the full Project Gutenberg™ License terms from this work, or any files
  • 41.
    containing a partof this work or any other work associated with Project Gutenberg™. 1.E.5. Do not copy, display, perform, distribute or redistribute this electronic work, or any part of this electronic work, without prominently displaying the sentence set forth in paragraph 1.E.1 with active links or immediate access to the full terms of the Project Gutenberg™ License. 1.E.6. You may convert to and distribute this work in any binary, compressed, marked up, nonproprietary or proprietary form, including any word processing or hypertext form. However, if you provide access to or distribute copies of a Project Gutenberg™ work in a format other than “Plain Vanilla ASCII” or other format used in the official version posted on the official Project Gutenberg™ website (www.gutenberg.org), you must, at no additional cost, fee or expense to the user, provide a copy, a means of exporting a copy, or a means of obtaining a copy upon request, of the work in its original “Plain Vanilla ASCII” or other form. Any alternate format must include the full Project Gutenberg™ License as specified in paragraph 1.E.1. 1.E.7. Do not charge a fee for access to, viewing, displaying, performing, copying or distributing any Project Gutenberg™ works unless you comply with paragraph 1.E.8 or 1.E.9. 1.E.8. You may charge a reasonable fee for copies of or providing access to or distributing Project Gutenberg™ electronic works provided that: • You pay a royalty fee of 20% of the gross profits you derive from the use of Project Gutenberg™ works calculated using the method you already use to calculate your applicable taxes. The fee is owed to the owner of the Project Gutenberg™ trademark, but he has agreed to donate royalties under this paragraph to the Project Gutenberg Literary Archive Foundation. Royalty
  • 42.
    payments must bepaid within 60 days following each date on which you prepare (or are legally required to prepare) your periodic tax returns. Royalty payments should be clearly marked as such and sent to the Project Gutenberg Literary Archive Foundation at the address specified in Section 4, “Information about donations to the Project Gutenberg Literary Archive Foundation.” • You provide a full refund of any money paid by a user who notifies you in writing (or by e-mail) within 30 days of receipt that s/he does not agree to the terms of the full Project Gutenberg™ License. You must require such a user to return or destroy all copies of the works possessed in a physical medium and discontinue all use of and all access to other copies of Project Gutenberg™ works. • You provide, in accordance with paragraph 1.F.3, a full refund of any money paid for a work or a replacement copy, if a defect in the electronic work is discovered and reported to you within 90 days of receipt of the work. • You comply with all other terms of this agreement for free distribution of Project Gutenberg™ works. 1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™ electronic work or group of works on different terms than are set forth in this agreement, you must obtain permission in writing from the Project Gutenberg Literary Archive Foundation, the manager of the Project Gutenberg™ trademark. Contact the Foundation as set forth in Section 3 below. 1.F. 1.F.1. Project Gutenberg volunteers and employees expend considerable effort to identify, do copyright research on, transcribe and proofread works not protected by U.S. copyright
  • 43.
    law in creatingthe Project Gutenberg™ collection. Despite these efforts, Project Gutenberg™ electronic works, and the medium on which they may be stored, may contain “Defects,” such as, but not limited to, incomplete, inaccurate or corrupt data, transcription errors, a copyright or other intellectual property infringement, a defective or damaged disk or other medium, a computer virus, or computer codes that damage or cannot be read by your equipment. 1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for the “Right of Replacement or Refund” described in paragraph 1.F.3, the Project Gutenberg Literary Archive Foundation, the owner of the Project Gutenberg™ trademark, and any other party distributing a Project Gutenberg™ electronic work under this agreement, disclaim all liability to you for damages, costs and expenses, including legal fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE. 1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you discover a defect in this electronic work within 90 days of receiving it, you can receive a refund of the money (if any) you paid for it by sending a written explanation to the person you received the work from. If you received the work on a physical medium, you must return the medium with your written explanation. The person or entity that provided you with the defective work may elect to provide a replacement copy in lieu of a refund. If you received the work electronically, the person or entity providing it to you may choose to give you a second opportunity to receive the work electronically in lieu of a refund.
  • 44.
    If the secondcopy is also defective, you may demand a refund in writing without further opportunities to fix the problem. 1.F.4. Except for the limited right of replacement or refund set forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PURPOSE. 1.F.5. Some states do not allow disclaimers of certain implied warranties or the exclusion or limitation of certain types of damages. If any disclaimer or limitation set forth in this agreement violates the law of the state applicable to this agreement, the agreement shall be interpreted to make the maximum disclaimer or limitation permitted by the applicable state law. The invalidity or unenforceability of any provision of this agreement shall not void the remaining provisions. 1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation, the trademark owner, any agent or employee of the Foundation, anyone providing copies of Project Gutenberg™ electronic works in accordance with this agreement, and any volunteers associated with the production, promotion and distribution of Project Gutenberg™ electronic works, harmless from all liability, costs and expenses, including legal fees, that arise directly or indirectly from any of the following which you do or cause to occur: (a) distribution of this or any Project Gutenberg™ work, (b) alteration, modification, or additions or deletions to any Project Gutenberg™ work, and (c) any Defect you cause. Section 2. Information about the Mission of Project Gutenberg™
  • 45.
    Project Gutenberg™ issynonymous with the free distribution of electronic works in formats readable by the widest variety of computers including obsolete, old, middle-aged and new computers. It exists because of the efforts of hundreds of volunteers and donations from people in all walks of life. Volunteers and financial support to provide volunteers with the assistance they need are critical to reaching Project Gutenberg™’s goals and ensuring that the Project Gutenberg™ collection will remain freely available for generations to come. In 2001, the Project Gutenberg Literary Archive Foundation was created to provide a secure and permanent future for Project Gutenberg™ and future generations. To learn more about the Project Gutenberg Literary Archive Foundation and how your efforts and donations can help, see Sections 3 and 4 and the Foundation information page at www.gutenberg.org. Section 3. Information about the Project Gutenberg Literary Archive Foundation The Project Gutenberg Literary Archive Foundation is a non- profit 501(c)(3) educational corporation organized under the laws of the state of Mississippi and granted tax exempt status by the Internal Revenue Service. The Foundation’s EIN or federal tax identification number is 64-6221541. Contributions to the Project Gutenberg Literary Archive Foundation are tax deductible to the full extent permitted by U.S. federal laws and your state’s laws. The Foundation’s business office is located at 809 North 1500 West, Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up to date contact information can be found at the Foundation’s website and official page at www.gutenberg.org/contact
  • 46.
    Section 4. Informationabout Donations to the Project Gutenberg Literary Archive Foundation Project Gutenberg™ depends upon and cannot survive without widespread public support and donations to carry out its mission of increasing the number of public domain and licensed works that can be freely distributed in machine-readable form accessible by the widest array of equipment including outdated equipment. Many small donations ($1 to $5,000) are particularly important to maintaining tax exempt status with the IRS. The Foundation is committed to complying with the laws regulating charities and charitable donations in all 50 states of the United States. Compliance requirements are not uniform and it takes a considerable effort, much paperwork and many fees to meet and keep up with these requirements. We do not solicit donations in locations where we have not received written confirmation of compliance. To SEND DONATIONS or determine the status of compliance for any particular state visit www.gutenberg.org/donate. While we cannot and do not solicit contributions from states where we have not met the solicitation requirements, we know of no prohibition against accepting unsolicited donations from donors in such states who approach us with offers to donate. International donations are gratefully accepted, but we cannot make any statements concerning tax treatment of donations received from outside the United States. U.S. laws alone swamp our small staff. Please check the Project Gutenberg web pages for current donation methods and addresses. Donations are accepted in a number of other ways including checks, online payments and
  • 47.
    credit card donations.To donate, please visit: www.gutenberg.org/donate. Section 5. General Information About Project Gutenberg™ electronic works Professor Michael S. Hart was the originator of the Project Gutenberg™ concept of a library of electronic works that could be freely shared with anyone. For forty years, he produced and distributed Project Gutenberg™ eBooks with only a loose network of volunteer support. Project Gutenberg™ eBooks are often created from several printed editions, all of which are confirmed as not protected by copyright in the U.S. unless a copyright notice is included. Thus, we do not necessarily keep eBooks in compliance with any particular paper edition. Most people start at our website which has the main PG search facility: www.gutenberg.org. This website includes information about Project Gutenberg™, including how to make donations to the Project Gutenberg Literary Archive Foundation, how to help produce our new eBooks, and how to subscribe to our email newsletter to hear about new eBooks.
  • 48.
    Welcome to ourwebsite – the perfect destination for book lovers and knowledge seekers. We believe that every book holds a new world, offering opportunities for learning, discovery, and personal growth. That’s why we are dedicated to bringing you a diverse collection of books, ranging from classic literature and specialized publications to self-development guides and children's books. More than just a book-buying platform, we strive to be a bridge connecting you with timeless cultural and intellectual values. With an elegant, user-friendly interface and a smart search system, you can quickly find the books that best suit your interests. Additionally, our special promotions and home delivery services help you save time and fully enjoy the joy of reading. Join us on a journey of knowledge exploration, passion nurturing, and personal growth every day! testbankfan.com