Question: 2 program are submitted below :: In JAVA: Override the toString() method and equals() method inside your class you created from Assignment 5. [2 points]

2 program are submitted below ::

In JAVA:

Override the toString() method and equals() method inside your class you created from Assignment 5. [2 points]

Create a Copy Constructor in your class from Assignment 5. [1 point]

Create a static field in your class called counter. It should increment everytime an object is created. [1 point]

Create a static method that displays the counter value. Also call this method at the end of your main method. [1 point]

Use the "this" reference in all your setter (mutator) methods and also use the "this" reference in your default constructor to call the parameterized constructor. [1 point]

Demonstrate that the copy Constructor, toString, and equals methods work in your main method [1 point]

mustang.java

public class mustang { //Declaring instance variables private String make; private String model; private double price; //Zero argumented constructor public mustang() { } //Parameterized constructor public mustang(String make, String model, double price) { super(); this.make = make; this.model = model; this.price = price; } //getters and setters public String getMake() { return make; } public void setMake(String make) { this.make = make; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } //This method is used to display the contents of an object inside it public void display() { System.out.println("Mustang Make :" + make); System.out.println("Mustang Model :" + model); System.out.println("Price :$" + price); }

}

demo.java

public class Demo {

public void display (){ //Creating a mustang class using default constructor mustang m = new mustang(); //Calling the setter methods m.setMake("Ford"); m.setModel("GT"); m.setPrice(50000);

//calling the display method on the mustang class m.display();

//Creating a mustang class using default constructor mustang m1 = new mustang("Ford", "GT", 50000);

//calling the display method on the mustang class m1.display();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!