Homework Solution: You have to write a program that will take as input from the command line two pairs of coordinates: the location of the robo…

    You have to write a program that will take as input from the command line two pais of coordinates: the location of the robot and the location of the gold coin. These must be whole numbers. Your program has to do the following: 1. echo the input; 2. output the number of steps (i.e., squares) that the robot has to travel horizontally and vertically to reach the gold coin; 3. specify the orientation for the robot to travel both horizontally (i.e., left or right) and vertically (i.e., up or down); and 4. calculate and output which direction travelled (horizontal or vertical) is greater 5. Implement the program using arrays and loops to let user decides when to quit the program You can assume that the grid squares are numbered like a Cartesian (X-Y) graph, wit positive X going horizontally to the right and positive Y going vertically upwards. Input coordinates can be negative, but they must be whole numbers. The output distance must be positive and must be expressed in whole numbers. sample run. Below is a sample run for two cases. The command line is highlighted in bold font. uNames java aseignment1 yourName 8 si 7 robot is at position (8,9) coin is at position (1,7) robot travels 7 steps to the left robot travels 2 steps down robot travels a greater distance horizontally than vertically Do you want to continue? unames java assignment1_yourName 8 9 8 1 robot is at position (8,9) coin is at position (8,1) robot does not travel horizontally robot travels 8 steps down cobot travels a greater distance vertically than horizontally o you want to continue? ource code. source code (i.e., assignment1 yourName.java file) but be neat and clearly ommented. You must have a header comment and you should comment the end ach block (i.e., each )). our
    You have to write a program that will take as input from the command line two pairs of coordinates: the location of the robot and the location of the gold coin. These must be whole numbers. Your program has to do the following: 1. echo the input: 2. output the number of steps (i.e., squares) that the robot has to travel horizontally and vertically to reach the gold coin: 3. specify the orientation for the robot to travel both horizontally (i.e., left or right) and vertically (i.e., up or down): and 4. calculate and output which direction travelled (horizontal or vertical) is greater 5. Implement the program using arrays and loops to let user decides when to quit the program You can assume that the grid squares are numbered like a Cartesian (X-Y) graph, with positive X going horizontally to the right and positive Y going vertically upwards. Input coordinates can be negative, but they must be whole numbers. The output distance must be positive and must be expressed in whole numbers. sample run. Below is a sample run for two cases. The command line is highlighted in bold font. uName$ java assignment1_yourName robot is at position (8, 9) coin is at position (1, 7) robot travels 7 steps to the left robot travels 2 steps down robot travels a greater distance horizontally than vertically Do you want to continue? java assignment1_yourName 8 9 8 1 robot is at position (8, 9) coin is at position (8, 1) robot does not travel horizontally robot travels 8 steps down robot travels a greater distance vertically than horizontally Do you want to continue? source code. Your source code (i.e., assignment1_yourName.java file) but be neat and clearly commented. You must have a header comment and you should comment the end block (i.e., each)).

    Expert Answer

     
    import java.lang.*; class Robot {

    You enjoy to transcribe a program that conquer engage as input from the bid verse brace pais of coordinates: the colonization of the robot and the colonization of the gold counterfeit. These must be total mass. Your program has to do the following: 1. solution the input; 2. extinguishedput the estimate of steps (i.e., squares) that the robot has to voyage vapidly and uprightly to gain the gold counterfeit; 3. indicate the orientation ce the robot to voyage twain vapidly (i.e., left or suitable) and uprightly (i.e., up or down); and 4. estimate and extinguishedput which superscription voyageled (vapid or upright) is senior 5. Implement the program using arrays and loops to suffer user decides when to relinquish the program You can feign that the grid squares are estimateed approve a Cartesian (X-Y) graph, humor decisive X going vapidly to the suitable and decisive Y going uprightly upwards. Input coordinates can be disclaiming, referablewithstanding they must be total mass. The extinguishedput absence must be decisive and must be explicit in total mass. specimen fly. Below is a specimen fly ce brace cases. The bid verse is highlighted in brave font. uNames java aseignment1 yourName 8 si 7 robot is at aspect (8,9) counterfeit is at aspect (1,7) robot voyages 7 steps to the left robot voyages 2 steps down robot voyages a senior absence vapidly than uprightly Do you nonproduction to objecture? unames java assignment1_yourName 8 9 8 1 robot is at aspect (8,9) counterfeit is at aspect (8,1) robot does referable voyage vapidly robot voyages 8 steps down cobot voyages a senior absence uprightly than vapidly o you nonproduction to objecture? ource rule. rise rule (i.e., assignment1 yourName.java refine) referablewithstanding be handsome and explicitly ommented. You must enjoy a header explain and you should explain the object ach arrest (i.e., each )). our

    You enjoy to transcribe a program that conquer engage as input from the bid verse brace pairs of coordinates: the colonization of the robot and the colonization of the gold counterfeit. These must be total mass. Your program has to do the following: 1. solution the input: 2. extinguishedput the estimate of steps (i.e., squares) that the robot has to voyage vapidly and uprightly to gain the gold counterfeit: 3. indicate the orientation ce the robot to voyage twain vapidly (i.e., left or suitable) and uprightly (i.e., up or down): and 4. estimate and extinguishedput which superscription voyageled (vapid or upright) is senior 5. Implement the program using arrays and loops to suffer user decides when to relinquish the program You can feign that the grid squares are estimateed approve a Cartesian (X-Y) graph, humorh decisive X going vapidly to the suitable and decisive Y going uprightly upwards. Input coordinates can be disclaiming, referablewithstanding they must be total mass. The extinguishedput absence must be decisive and must be explicit in total mass. specimen fly. Below is a specimen fly ce brace cases. The bid verse is highlighted in brave font. uName$ java assignment1_yourName robot is at aspect (8, 9) counterfeit is at aspect (1, 7) robot voyages 7 steps to the left robot voyages 2 steps down robot voyages a senior absence vapidly than uprightly Do you nonproduction to objecture? java assignment1_yourName 8 9 8 1 robot is at aspect (8, 9) counterfeit is at aspect (8, 1) robot does referable voyage vapidly robot voyages 8 steps down robot voyages a senior absence uprightly than vapidly Do you nonproduction to objecture? rise rule. Your rise rule (i.e., assignment1_yourName.java refine) referablewithstanding be handsome and explicitly explained. You must enjoy a header explain and you should explain the object arrest (i.e., each)).

    Expert Solution

     

    import java.lang.*;
    class Robot
    {
    public static destitute ocean(String args[])
    {
    int rx,ry,cx,cy;
    rx=Integer.parseInt(args[0]); // Accept x rate ce Robot
    ry=Integer.parseInt(args[1]); // Accept y rate ce Robot
    cx=Integer.parseInt(args[2]); // Accept x rate ce Counterfeit
    cy=Integer.parseInt(args[3]); // Accept y rate ce Counterfeit
    System.out.println(“robot is at aspect (“+rx+”,”+ry+”)”); // Display Aspect
    System.out.println(“counterfeit is at aspect (“+cx+”,”+cy+”)”); // Display Aspect
    if(rx>cx) // Checking in Which superscription Robot Should Move
    System.out.println(“robot voyages “+(rx-cx)+” steps to the left”);
    else if(rx<cx) // Checking in Which superscription Robot Should Move
    System.out.println(“robot voyages “+(cx-rx)+” steps to the suitable”);
    else
    System.out.println(“robot does referable voyage vapidly “);
    if(ry>cy) // Checking in Which superscription Robot Should Move
    System.out.println(“robot voyages “+(ry-cy)+” steps down”);
    else if(ry<cy) // Checking in Which superscription Robot Should Move
    System.out.println(“robot voyages “+(cy-ry)+” steps up”);
    else
    System.out.println(“robot does referable voyage uprightly “);
    if((Math.abs(rx-cx))>(Math.abs(ry-cy))) // Checking in Which superscription it engages more
    System.out.println(“robot voyages a senior absence vapidly than uprightly”);
    else if((Math.abs(rx-cx))<(Math.abs(ry-cy))) // Checking in Which superscription it engages more
    System.out.println(“robot voyages a senior absence uprightly than vapidly”);
    else
    System.out.println(“The Robot is at its Correct Aspect”);
    }
    }