Ok so I started Java a week ago and have done some pretty basic stuff but I am having a problem getting the code straight in my brain and lack confidence in my coding knowledge as of now to be sure I am doing the right thing.
I am going to type out the code that I have and see what everyone thinks and please give feedback I am not asking for answers or anything just want a little boost in confidence is all and maybe some pointers on how to better myself as a coder here goes nothing.
The assignment is to create an application where the main() method holds two integer variables. I have to assign values to both. I need to pass both variables to methods named
sum() and difference(). These methods have to compute the sum of and difference between the values of two arguments. I also have to add another method called product() and it should do all the above but instead of displaying the answers it has to return the answer to the calling method, which displays the answer. This is what I have:
public class Numbers
{
public static void main(String[] args)
{
int firstNum = 40; ( these are the values I assigned)
int secondNum = 132;(see above)
computeSum(firstNum, secondNum);
computeDiff(firstNum, secondNum);
computeProduct(firstNum, secondNum);
}
public static void computeSum(int firstNum, int secondNum)
{
double sum;
sum = firstNum + secondNum;
System.out.println("\nThe sum of " + firstNum +
" plus " + secondNum + " is " + sum);
}
public static void computeDiff(int firstNum, int secondNum)
{
double diff;
diff = firstNum - secondNum;
System.out.println("\nThe difference of " + firstNum
" minus " + secondNum + " is " + diff);
}
public static void computeProduct(int firstNum, secondNum)
{
double product;
product = firstNum * secondNum;
System.out.println("\The product of " + firstNum +
" times " + secondNum + " is " + product);
return product;
}
}
So that is what I have done and spent the last 2 hours trying to figure out, the part I am really confused on is the return product; part is that what the question is asking? I get lost when it talks about calling a method and what not any help would be awsome and if it is correct even better just thought I would get on and ask some people with more knowledge than myself.
-Andrew-

