Instructions: Answer the following questions one at a time. After answering each question, check your answer (by clicking on the check-mark icon if it is available) before proceeding to the next question.
Getting Ready: Before going any further, you should:
.java Files: In most IDEs, .java files
(i.e., source files) can just be copied into the project.
.class and .jar Files:
In some IDEs it is easier to use .class
files and in others it is easier to use a .jar file
that contains the .class files. Hence, you have been
provided with both.
See the course "Help" page on your IDE for more information.
Resources: In some IDEs, resources (e.g., images, data files) need to be in a special directory whereas in others they need to be in the working directory. See the course "Help" page on your IDE for more information.
TwoPartNumber.java.
TwoPartNumber.java to ensure that it has no
syntax errors.
abstract modifier from the declaration of
the TwoPartNumber class.
TwoPartNumber class.
abstract modifier from the declaration of
the initializeUnits method.
TwoPartNumber class.
abstract modifier in the declaration of the
initializeUnits() method.
TwoPartNumber class.
initializeUnits method.
TwoPartNumber class.
initializeUnits method.
TwoPartNumber class.
initializeUnits() and the initializeUnits()
method is not implemented?
initializeUnits() will be executed if there are
no concrete derived classes?
Driver0.java.
Driver0.java.
number variable
generate a compile-time error message?
smallsPerLarge) in the
TwoPartNumber class declared to be final?
smallsPerLarge) in the
TwoPartNumber class declared to be static?
Length.java.
Driver1.java.
Driver1.
initializeUnits() in the Length class.
Length class.
initializeUnits() in the Length class.
Weight class (containing pounds and ounces)
that extends the TwoPartNumber class.
Length
and Weight classes extend
the TwoPartNumber class?
Weight class, you
found a fault in the changeBy() method. Assuming the
current implementation, would you have to correct the fault in
both the Weight class and the Length class?
Weight
class to create a Length, you found a fault in
the changeBy() method. Would you have to correct the
fault in both the Weight class and
the Length class?
Driver2.java.
Driver2 class.
myLength.changeBy(myWeight) generate a compile-time
error message?
Driver2.
changeBy() method in
the TwoPartNumber class visible/accessible only to
derived classes that understand this issue. What change did you
make?
changeBy()
method to the Length class. Of course, it shouldn't
duplicate code in the base class. What code did you add?
changeBy()
method to the Weight. What code did you add?
Driver2.java. Why isn't an error generated?
LengthDatabase.java and
DatabaseDriver1.java.
DatabaseDriver1.
DatabaseDriver2.java that creates
and stores Weight objects
(rather than Length objects) in the
LengthDatabase.
DatabaseDriver2.
TwoPartNumberDatabase.java.
TwoPartNumberDatabase
class and the LengthDatabase class?
TwoPartNumberDatabase class
(as compared to the LengthDatabase class)?
TwoPartNumberDatabase class
(as compared to the LengthDatabase class)?
DatabaseDriver1 and
DatabaseDriver2 so that the database they
use is a TwoPartNumberDatabase. Make sure you change
both the declaration and the instantiation.
DatabaseDriver1.
DatabaseDriver2 by typecasting the value returned by
database.get(name) to the appropriate type.
DatabaseDriver2 by declaring result
and length to be TwoPartNumber objects.
LengthDatabase class
(with an appropriate comment).
public Length total()
{
Length result;
result = new Length();
for (int i=0; i<nextIndex; i++)
{
result.changeBy(values[i]);
}
return result;
}
TwoPartNumberDatabase
class. What makes it impossible?
TwoPartNumber database class and add type safety?
TwoPartNumberDatabase
class.
/**
* Get the total TwoPartNumber of all objects in this
* TwoPartNumberDatabase.
*
* @return The total
*/
protected TwoPartNumber totalValue()
{
TwoPartNumber result;
result = createElement();
for (int i=0; i<nextIndex; i++)
{
result.changeBy(values[i]);
}
return result;
}
createElement() method?
TwoPartNumber
that can be constructed?
createElement() method
in the TwoPartNumber class construct
an object that it is a specialization of TwoPartNumber?
TwoPartNumber class can't implement
the createElement() method but it's specializations
can. So, what should be true of the createElement()
method in the TwoPartNumber class.
TwoPartNumberDatabase class abstract.
What code did you add?
WeightDatabase class (just to be different)
that extends the TwoPartNumberDatabase class and
provides all of the desired functionality (including
the public Weight total() method) in a type-safe way.
What code is in this class?
TwoPartNumber?
Copyright 2021