Question: 1. Explain the purpose of a constructor. _______________________________________________ _____________________________________________________________________________ 2. Name the first two fields in the Ball class and tell the data type of

1. Explain the purpose of a constructor. _______________________________________________ _____________________________________________________________________________ 2. Name the first two fields in the Ball class and tell the data type of each: ___________________ _____________________________________________________________________________ 3. Write the signature (opening line) of a constructor for a class named CreditCard. _____________________________________________________________________________ 4. The CreditCard class has a field for the owners name. Write a field declaration for storing that information. __________________________________________________________________ 5. Write the statement that would assign your name to the memory location declared above. _____________________________________________________________________________ 6. What was the name of the method in the Ball class that displayed information about the ball? _ _____________________________________________________________________________ 7. Write the Java command that would display the current owner of the credit card object - whomever it was at any time. (Writing the method is not necessary here just the display statement.) It might look like this with the blank filled with the current owners name: _____________________________________________________________________________ 8. Explain the difference between an accessor and a mutator method. Give an example of each from the Student class (lab-classes project). _________________________________________ _____________________________________________________________________________ _____________________________________________________________________________ _____________________________________________________________________________ The credit card belongs to ______________________. Methods including Constructors 02/08/21 Turn over as needed 9. Explain how you open the BlueJ Inspector and the type of information found. _____________________________________________________________________________ _____________________________________________________________________________ 10. What was the name of the accessor method we wrote after the material field was added to the Ball class? ____________________________________________________________________ 11. Explain what a parameter is and when we need to use one. ___________________________ _____________________________________________________________________________ _____________________________________________________________________________ 12. Give an example of a method in the Ball class that has a parameter? ______________________ ____________________________________________________________

code

/** * Write a description of class ball here. * * @author (your name) * @version (a version number or a date) */ public class ball { // instance variables - replace the example below with your own private String color; private int diameter;

/** * Constructor for objects of class ball */ public ball() { // initialise instance variables color = "red"; diameter = 10; }

/** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public String getColor(){ return color; } public int getDiameter(){ return diameter; } public void setYellowColor(){ color = "yellow"; } public void setOrangeColor(){ color = "orange"; } public void setBallColor(String setColor){ color = "setColor"; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!