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

Add the following method to the Point class: public void flip() Negates and swap

ID: 3680310 • Letter: A

Question

Add the following method to the Point class:

public void flip()

Negates and swaps the x/y coordinates of the Point object. For example, if the object initially represents the point (5, -3), after a call to flip, the object should represent (3, -5). If the object initially represents the point (4, 17), after a call to flip, the object should represent (-17, -4).

Explanation / Answer

public class Point { private int x; private int y; // your code goes here /*logic: 1. First we will swap both values. 2. after that we will negate both values */ public void flip() { int temp; //swapping //this pointer is used to fetch values coresponding to current object temp=this->x; // third temp variable is used to swap two values this->x=this->y; this->y=temp; //negation this->x=-(this->x); this->y=-(this->y); } }

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