Finish the Java program inputNewPlayerLocation: to input (x,y) coordinates from user (using Scanner), then return a Point object with those coordinates. swapPoints: to swap the coordinates of two Point objects. (Hint: To keep the main function's reference variables relevant, you can't swap Point objects entirely. You need to change the x and y coordinates inside the Point objects.)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Finish the Java program

  • inputNewPlayerLocation: to input (x,y) coordinates from user (using Scanner), then return a Point object with those coordinates.
  • swapPoints: to swap the coordinates of two Point objects. (Hint: To keep the main function's reference variables relevant, you can't swap Point objects entirely. You need to change the x and y coordinates inside the Point objects.)
import java.awt.Point;
import java.util.Scanner;
22
23
24
25
class Main
{
public static void main(String[] args)
{
Point player1_location, player2_location;
26
27
28
29
30
player1_location = inputNewPlayerLocation();
player2_location = inputNewPlayerLocation();
31
32
33
34
System.out.println("Player1 location: (" + player1_location.x
35
+"," + player1_location.y + ")");
36
System.out.println("Player2 location: (" + player2_location.x
|||| +"," + player2_location.y + ")");
37
38
39
swapPoints (player1_location, player2_location);
40
System.out.println("Player 1 and Player 2 have swapped locations!");
System.out.println("Player1 location: (" + player1_location.x
|||||||| || +"," + player1_location.y + ")");
System.out.println("Player2 location: (" + player2_location.x
|||| +"," + player2_location.y + ")");
41
42
43
44
45
46
}
47
Transcribed Image Text:import java.awt.Point; import java.util.Scanner; 22 23 24 25 class Main { public static void main(String[] args) { Point player1_location, player2_location; 26 27 28 29 30 player1_location = inputNewPlayerLocation(); player2_location = inputNewPlayerLocation(); 31 32 33 34 System.out.println("Player1 location: (" + player1_location.x 35 +"," + player1_location.y + ")"); 36 System.out.println("Player2 location: (" + player2_location.x |||| +"," + player2_location.y + ")"); 37 38 39 swapPoints (player1_location, player2_location); 40 System.out.println("Player 1 and Player 2 have swapped locations!"); System.out.println("Player1 location: (" + player1_location.x |||||||| || +"," + player1_location.y + ")"); System.out.println("Player2 location: (" + player2_location.x |||| +"," + player2_location.y + ")"); 41 42 43 44 45 46 } 47
63
/* Here is the Sample Output your completed program should produce:
64
Welcome, new player. Please enter your coordinates:
x: 5
65
66
67
у: 7
Welcome, new player. Please enter your coordinates:
X: 10
68
69
у: 15
Player1 location: (5,7)
Player2 location: (10,15)
Player 1 and Player 2 have swapped locations!
Player1 location: (10,15)
Player2 location: (5,7)
70
71
72
73
74
75
76
77
78
Welcome, new player. Please enter your coordinates:
79
x: 20
у: 30
Welcome, new player. Please enter your coordinates:
80
81
82
х: 3
у: 1
Player1 location: (20,30)
Player2 location: (3,1)
Player 1 and Player 2 have swapped locations!
Player1 location: (3,1)
Player2 location: (20,30)
83
84
85
86
87
88
89
90
*/
Transcribed Image Text:63 /* Here is the Sample Output your completed program should produce: 64 Welcome, new player. Please enter your coordinates: x: 5 65 66 67 у: 7 Welcome, new player. Please enter your coordinates: X: 10 68 69 у: 15 Player1 location: (5,7) Player2 location: (10,15) Player 1 and Player 2 have swapped locations! Player1 location: (10,15) Player2 location: (5,7) 70 71 72 73 74 75 76 77 78 Welcome, new player. Please enter your coordinates: 79 x: 20 у: 30 Welcome, new player. Please enter your coordinates: 80 81 82 х: 3 у: 1 Player1 location: (20,30) Player2 location: (3,1) Player 1 and Player 2 have swapped locations! Player1 location: (3,1) Player2 location: (20,30) 83 84 85 86 87 88 89 90 */
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education