Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Answer the following for the XYCoord class given below. (20 pts.) (a) Give a statement to create a new XYCoord object, coord1, initialized to its

Answer the following for the XYCoord class given below. (20 pts.)

(a) Give a statement to create a new XYCoord object, coord1, initialized to its default value. (1pt)

(b) Give a statement to create a new XYCoord object, coord2, to the value (20,40). (1 pt.)

(c) Add a copy constructor to the XYCoord class below where indicated. (1 pts.)

(d) Create a new XYCoord object named coord4 that has the same value as an XYCoord object named coord3. (2 pts)

(e) Add getter and setter methods to the XYCoord class below where indicated. (4 pts.)

(f) Complete the toString and equals methods in the XYCoord class where indicated. (4 pts.)

(g) Complete a method named scale to the XYCoord class where indicated that allows a scaling factor to be given, and returns a new XYCoord object with both the x and y values multiplied by the provided scaling factor. (3 pts.)

(h) Give a section of code that, for objects xcoord1 and xcoord2, displays are equal if they are equal, and not equal otherwise. (2 pts.)

(i) Give the code to display the following, (2 pts.)

The value of coord1 is (x, y) - for the x and y values of object coord1

public class XYCoord

{

private int x;

private int y;

public XYCoord()

{

x = 0;

y = 0;

}

public XYCoord(int a, int b)

{

x = a;

y = b;

}

// add a copy constructor (set to value of another XYCoord object)

// add getters/setters (accessors/mutators)

// complete to return a string of the form (x, y)

public String toString()

{

}

//complete

public boolean equals( ):

{

}

//complete scale method

ALREADY HAVE QUESTION NUMBER ONE COMPLETED

2. Create a subclass of the XYCoord class from question 1, called ColorXYCoord, that stores a color value (as a string, e.g., red). INCLUDE ONLY (a) the needed instances variables, (b) a constructor that takes as parameters x and y values and a color (as a String), and (c) an appropriate toString method that returns a the value of an XYCoord object in the form "(10, 20) red". (10 pts.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions