Java Reference
In-Depth Information
3. The UML diagram below shows the relationship between four classes. Implement
the classes in a test program that creates instances of
CreditCard
,
Cash
, and
Check
. Output the string description of each. Note that the italicized
Payment
class indicates that this is an abstract class. The word “in” means the parameter is
used to deliver data to the method.
Payment
#amount:
double
+Payment(in amount
double
)
+toString( ) :String
Cash
+Cash(in amount
double
)
Check
CreditCard
-RoutingNumber: String
-Name: String
-Expiration: String
-Name: String
-Number: String
+Check(in
double
amount, in String number, in String name)
+getNumber( ): String
+setNumber(in String newNumber)
+getName( ): String
+setName(in String newName)
+CreditCardin(in
double
amount, in String name, in String number, in String expiration)
+getNumber( ): String
+setNumber(in String newNumber)
+getExpiration( ): String)
+setExpiration (in String newExpiration)
+getName( ): String
+setName(in String newName)
4. Use the Model-View-Controller pattern to implement a simple timer-based coun-
ter. The counter should start at a user-specified initial value and increment by one
every second until it reaches a user-specified final value. A UML diagram depicting
the three classes for the pattern is shown below. The word “in” means the param-
eter is used to deliver data to the method.
CounterModel
-counter
+CounterModel(in initialValue
int
)
+Increment( ):
void
CounterView
CounterController
+Display(in
int
counterValue)
-startValue
-endValue
+CounterController(in
int
startValue, in
int
endValue)
+Start( )