- Define and provide an example for each of the following terms to someone else:
- Mutator method
- Accessor method
- Private helper method
- Constructor
- No argument constructor
- Think of three real world objects. Identify what the instance data would be and what would the accessor and mutator methods would be for each one.
- Write a simple Java program with a simple class that has the following:
- 1+ accessor methods
- 1+ mutator methods
- 1+ instance data
Have the program create at least 2 instances of the class.
- Locate the following terms in your code and tell someone else what they do:
- Reference variable
- Object
- Member access operator
- Write down the line numbers in the order that they're executed in the following code:
public class ArgumentParameterExample{
public static void paramTest( int num, String msg ){
num = 42;
msg = "All your base are belong to us";
}
public static void main(String[] args){
int value = 1;
String str = "hello, world";
paramTest( value, str );
System.out.println( value );
System.out.println( str );
}
}
- Discuss with someone else the difference between an argument and a parameter.
- The volume of a cube is defined as its width * height * length. Write the SimpleCube class to match up with the methods called in main(). Have toString() display the following:
A WIDTH by HEIGHT by LENGTH cube has a volume of VOLUME
where WIDTH, HEIGHT, and LENGTH are replaced by the values of instance data members and VOLUME is calculated as WIDTH * HEIGHT * LENGTH.
Simple class to practice writing methods with multiple parameters
@author
@version
public class CubeDriver{
public static void main( String[] args ){
SimpleCube box = new SimpleCube();
int x = 3;
int y = 4;
box.setWidth( x );
box.setHeight( y );
box.setLength( 5 );
int volume = box.getVolume();
System.out.println( volume );
System.out.println( box.toString() );
}
}
- For each of the following pairs of methods, determine which ones are valid and why or why not:
-
public void printDetails( int length ){
...
}
public void printDetails( int width ){
...
}
-
public double incrementByValue( int increase ){
...
}
public double incrementByValue( double increase ){
...
}
-
public int getCost( int fee ){
...
}
public double getCost( int fee ){
...
}
-
public double updateInvoice( double fees, double taxes, double shipping ){
...
}
public double updateInvoice( double shipping, double fees, double taxes ){
...
}
- Given the following method declaration, write an overloaded method:
public boolean withdraw( double amount, double fee ){
...
}