public static double slope(Line2D.Double line) // precondition: line not verticalAdd the methods to a class Geometry. The intersection method should compute the intersection of the lines that are obtained by extending the segments line1, line2 indefinitely. Return null if the lines are parallel. Why does it make sense to use static methods in this case? (Add a comment in Geometry.java)
public static double yIntercept(Line2D.Double line) // precondition: line not vertical public static boolean isVertical(Line2D.Double line) public static boolean areParallel(Line2D.Double line1, Line2D.Double line2)
public static Point2D.Double intersection(Line2D.Double line1, Line2D.Double line2)
public class BarCode
{
/**
* Constructs a bar code from a 5-digit zip code
* @param zipCode the zip code
* (Precondition: zipCode is between 0 and 99999)
*/
public BarCode(int zipCode) { . . . }
/**
* Constructs a bar code from a pattern of | and : bars
* @param bars a string of bars
* (Precondition: bars is a valid barcode)
* (Note: There are no blank spaces in the string)
*/
public BarCode(String bars) { . . . }
/**
* Gets the bar pattern for this bar code.
* @return the pattern of | and : bars for this bar code.
* (Note: There are no blank spaces in the string)
*/
public String getBars() { . . . }
/**
* Gets the zip code for this bar code.
* @return the zip code for this bar code
*/
public int getZipCode() { . . . }
}Use these static methods and fields: /**
* Returns the bars for a given digit
* @param digit (Precondition: 0 <= digit <= 9)
* @return the bar pattern
*/
private static String getBarsForDigit(int digit)
{
assert 0 <= digit && digit <= 9;
return barValues[digit];
}
/**
* Returns the digit for a given bar pattern
* @param bars the bar pattern
* @return the digit for the pattern, or -1 if
* no pattern matches.
*/
private static int getDigitForBars(String bars)
{
for (int i = 0; i < barValues.length; i++)
if (barValues[i].equals(bars))
return i;
return -1;
}
private static String[] barValues =
{
"||:::",
":::||",
"::|:|",
"::||:",
":|::|",
":|:|:",
":||::",
"|:::|",
"|::|:",
"|:|::"
};
private static final String START = "|";
private static final String END = "|";
private static final int DIGITS = 5;
private static final int BAR_LENGTH = 5;
Use assertions to verify all preconditions.Submit a zip file hw8_xyzw with the files