Hi all,
I'm new to programming and am trying to understand getX() and getY() to extract the x, y coordinates from a point entered by the user. One of my problems is that I've defined that point (location) as a double, and so I'm getting the error 'double cannot be dereferenced' when I call location.getX() and location.getY(). To clarify, the x, y is a point of 2 integers.
This program is supposed to take the name, direction, and location of a robot and depending on the user cmd's, it's supposed to move it forward one step, turn it left (N,S,W,E), and print a report saying what was done.
I'd appreciate any clarification so I can test the code I've got. Thanks in advance
import java.util.*; class Robot { //method main gets the values from the user public static void main(String[] args) { Scanner zip = new Scanner(System.in); System.out.println("Enter the robot's name: "); String name = zip.nextLine(); System.out.println("Enter the location (x, y) format: "); double location = zip.nextDouble(); System.out.println("Enter the direction the robot is facing: "); String direction = zip.nextLine(); double x = location.getX(); double y = location.getY(); } //method turnLeft changes the direction depending on the currentLocation String turnLeft(String direction) { String currentLocation = direction; if (currentLocation == "North") { currentLocation = "West"; } if (currentLocation == "West") { currentLocation = "South"; } if (currentLocation == "South") { currentLocation = "East"; } if (currentLocation == "East") { currentLocation = "North"; } } //method moveForward changes the location depending on the currentLocation String moveForward(String direction, Double location) { String currentLocation = direction; if (currentLocation == "South") { location.getY() = location.get(Y) + 1; } if (currentLocation == "West") { location.getX() = location.getX() - 1; } } //method report prints the following: String report(String direction, Double location) { return name + ", " + location.getX() + ", " + location.getY() + ", " + currentLocation; } }