Access over 20 million homework & study documents

Additions to the Automobile ClassInstance variable String colorO

Content type
User Generated
Rating
Showing Page:
1/10
Additions to the Automobile Class
Instance variable : String colorOfAuto - represents the
color of the Automobile
Modify the constructors to include setting the new
colorOfAuto instance variable.
Add accessor and mutator method for the colorOfAuto
instance variable.
New Methods
String toString() method - returns a String that represents
the instance variables of the Automobile class in a
sentence. Use the accessor method to get the instance
variables. An example of the String might be \"The Red
Chevrolet Camaro costs $54982.62\"
boolean equals( Automobile otherAuto) - that compares the
two Automobile object based on make, model and color
and returns true if all those instance variables are the
same and false if any are different.
Overloaded void setColor(int colorCode)
an overloaded setColor mutator method that converts
parameter colorCode to a String representing the a color
and assigns that String to the instance variable
colorOfAuto.
The conversion of colorCode to color is: 1 - Red, 2 - Blue,
3 - White, 4 - Black. If the colorCode is not 1 - 4, print an
error message stating that the color code is invalid.
Add to the AutomobileTest.java as follows:
Modify the parameterized constructor call to include color.
Use the mutator method, to pass a String representing the
color, to set the color for the automobile object that was
created using the default constructor.
Test the equals method. in testing this method, use an if
statement where the condition is the call to the equals
method.
Test the setColor method by changing the color of an
Automobile object.

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/10
Call the toString method as needed to show your tests
worked, for example after you call change the color using
one of the mutator methods call the toString to show that
the color has changed.
previous code
public class Automobile
{
public static void main(String[] args)
{
Automobile defaultAuto=new Automobile();
Automobile parameterAuto=new Automobile(\"Ford\",
\"Focus\",22999.00);
defaultAuto.setMake(\"Toyota\");
defaultAuto.setModel(\"F250\");
defaultAuto.setPrice(24894.84);
System.out.println(\"The \"+defaultAuto.getMake()+\" \"
+defaultAuto.getModel()
+\" costs $\"+defaultAuto.getPrice());
System.out.println(\"The \"+parameterAuto.getMake()+\" \"
+parameterAuto.getModel()
+\" costs $\"+parameterAuto.getPrice());
}
private String make;
private String model;
private double price;
public Automobile()
{
make=\"\";
model=\"\";
price=0;
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/10

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 10 pages?
Access Now
Unformatted Attachment Preview
Additions to the Automobile Class Instance variable : String colorOfAuto - represents the color of the Automobile Modify the constructors to include setting the new colorOfAuto instance variable. Add accessor and mutator method for the colorOfAuto instance variable. New Methods String toString() method - returns a String that represents the instance variables of the Automobile class in a sentence. Use the accessor method to get the instance variables. An example of the String might be \"The Red Chevrolet Camaro costs $54982.62 \" boolean equals( Automobile otherAuto) - that compares the two Automobile object based on make, model and color and returns true if all those instance variables are the same and false if any are different. Overloaded void setColor(int colorCode) an overloaded setColor mutator method that converts parameter colorCode to a String representing the a color and assigns that String to the instance variable colorOfAuto. The conversion of colorCode to color is: 1 - Red, 2 - Blue, 3 - White, 4 - Black. If the colorCode is not 1 - 4, print an error message stating that the color code is invalid. Add to the AutomobileTest.java as follows: Modify the parameterized constructor call to include color. Use the mutator method, to pas s a String representing the color, to set the color for the automobile object that was created using the default constructor. Test the equals method. in testing this method, use an if statement where the condition is the call to the equal ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Great! 10/10 would recommend using Studypool to help you study.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4