Concept explainers
Given program:
import java.util.ArrayList;
import java.util.Collections;
//Declare PointDemo class
public class PointDemo
{
public static void main(String[] args)
{
//Define variables
Point p1 = new Point(2, 8);
Point p2 = new Point(7, 2);
Point p3 = new Point(3, 4);
Point p4 = new Point(1, 4);
//Declare variable points
ArrayList points = new ArrayList();
points.add(p1);
points.add(p2);
points.add(p3);
points.add(p4);
//Print the statement
System.out.println("Points in the list before sorting: " + points);
Collections.sort(points);
System.out.println("Points in the list after sorting: " + points);
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
EBK BUILDING JAVA PROGRAMS
- Give edgeTo after B is visited. Format your answer as {A:?, B:?, C:?, D:?, E:?, F:?, G:?, S:-}.((Hint: the first step of the algorithm is to visit S, which should change the entries for A and B in edgeTo and distTo. The second step is to visit B, which should change the entries for C and E))Give distTo after B is visited. Format your answer as {A:?, B:?, C:?, D:?, E:?, F:?, G:?, S:0}.Give edgeTo after Djiksta's is finished. Format your answer as {A:?, B:?, C:?, D:?, E:?, F:?, G:?, S:-}.Give distTo after Dijkstra's is finished. Format your answer as {A:?, B:?, C:?, D:?, E:?, F:?, G:?, S:0}.arrow_forwardWhich best describes this axiom: ( aList ( ) ) . replace ( i, item ) ) . getEntry ( i ) = item When an item is replaced, it always goes in the position specified in the method call When an item is replaced, space is made by moving all of the items starting at the position specified down toward the bottom of the list by one to make room When an item is replaced, it always goes in the first available unused position None of thesearrow_forwardIterating over a collection of items is the job of the for construct's looping mechanism. So long as there are things to process, it will keep running forever. So, what do you make of this?arrow_forward
- Please Solve Part B onlyarrow_forwardReimplement the TrafficLight class using a simple counter that is advanced in each call to next. If the traffic light was initially green, the counter has values 0 1 2 3 4 5 6 ... . If the traffic light was initially red, the counter has values 2 3 4 5 6 7 8 ... . Compute the current color and the number of reds, using integer division and remainder.arrow_forwardJAva Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is locatedat a point with integer coordinates and faces north, south, east, or west. Supply methods:public void turnLeft()public void turnRight()public void move()public Point getLocation()public String getDirection()The turnLeft and turnRight methods change the direction but not the location. The move method movesthe robot by one unit in the direction it is facing. The getDirection method returns a string “N”, “S”,“E”, “W”. For the new object, the initial location and facing should be specified. For the initial facing, 0means north, 1 means east, 2 means south, and 3 means west.A tester class, RobotTester, has been provided as follows to help you how to implement the Robot class.Therefore, implement the Robot class such that the following RobotTester class can be executed withoutany changes.import java.awt.Point;/**A class to test the Robot class.*/public class RobotTester{/**Tests the…arrow_forward
- Write the value and compareTo methods for a pair of cards where suits play an important role. Aces are high, and assume that suits are ranked clubs (low), diamonds, hearts, and spades (high). Assume that face values are only considered if the suits are the same; otherwise ranking of cards depends on their suits alone.arrow_forwardImplement the class Character The role should be “primary” or “secondary” all other values are not acceptable. Considercapital and small letters variance. The gender should be “m” or “M” for male or “f” or “F” for female. The age should be a positive value. The giveRaise method increase the salary of a character by a given percentage with amaximum salary of 10000. The toString method returns a string that describes the character. For example: [Elisabeth Kane, female, 35, primary,4500$] 2) Implement the class Play A Play can have at most 20 characters. The real number of characters is registered in nbOfCharacters and is updated automaticallywhen a new character is added. AddCharacter method adds a new character to the characters array and updates thenbOfCharacters value. The attribute nbPlay keeps track of the number of Plays created. The toString method returns a string description of the play including name, genre and thenames of all the characters.Example: [The Opera…arrow_forwardShow code for an input method of a Time class. (A time-of-day has both an hour and a minute, commonly separated by a : symbol.) (Thought-provoker: Some times have a number of seconds after a 2nd : symbol...) (Hint: The members of a Time are not independent.)arrow_forward
- Create the compareTo method for a class that represents an individual whose first and last names are stored as two Strings. In an alphabetical list of people with last names first and then first names, one individual is "less than" another if they come before the other.(as is typical).arrow_forwardUse Java.arrow_forwardNote that you can only use recursion to solve Q1 and you cannot use any loop. You are free to add helper methods, but you are not allowed to change the method header.Question 1: Crazy seriesIn this session, you need to implement the crazy series method. In the crazy series, you will be given a starting number. Then, you need to times 2 for each number until the number is greater than 100. After the number is greater than 100, you need to divide 3 until we reach the number is less than 5. Note that the input number must be greater than 0, and you are not allowed to use loop here.For example,crazySeries(10) should return ArrayList [10.0, 20.0, 40.0, 80.0, 160.0, 53.333333333333336, 17.77777777777778, 5.9259259259259265, 1.9753086419753088]crazySeries(5) should return ArrayList [5.0, 10.0, 20.0, 40.0, 80.0, 160.0, 53.333333333333336, 17.77777777777778, 5.9259259259259265, 1.9753086419753088]crazySeries(1) should return ArrayList [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0,…arrow_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