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

Please complete the entire assignment :) The class CAR has the following data an

ID: 649913 • Letter: P

Question

Please complete the entire assignment :)

The class CAR has the following data and methods listed below: . Data fields: A String model that stores the car model, and an int year that stores the year the car was built. . Default constructor . Overloaded constructor that passes values for both data fields. . Method getModel that returns the cars model. . Method getYear that returns the year the car was built. . Method setModel that re-sets the value of the car model. . Method satYear that re-sets the year. . Method compare that passes an object of the Car class and returns true if the calling object is equal to the parameter object, and false otherwise. . Method print that prints both the model and the year (any format). And here?s the UML for the object The CAR class implementation has been written for you as well as the structure for the calling program CARDEMO. You will complete the exercise by writing the Java statements fo each of the commented sections. You should be able lo run the program after compiling. . Create an object of the class Car named Ferrari. . Use the print method to print all information about the Ferrari object. . Create an object of the class Car named cobra, passing parameters Cobra and 1967. . Print information about the Cobra object using get methods. . Change the model of the cobra object to Shelby Cobra. . Change the year of the cobra object to 1963. . Use the print method to print Out information about the cobra. . Use an if/else statement and the method compare to compare the ferrari obj with the cobra obj. Output Same if they are the same, or Different if they are different.

Explanation / Answer

import java.util.Arrays;
import java.util.Scanner;
public class Car{
    String model;
    int year;
   Car()
   {
       model="";
        year=0;
   }
    Car(String m,int y)
    {
        model=m;
        year=y;
    }
    String getModel()
    {
        return model;
    }
    int getYear()
    {
        return year;
    }
    void setModel(String m)
    {
        model=m;
    }
    void setYear(int y)
    {
        year=y;
    }
    boolean compare(Car temp)
    {
        if(temp.model==model && temp.year==year)
            return true;
        else
            return false;
    }
    void print()
    {
        System.out.print("Model: ");
        System.out.print(model);
        System.out.print(" year: ");
        System.out.println(year);
    }
    public static void main(String[] args)
    {
        Car ferrari = new Car();
        ferrari.print();
        Car cobra = new Car("Cobra",1967);
        System.out.print("Model: ");
        System.out.print(cobra.getModel());
        System.out.print(" year: ");
        System.out.println(cobra.getYear());
        cobra.setModel("Shelby Cobra");
        cobra.setYear(1963);
        cobra.print();
        if(cobra.compare(ferrari))
            System.out.println("Same");
        else
            System.out.println("Different");
    }
}

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