Question: A point can be characterized by x and y coordinates. Define a class called MyPoint. Instance variables: x // should be private Y //should be

A point can be characterized by x and y coordinates. Define a class called MyPoint. Instance variables: x // should be private Y //should be public Class variable : noOfObjects //should be private //keeps track of the number of objects Three constructors: One with no arguments One with one argument (The argument will initialize the instance variable x) One with two arguments (The arguments will initialize the instance variables x and y) Use this keyword where necessary Setter method Define a setter method that assigns a value to the variable x Define a setter method that modifies the value of the static variable (A setter method is like a normal method that modifies private variables. It does not return anything) Getter method Define a getter method that retrieves the value of the instance variable x Define a getter method that retrieves the value of class variable noOfObjects (A getter method is like a normal method that retrieves private variables. It returns the value of the variable) Create a Driver class and inside its main method do the following: Ask the user for the values of both x and y Create three objects: The first object should use the constructor without any arguments The second object should use the constructor with one argument (pass in the user input) The Third object should use the constructor with two arguments (pass in user inputs) After the objects have been created For the first object use the setter method to assign a value to x. Also just assign y from main For the second object just assign y from main As each object is being created increment the static variable by one. Display the contents of each object along with the static variable. Use the getter methods where necessary.

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!