QuestionQuestion

Write a client program(test class) to THOROUGHLY test the class Vehicle. In the client program, create two Vehicle objects. Assign any values to the two objects. Exercise the methods to verify their functionality.

Approach to Testing:

Two separate files:
-Vehicle.java
-VehicleTest.java (client program) ( or other name )

Approach to Testing:
-Create an object with the default constructor
    -Verify the disclaimer is displayed.
          -Create a second object with the default constructor
          -Verify the disclaimer is not displayed a second time.
    -Verify and print to insure default values were assigned.
          -Use the 'get' methods coupled with output statements.
    -Initialize all of the instance variables using the 'set' methods.
    -Verify and print the values of the instance variables using the "toString' method or print using the 'get' methods.
    -Create an object with the overloaded constructor.
          -Verify and print the values of the instance variables using the "toString' method.
    -Create an object using the 'copy' constructor.
          -Compare the 'new' vehicle to the 'original' using the equals method.
    -Verify each of the other methods -
          -Equals method - needs three objects, 2 equal, 2 unequal
          -Compare equals
          -Compare unequal's "toString' method
          -Finalize method.
          -Others.

Problem. Implement Practice Problem 5, page 465 in the text. Include instance variables for the make, model, year, color, and speed. Also include a constructor, the accessors, mutators and methods toString', "equals', and "finalize' You will also implement the `copy' constructor Write a client class to test the behavior of the class and ALL of its methods.

The outline of the class is given as follows:

public class Vehicle {
private String make;
private String model;
private int year;
private String color;
private int speed;
public Vehicle ( ) { }
public Vehicle (String mak, String mod, int yr, String clr, int spd
)
{ }
public Vehicle ( Vehicle original ) { } 11 Follow the Person example
public String getMake ( ) {
}
public void setMake ( String mak ) (
}
public String getModel
public void setModel ( String mod ) {
}
public void setYear ( int yr ) { }
public int getYear ( ) {
}
public void setColor ( String clr )
(
}
public String getColor ( ) (
}
public void setSpeed ( int spd ) (
)
public int getSpeed ( ) ( )
public String toString ( ) ( }
public boolean equals ( Object obj ) { ) 11 Follow `Person' example
public void finalize ( ) (
}
}

ALL METHODS MUST BE IMPLEMENTED!!!

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/**
*
* @author
*/
public class Vehicle {

    private String make;
    private String model;
    private int year;
    private String color;
    private int speed;

    /**
    * constructor
    */
    public Vehicle() {
       make = "";
       model = "";
       year = 0;
       color = "";
       speed = 0;
    }

    /**
    * constructor
    * @param mak
    * @param mod
    * @param yr
    * @param clr
    * @param spd
    */
    public Vehicle(String mak, String mod, int yr, String clr, int spd) {
       make = mak;
       model = mod;
       year = yr;
       color = clr;
       speed = spd;
    }

   /**
    * constructor
    * @param original
    */
    public Vehicle(Vehicle original) {
       make = original.make;
       model = original.model;
       year = original.year;
       color = original.color;
       speed = original.speed;
    }

    /**
    * accessor
    * @return
    */
    public String getMake() {
       return make;
    }

    /**
    * mutator
    * @param mak
    */
    public void setMake(String mak) {
       make = mak;
    }

    /**
    * accessor
    * @return
    */
    public String getModel() {
       return model;
    }

    /**
    * mutator
    * @param mod
    */
    public void setModel(String mod) {
       model = mod;
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats