Concept explainers
(Geometry: Graham’s
/** Return the points that form a convex hull */
public static ArrayList<MyPoint> getConvexHull (double[][] s)
MyPoint is a static inner class defined as follows:
private static class MyPoint implements Comparable<MyPoint> {
double x, y;
MyPoint rightMostLowestPoint;
MyPoint (double x, double y) {
this.x = x; this.y = y;
}
public void setRightMostLowestPoint(MyPoint p) {
rightMostLowestPoint = p;
}
@Override
public int compareTo(MyPoint o) {
// Implement it to compare this point with point o
// angularly along the x-axis with rightMostLowestPoint
// as the center, as shown in Figure 22.10b. By implementing
// the Comparable interface, you can use the Array.sort
// method to sort the points to simplify coding.
}
}
Write a test program that prompts the user to enter the set size and the points, and displays the points that form a convex hull, Here is a sample run:
How many points are in the set? 6
Enter six points: 1 2.4 2.5 2 1.5 34.5 5.5 6 6 2.4 5.5 9
The convex hull is
(1.5, 34.5) (5.5, 9.0) (6.0, 2.4) (2.5, 2.0) (1.0, 2.4)
Want to see the full answer?
Check out a sample textbook solutionChapter 22 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Python (4th Edition)
Problem Solving with C++ (9th Edition)
Software Engineering (10th Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with Java: Early Objects (6th Edition)
- mergeAndRemove(int[], int[]) This is a public static function that takes a int[] and int[] for the parameters and returns an int[]. Given two arrays of integers. Your job is to combine them into a single array and remove any duplicates, finally return the merged array.arrow_forwardWrite method body of followingfunction: void deleteRange(int from, int to){ } Above function deletes whole range of elements from an array by asking user for starting value and ending value. (Dont use pointers) Write best solution for worst case scenario.arrow_forwardCan someone help me with this? code: public class PigLatinator {/*** Takes a character array and arranges the characters into it's pig-latin form** The rules for pig-latin are as follows:* 1. If a word starts with a consonant, search through the word beginning at index 0 for the first * instance of a vowel. Split the array at this vowel, moving the consonants to the back of the array, * following a '-'. The add 'ay' at the end of the word.* 2. If a word starts with a vowel add the word "yay" at the end of the word following a '-'.* 3. If a word contains no vowels, just add "ay" at the end of the word following a '-'.* 4. If input is null, return null.* * Hint: Use your isVowel method to cut down on repetitive code* NOTE: Do not use string methods to rearrange your arrays; you should use the indexes** Example: char[] input = {'h', 'e', 'l', 'l', 'o'} gives* char[] output = {'e', 'l', 'l', 'o', '-', 'h', 'a', 'y'}* char[] input = {'f', 'l', 'a', 'r', 'e'} gives* char[] output = {'a',…arrow_forward
- Solve by Jova II.12 (Sum ArrayList) Write the following method that returns the sum of all num- bers in an ArrayList: public static double sum(ArrayList list) Write a test program that prompts the user to enter five numbers, stores them in an array list, and displays their sum.arrow_forwardبلغة جافا (java)arrow_forwardsove by Java I1.7 (Shuffle ArrayList) Write the following method that shuffles the elements in an ArrayList of integers: public static void shuffle(ArrayList list)arrow_forward
- void mystery2(int list[], int length) { for (int i = 0; i < length - 1; i++) { if (i % 2 == 0) { list[i]++; } else { list[i]--; } }} For each array below, indicate what the array's contents would be after the function were called and passed that array as its parameter. use the following as input. {6, 3} {2, 4, 6} {1, 2, 3, 4} {2, 2, 2, 2, 2} {7, 3, 2, 0, 5, 1}arrow_forwardDon't use vector array .using ifstream and ofstream. C++ programarrow_forwardHi, You are the Best :)arrow_forward
- (See attached photo) Please explain the exact running time of the program. The attached photo's answer is already correct only the explanation of getting the exact running time is needed.arrow_forwardJava question: A program that simulates a Bingo game declares an array of BingoCard. BingoCard[] players = new BingoCard[10]; //assuming no error occurs Why does a for-loop correctly constructs each BingoCard, whereas a for-each loop does not? for (BingoCard card : players) card = new BingoCard(); //I am thinking: "for each element of players, instantiate a new BingoCard object" for (int i=0;i<players.length;i++) players[i] = new BingoCard(); //I think for-loop also does the same thing.arrow_forward1-Write a JAVA program to delete duplicate elements from array. How to removeduplicate elements from array in JAVA programming. After performing delete operationthe array should only contain unique integer value. Logic to delete duplicate elementsfrom array.ExampleInputInput array elements: 10, 20, 10, 1, 100, 10, 2, 1, 5, 10OutputAfter removing all duplicate elementsElements of array are: 10, 20, 1, 100, 2, 5arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education