Methods that return a value Assignment Help

Assignment Help: >> Classes in Java >> Methods that return a value

Methods that return a value:

As well as methods that move the robot, we also have methods that indicate the current position of the robot. The two methods we need are called getX and getY. These methods each return a value, the current x or y position of the Robot object.The code for these two methods is shown below:

public int getX()

{

return x;

}

public int getY()

{

return y;

}

The method header includes the keyword int (rather than void as before) to indicate that the method will return an integer value. In the body of the method, the return keyword precedes the value to be returned. In this case, the methods simply return the value of the appropriate instance variable.

In previous discussions of methods that return a value, we have not explained what happens to the returned value after the method has done its work. By way of explanation, we now look at the method getX. We can invoke this method to find the current x position of the Robot object referenced by deetoo as follows:

deetoo.getX();

However, this statement is not very useful as we have not made use of the returned value in this case, it would be discarded. The simplest thing to do is to save the value by assigning it to an integer variable as follows:

int currentX; 

currentX = deetoo.getX(); 

We can then use this saved value in any way appropriate to an integer value. For example, we could display it in a message:

System.out.println("Robot at x="+currentX);

 

Java Assignment Help - Java Homework Help

Struggling with java programming language? Are you not finding solution for your Methods that return a value  homework and assignments? Live Methods that return a value  experts are working for students by solving their doubts & questions during their course studies and training program. We at Expertsmind.com offer Methods that return a value  homework help, java assignment help and Methods that return a value  projects help anytime from anywhere for 24x7 hours. Computer science programming assignments help making life easy for students.

Why Expertsmind for assignment help

  1. Higher degree holder and experienced experts network
  2. Punctuality and responsibility of work
  3. Quality solution with 100% plagiarism free answers
  4. Time on Delivery
  5. Privacy of information and details
  6. Excellence in solving java programming language queries in excels and word format.
  7. Best tutoring assistance 24x7 hours

 

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd