Alright basically I have an assignment due at 11:59 pm tonight and so I would appreciate all the help I can get. I have code that I wish for those to look over and see if its correct I also have a question about some of the questions and whether or not I interpreted them correctly. Also an example on how to do the last part of my assignment would be helpful.
Assignment:
1. Each instance of a Doodad has a color(String), a weight(int) and a boolean variable to indicate if it has been refurbished as private instance variables.
2. Use modifiers: setColor, setWeight, setRefurbished, and accessors: getColor, getWeight, getRefurbished.
3. There should be two constructors: one with the signature: (String, int, boolean); the other with no parameters which then uses the default values("red", 10, false)
4. Write a toString method that creates a string consisting of exactly the color on the first line, the weight on the second and the boolean on the third line(use no additional formatting or labeling). Each of the three lines ends with a newline character.
5.(example of something similar please) Include a public method named isHeavy which should return true if the Doodad has a weight greater than the weight passed to isHeavy as a parameter. If no parameter is passed, true is returned if the weight is greater than 12(use method overloading).
public class Doodad {
// Data Fields
/** The Color */
private String Color;
/** The Weight */
private int Weight;
/** The Refurbished */
private boolean Refurbished;
//Modifier Methods
/** Sets the Color field.
@param colors The Color
*/
public void setColor(String colors) {
Color = colors;
}
/** Sets the Weight field.
@param theweight The Weight
*/
public void setWeight(int theweight) {
Weight = theweight;
}
/** Sets the Refurbished field.
@param refurbish The Refurbished
*/
public void setRefurbished(boolean refurbish) {
Refurbished = refurbish;
}
// Accessor Methods
/** Gets the doodads color.
@return the color as a String
*/
public String getColor() {
return Color;
}
/** Gets the doodads weight.
@return the weight as a int
*/
public int getWeight() {
return Weight;
}
/** Gets the doodads refurbished.
@return the refurbished as a boolean
*/
public boolean getRefurbished() {
return Refurbished;
}
// Constructors
/** Construct a Doodad with given values
@param colors The Color
@param theweight The Weight
@param refurbish The Refurbished
*/
public Doodad(String colors, int theweight, boolean refurbish) {
Color = colors;
Weight = theweight;
Refurbished = refurbish;
}
/** Construct a doodad with nothing specefied.
@param No parameter
*/
public Doodad() {
}
/** Retrieves the information in a Person object.
@return the object state as a string
*/
public String toString() {
return "The Colors: " + Color + "\n"
+ "The weight: " + Weight + "\n"
+ "boolean: " + boolean + "\n";
}
public void isHeavy(){
So now my questions for the very first part of the assignment is the boolean suppose to be Refurbished or not? I'm confused about that.
Second question: third part of the assignment is the first construct suppose to look like this: (String colors, int theweight, boolean refurbish) or this: (String, int, boolean)
Third question: fourth part of the assignment is the toString suppose to look like this:
public String toString() {
return "The Colors: " + Color + "\n"
+ "The weight: " + Weight + "\n"
+ "boolean: " + boolean + "\n";
or like this:
public String toString() {
return "The Colors: " + Color + "\n"
+ "The weight: " + Weight + "\n"
+ "boolean: " + Refurbished + "\n";
Last question of course deals with the very last part of the assignment I'm basically confused, I get the feeling I'm suppose to use a boolean:
Like this:
public boolean equals(Doodad doo){
if (Doodad> theweight)
return true;
else
(Doodad>12)
return true;
I don't know.
Thanks for the help and answering my questions.