Carrying a torch
Badges: 7
Rep:
?
#1
Report Thread starter 1 month ago
#1
I'm having an issue while programming in java

I have to make a calculator that operates on two values and each values has to be in a different method
0
reply
AcseI
Badges: 18
Rep:
?
#2
Report 4 weeks ago
#2
(Original post by Carrying a torch)
I'm having an issue while programming in java

I have to make a calculator that operates on two values and each values has to be in a different method
And what is the issue?
0
reply
Carrying a torch
Badges: 7
Rep:
?
#3
Report Thread starter 4 weeks ago
#3
(Original post by AcseI)
And what is the issue?
I have two methods and each one separately gives input values stored in separate variables. So when I make a third method and try to do simple arithmetics using the input values it doesn't work because the variables aren't local.

I was told that I had to somehow pass an argument and use parameters. The thing is, I'm not able to link each input value variables to variables or values in any other method.
Last edited by Carrying a torch; 4 weeks ago
0
reply
AcseI
Badges: 18
Rep:
?
#4
Report 4 weeks ago
#4
(Original post by Carrying a torch)
I have two methods and each one separately gives input values stored in separate variables. So when I make a third method and try to do simple arithmetics using the input values it doesn't work because the variables aren't local.

I was told that I had to somehow pass an argument and use parameters. The thing is, I'm not able to link each input value variables to variables or values in any other method.
So I'm not a Java person, and troubleshooting code is basically impossible without seeing the code.

In general terms, each number would be stored in it's own method as a variable and you'd return that number to the calling method. So:
method_1 generates a number and returns it
method_2 generates a number and returns it

Then method_3, the one where you actually do the calculation, would call each of those methods. You could store those numbers in variables, and then perform an operation (in this example addition):
number_1 = method_1()
number_2 = method_2()
total = number_1 + number_2

It's a slightly odd task though, as by itself this isn't something that actually requires 3 different methods. It's difficult to offer more help without knowing the exact brief you've been given.
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top