Question
Question 6) A Golomb ruler is a collection of integers such that no two pairs of values are the same distance apart. Eg: If the
Question 6)
A Golomb ruler is a collection of integers such that no two pairs of values are the same distance apart. Eg: If the current ruler is {1, 2, 4}, then either 7 or 9 could be added to the ruler but not both.
(Since 7 2 = 5 and 9 4 = 5). You might want to use Math.abs(n) to compute the absolute value of n and the sort(null) method on List to sort a list.
public class Ruler {
/** * Creates a ruler containing no values */ public Ruler();
/** * @return The values of in the ruler (in increasing order), comma separated. * This method should not rearrange/reorder any internal data. */ public String toString();
/** * @return true if x could be added to the ruler without breaking the invariant, * false otherwise */ public boolean isLegal(int x);
/** * Add x to the ruler if doing so wouldnt break the invariant, do nothing otherwise. */ public void add(int x); }
A) Which Javadoc tag should be used on add(int x) to describe the invariant?
B) Declare the member variables you think are necessary.
C) Implement toString() for this class.
D) Implement isLegal() for this class.
E) Implement add(int x) for this class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started