Create a class Point that keeps track of an x coordinate and a y coordinate on the Cartesian plane, both of type
double. Provide getter and setter methods, and these methods:
findDistance() - an instance method that takes as input a
Point, computes and returns its distance from the current
Point using the Pythagorean formula
areEquidistant() - an instance predicate method that takes as input two
Point objects, and returns true if the difference in distance from the current Point to each of those inputs is within TOLERANCE. Define TOLERANCE as a final value of 0.01,
readPoint() - a static method that reads the x and y coordinates from the keyboard, and calls the constructor to create a new
Point instance, which is returned,
Point, whose coordinates are inputed by the user. Compute, and report if any of the three points is equidistant to the other two.
new Point(1.0, 2.0)) and use these objects to implement and test the rest of the methods. Once you are done, the readPoint method will be easier to implement and test. Doing otherwise you will find that testing is very time-consuming because you need to do through the keyboard input every time you test.
Implement a class called Flight to represents an airline flight. Include instance data to represent the name of the airline, the flight number, and the flight origin and destination cities. Provide getter and setter methods, and these methods:
Flight constructor - define a constructor that takes as input the information to initialize the instance data,
readFlight() - a static method that takes as input a
Scanner and outputs a
Flight object specified by the user,
stopOver() - a static predicate method that takes as input two
Flight objects and returns true if the first
Flight object's destination matches the second
Flight object's origin,
The aims of this problem are
For this task, your solution must involve recursion. You may create own private helper methods as necessary.
Define a new class named
StringOps and include definitions of the following methods:
public static String removeChar(String s, char ch)- returns a new string that is constructed from the input string s, with the first occurrence of the character ch removed. If the character ch is not contained in the input string S, then this method returns the original string.
removeChar("java", 'a')returns the string "jva", and the method call
removeChar("java", 'q')returns "java"
public static void testAnagrams (String word1, String word2)- determines whether the two input strings word1 and word2 are anagrams and prints the outcome to the user. An anagram is defined as two words that have exactly the same letters, but in a different order
testAnagrams("melon", "lemon");might result in the following printout: "melon and lemon are anagrams", while the method call
testAnagrams("hello", "world");might result in: "hello and world are not anagrams"
main()- contains code to test all of your methods