Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA LANGUAGE PLEASE: Develop an application named Prog3 that tests your Robo

ID: 3669348 • Letter: I

Question

In JAVA LANGUAGE PLEASE:

Develop an application named Prog3 that tests your Robot class. The test application will ask the user for the robot's name. It will then instantiate a Robot object using the name. The application will then use a loop to ask the user to enter a direction ( X or Y) to move and the distance. The loop will terminate when the user enters a direction of q ( for quit). Once the loop is done, the program will display the robot's final position and the total distance is traveled.

Explanation / Answer

public class Robot { private String name; private int xPosition; private int yPosition; private int totalDistance; public Robot(String name, int xPosition, int yPosition, int totalDistance){ super(); this.name = name; this.xPosition = 0; this.yPosition = 0; this.totalDistance = totalDistance; } public String getName() { return name; } public int getxPosition() { return xPosition; } public int getyPosition() { return yPosition; } public int getTotalDistance() { return totalDistance; } public void moveX(int distance){ xPosition += distance; totalDistance += Math.abs(distance); } public void moveY(int distance){ yPosition += distance; totalDistance += Math.abs(distance); } } import java.util.Scanner; public class RobotDemotest { public static void main(String[] args) { Scanner in = new Scanner(System.in); Robot robot = new Robot(); //asks the user for robots name System.out.print("Enter robots name; "); Robot.name = in.nextLine(); //asks the user to move the robot System.out.print("Direction of move (x/y/q): "); String move = in.nextLine(); if( move.equals("x") ){ System.out.print("Distance: "); } else if( move.equals("y") ){ System.out.print("Distance: "); } else{ } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote