Question: An orthogonal vector is defined by two real values a, b and written in the form ai+bj. We define equality for two vectors v1=ai+bj and

An orthogonal vector is defined by two real values a, b and written in the form ai+bj. We define equality for two vectors v1=ai+bj and v2=ci+dj as follows:
(v1 == v2) if and only if (a = c) and (b = d)
Given is a class Vector that encapsulates an orthogonal vector. Your task is to write an immutable version of this class and implement the following methods: toString that returns a string representation of the vector; equals that returns true if this equals that, false otherwise; compareTo that implements the Comparable interface and hashCode. The comparison, for compareTo, is based on a comparison of the coefficients of i, and if equal, on the coefficients of j.
class Vector implements Comparable{
private double a,b;
Vector(double a0, double b0){
a = a0; b = b0;
}
}
Write a separate class and test code.
Be sure to test the code to make sure it works correctly.

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!