4 Replies - 504 Views - Last Post: 08 December 2016 - 09:53 AM Rate Topic: -----

#1 nicadisa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-December 16

Help writing method for divide()

Posted 08 December 2016 - 08:47 AM

Hello, I need help writing a method for divide() in Java. I already have the divisor set to 2 but I got stuck on the divide method. So far I have:


public void divide()


it needs to take a single formal argument of type double
and return the result of dividing the argument by divisor as a value of type double

I can't wrap my brain around it. Can anybody help?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Help writing method for divide()

#2 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 693
  • View blog
  • Posts: 5,303
  • Joined: 25-December 13

Re: Help writing method for divide()

Posted 08 December 2016 - 08:48 AM

Take a look at the tutorial about how to define a method: http://docs.oracle.c...OO/methods.html
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2540
  • View blog
  • Posts: 10,176
  • Joined: 03-December 12

Re: Help writing method for divide()

Posted 08 December 2016 - 09:01 AM

Quote

return the result


Think about it,


Requirements
  • take a single formal argument of type double
  • return the result


What should the method signature look like based on these requirements?
Was This Post Helpful? 0
  • +
  • -

#4 nicadisa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-December 16

Re: Help writing method for divide()

Posted 08 December 2016 - 09:47 AM

Thanks for your replies.

I'm supposed to type in divide(5); and it returns 2.5

what I don't understand is how the method gets the argument 5 and then divides it by 2

the divisor initiates to 2, so that's fine

when I type in divide(5) what's going on?

the divide method is supposed to get the 5 and then divide it by 2 and return the quotient, 2.5

I've been stuck on this for a while
Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 693
  • View blog
  • Posts: 5,303
  • Joined: 25-December 13

Re: Help writing method for divide()

Posted 08 December 2016 - 09:53 AM

Continue reading the tutorial: http://docs.oracle.c...eturnvalue.html

Be sure to look at the other pages about using methods and arguments to methods.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1