Answered Essay: goal The goals of this assignment are to 1. practice using comments in your code; 2. learn h

goal The goals of this assignment are to 1. practice using comments in your code; 2. learn how to use command-line input; 3. practice using mathematical operators; and 4. practice using arrays and loops program Imagine a maze size in both directions (although you can assume that an int is large enough to store the largest coordinate in our grid) As an example, heres a picture of a 5x5 square grid maze. The robot is indicated by and the gold coin is indicated by with a robot in it. The maze is arranged in a square grid of infinite In addition to your robot, there is also a gold coin in the maze. The object of the game is for the robot to find the gold coin. In this illustration, the robot would travel 3 steps to the left and 2 steps up to reach the gold coinUSing Java, PLEASE include Comments, im have trouble with this and i need it in text please so it can be clear not written. and using command prompt.

goal The goals of this assignment are to 1. practice using comments in your code; 2. learn how to use command-line input; 3. practice using mathematical operators; and 4. practice using arrays and loops program Imagine a maze size in both directions (although you can assume that an int is large enough to store the largest coordinate in our grid) As an example, here’s a picture of a 5×5 square grid maze. The robot is indicated by and the gold coin is indicated by with a robot in it. The maze is arranged in a square grid of infinite In addition to your robot, there is also a gold coin in the maze. The object of the game is for the robot to find the gold coin. In this illustration, the robot would travel 3 steps to the left and 2 steps up to reach the gold coin

Expert Answer

 

Explanation::

  • Code in JAVA is given below.
  • Note that class name is assignment1_yourName so please consider class name while saving the file and running the program.
  • Logic:: Logic is simple to understand. See the images provided below for better understanding of the strategy used.
  • Please read all the comments provided in code for better understanding of the code.
  • Each every case is considered and program is executed using different test cases.
  • See the output screenshots provided below the code.

Logic::

Code in JAVA::

/*

* Robot Travels to coin problem!!

*/

public class assignment1_yourName{

public static void main(String args[]){

/*

* Below 4 integer variables are declared.

* robotX and robotY stores current position of Robot.

* coinX and coinY stores current position of Coin.

*/

int robotX,robotY;

int coinX,coinY;

/*

* Initialization of all the four variables is done below.

* Values of command line argument are stored in args[] string array.

* See the index values of args[] they start from 0 and go upto 3.

*/

robotX=Integer.parseInt(args[0]);

robotY=Integer.parseInt(args[1]);

coinX=Integer.parseInt(args[2]);

coinY=Integer.parseInt(args[3]);

/*

* Below we need to know how many steps do robot need to travel.

* int stepsX stores difference between coinX and robotX.

* int stepsY stores difference between coinY and robotY.

* More information is provided in image format to understand how

* this formula is derived.

*/

int stepsX=coinX-robotX;

int stepsY=coinY-robotY;

/*

* It is possible that we get stepsX and stepsY as negative value.

* But for printing purpose of steps count we need to show them as positive

* number of steps. So integer x and y stores absolute values of stepsX and stepsY

* respectively.

*/

int x=Math.abs(stepsX);

int y=Math.abs(stepsY);

/*

* We just print current position of robot and coin using required format.

*/

System.out.println(“robot is at position (“+robotX+”,”+robotY+”)”);

System.out.println(“coin is at position (“+coinX+”,”+coinY+”)”);

/*

* Now we print all the steps taken by robot to reach the coin.

* Every possible condition is provided in if-else conditions.

*/

/*

* Here first horizontal movement of robot is considered.

*/

if(stepsX==0){

/*

* If stepsX is 0 that means robot do not travel horizontally

*/

System.out.println(“robot does not travel horizontally”);

}else{

/*

* If stepsX is not 0 then it means that robot has to move horizontally.

* Now there are two possibilities of horizontal movement

* 1’st is left and 2’nd is right.

*/

if(stepsX<0){

/*

* If stepsX is negative then it means that robot has to move left.

* Note here in print statement we have used absolute value x for number of steps.

*/

System.out.println(“robot travels “+x+” steps to the left”);

}else{

/*

* If stepsX is positive then it means that robot has to move right.

* Note here in print statement we have used absolute value x for number of steps.

*/

System.out.println(“robot travels “+x+” steps to the right”);

}

}

/*

* Now secondly vertical movement of robot is considered.

*/

if(stepsY==0){

/*

* If stepsY is 0 that means robot do not travel vertically

*/

System.out.println(“robot does not travel vertically”);

}else{

/*

* If stepsY is not 0 then it means that robot has to move vertically.

* Now there are two possibilities of vertical movement

* 1’st is up and 2’nd is down.

*/

if(stepsY<0){

/*

* If stepsY is negative then it means that robot has to move down.

* Note here in print statement we have used absolute value y for number of steps.

*/

System.out.println(“robot travels “+y+” steps down”);

}else{

/*

* If stepsY is positive then it means that robot has to move up.

* Note here in print statement we have used absolute value y for number of steps.

*/

System.out.println(“robot travels “+y+” steps up”);

}

}

/*

* Now depending on which steps are greater we print respective statement

*/

if(x>y){

System.out.println(“robot travels a greater distance horizontally than vertically”);

}else if(y>x){

System.out.println(“robot travels a greater distance vertically than horizontally”);

}else{

System.out.println(“robot already at coin position”);

}

/*

* NOTE::

* WE cannot loop and take command line arguments again and again in same

* run of the program.

* We can only take one set of arguments and get respective output.

*/

System.out.println(“Do you want to continue?”);

}//MAIN ENDS HERE

}//CLASS ENDS HERE

Output::

Test case 1::

Test case 2::

Test case 3::( Explained in Logic section)

Test case 4::(Robot is at same position of coin)

Thank you!!

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.