Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

More Books

Students also viewed these Databases questions