Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Provide one additional instance method for this class (use parameters as needed)

ID: 3641577 • Letter: P

Question

Provide one additional instance method for this class (use parameters as needed) to achieve something interesting for your class
Modify the main function/client program from the previous program you wrote such that the main program also invokes(or tests) this new method you've added to your class.
Ensure that the method is being invoked correctly (perhaps by printing something within each or show that the method is having some change on the objects when they are invoked).
Extra Credit: Add another interesting instance method to your class, and test the method from the main function/client program

****MAIN CLASS****
public class main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {

// TODO code application logic

Motorcycle[] motorcycleArray = new Motorcycle[3];

// instantiate 3 objects of type Motoryclce

Motorcycle m1 = new Motorcycle("Honda", "CBR600RR",
"HDJSLE49920FJSKXX", "2010");

Motorcycle m2 = new Motorcycle("Suzuki", "GSXR750",
"JKSF3J9393FJKDL11", "2011");

Motorcycle m3 = new Motorcycle("Yamaha", "YZFR1",
"YZF33129FJKLLSEKH12", "2012");


// add to array

motorcycleArray[0] = m1;

motorcycleArray[1] = m2;

motorcycleArray[2] = m3;


System.out.println("------OPTION 1-------");

// print some data option 1

for(int i = 0; i < motorcycleArray.length; i++)
{
System.out.println("Motorcycle #" + i + " Make: " + motorcycleArray[i].Make +
" Model: " + motorcycleArray[i].Model + " VIN: " +
motorcycleArray[i].Vin + " Year: " + motorcycleArray[i].Year);
}


System.out.println("-----OPTION 2--------");

// option 2 **Extra Credit**

System.out.println(m1.toString());

System.out.println(m2.toString());

System.out.println(m3.toString());
}
}

****MOTORCYLE CLASS****

public Motorcycle()
{

}

/**
* Constructor with parameters (copy constructor)
* Called when creating a new Motorcycle object
* @param make
* @param model
* @param vin
* @param year
*/
public Motorcycle(String make, String model, String vin, String year)
{
this.Make = make;
this.Model = model;
this.Vin = vin;
this.Year = year;
}


/**
* Override method for toString
* *Extra Credit*
*/
@Override public String toString()
{
return "Make: " + Make + " Model: " + Model + " VIN: " + Vin + " Year: " + Year;
}
}

Explanation / Answer

I added getter and setter methods that I used throughout your program.

public class Motorcycle {

    private String Make;
    private String Model;
    private String Vin;
    private String Year;

    public Motorcycle() {
        this.Make = "No Make";
        this.Model = "No Model";
        this.Vin = "No Vin";
        this.Year = "No Year";
    }
    public Motorcycle(String make, String model, String vin, String year) {
        this.Make = make;
        this.Model = model;
        this.Vin = vin;
        this.Year = year;
    }

    /**
    * Override method for toString *Extra Credit*
    */
    @Override
    public String toString() {
        return "Make: " + getMake() + " Model: " + getModel() + " VIN: " + getVin()
                + " Year: " + getYear();
    }

    public String getMake() {
        return Make;
    }

    public void setMake(String make) {
        Make = make;
    }

    public String getModel() {
        return Model;
    }

    public void setModel(String model) {
        Model = model;
    }

    public String getVin() {
        return Vin;
    }

    public void setVin(String vin) {
        Vin = vin;
    }

    public String getYear() {
        return Year;
    }

    public void setYear(String year) {
        Year = year;
    }

}

// Main Class

public class MotorcycleTester {
    public static void main(String[] args) {

        // TODO code application logic

        Motorcycle[] motorcycleArray = new Motorcycle[6];

        // instantiate 3 objects of type Motoryclce

        Motorcycle m1 = new Motorcycle("Honda", "CBR600RR",
        "HDJSLE49920FJSKXX", "2010");

        Motorcycle m2 = new Motorcycle("Suzuki", "GSXR750",
        "JKSF3J9393FJKDL11", "2011");

        Motorcycle m3 = new Motorcycle("Yamaha", "YZFR1",
        "YZF33129FJKLLSEKH12", "2012");
       
        Motorcycle m4 = new Motorcycle();
       
        Motorcycle m5 = new Motorcycle();
       
        Motorcycle m6 = new Motorcycle();


        // add to array

        motorcycleArray[0] = m1;

        motorcycleArray[1] = m2;

        motorcycleArray[2] = m3;
       
        motorcycleArray[3] = m4;
       
        motorcycleArray[4] = m5;
       
        motorcycleArray[5] = m6;
       
       
        System.out.println("------ EXTRA -------");
       
        m4.setMake("Ford");
        m4.setModel("F150");
        m4.setVin("FFSAUEF");
        m4.setYear("2000");
       
        m5.setMake("Honda");
        m5.setModel("Accord");
        m5.setVin("HILIHE");
        m5.setYear("2011");
       


        System.out.println("------OPTION 1-------");

        // print some data option 1

        for(int i = 0; i < motorcycleArray.length; i++)
        {
        System.out.println("Motorcycle #" + i + " Make: " + motorcycleArray[i].getMake() +
        " Model: " + motorcycleArray[i].getModel() + " VIN: " +
        motorcycleArray[i].getVin() + " Year: " + motorcycleArray[i].getYear());
        }


        System.out.println("-----OPTION 2--------");

        // option 2 **Extra Credit**

        System.out.println(m1.toString());

        System.out.println(m2.toString());

        System.out.println(m3.toString());
       
        System.out.println(m4.toString());

        System.out.println(m5.toString());

        System.out.println(m6.toString());
        }
        }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote