Differentiate class-level static vs. instance/object-level variables
Differentiate class-level static vs. instance/object behaviors/methods
Define instance variables (that you want to be interrelated)
Name
Data Type
private
Define class variables static as needed
Name
Data Type
public / private / final
Create constructor (behavior) that creates initial state of object
Overloaded constructor (with as many parameters)
public
Same name as class
No return type
Default - no parameters
Logic - initialize all variables
Repeat as needed, adding parameters
Create 1 accessor and 1 mutator behaviors per attribute
Accessors
Name is get_<attr_name>
Public
Return type same data type as attribute
No parameters
Logic - return value
Mutators
Name is set_<attr_name>
Public
Return type is void
Parameter is same data type as attribute
Logic validates input parameter and sets attribute value
Write toString method
public
Returns String
No parameters
Logic - convert needed attributes to a format that can be printed
Write equals method
public
Returns boolean
Parameter - instance of the class
Logic - compare attributes for equity
Create additional methods as needed
Subsection9.10.1
Consider the SongType class you began in an earlier exercise, as illustrated in the following UML diagram.
Figure9.10.1.
For questions 36 - 39, fill in the code blanks to implement the toString method to print the song in the following format: SONG by ARTIST (X.XX) where X.XX is the length in minutes.
public ___A___ toString () {
return ___B___ + " by " + ___C___ + "(" + ___D___ + ")";
ExercisesExercises
1.
Q36: Fill in Blank A.
String
int
double
void
return
2.
Q37: Fill in Blank B.
void
String
title
artist
length
3.
Q38: Fill in Blank C.
void
String
title
artist
length
4.
Q39: Fill in Blank D.
void
String
title
artist
length
For questions 40 - 45, fill in the code blanks to implement the equals method, where two songs are equal if
For questions 46 - 50, fill in the code blanks to implement a method called isLonger, which returns true if the song is longer than the song in the parameter.