Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am being asked to solve a two part question in Joyce Farrell\'s 5th Edition of

ID: 3623119 • Letter: I

Question


I am being asked to solve a two part question in Joyce Farrell's 5th Edition of Java Programming. I was able to solve the first part (with a little help from this site and a friend).

I will post that code below:

The second part of the question asks me to add a method named product() which I have done to the "Numbers" class. The product () method should compute the multiplication productt of two integers, but not display the answer. Instead, it should return the answer to the calling method, which displays the answer. I have scoured the textbook and while they do speak about calling and returning a method, I cannot make this work. Any guidance would be apprcieated: (You will notice some failed attempts of doing this in the code). This code will compile but will not do what is being asked.

public class Numbers2
{
public static void main(String[] args)
{ //Declaring static integers
int firstEntry =105;
int secondEntry=79;
int callTest;
int multiply;


//Referances to the methods below
sum(firstEntry,secondEntry);
differance(firstEntry,secondEntry);
product(firstEntry,secondEntry);


} //First method
static void sum(int entryOne,int entryTwo)
{ //Output ~ adds and displays the two integers
System.out.println("The sum of the numbers " + entryOne + " and " + entryTwo +
" is " + (entryOne + entryTwo));

} //Second method
static void differance(int entryOne,int entryTwo)
{ //Output ~ subtracts and displays the two integers
System.out.println("The differance of the numbers " + entryOne + " and " + entryTwo +
" is " + (entryOne - entryTwo));
}//Third method
public static int product(int entryOne,int entryTwo)
{
int multiply;
multiply = entryOne * entryTwo;
return multiply;

Explanation / Answer

please rate - thanks

you virtually had it

public class Numbers2
{
public static void main(String[] args)
{ //Declaring static integers
int firstEntry =105;
int secondEntry=79;
int callTest;
int multiply;
int prod;

//Referances to the methods below
sum(firstEntry,secondEntry);
differance(firstEntry,secondEntry);
prod=product(firstEntry,secondEntry);
System.out.println("The product of the numbers " + firstEntry + " and " + secondEntry +
" is " + prod);


} //First method
static void sum(int entryOne,int entryTwo)
{ //Output ~ adds and displays the two integers
System.out.println("The sum of the numbers " + entryOne + " and " + entryTwo +
" is " + (entryOne + entryTwo));

} //Second method
static void differance(int entryOne,int entryTwo)
{ //Output ~ subtracts and displays the two integers
System.out.println("The differance of the numbers " + entryOne + " and " + entryTwo +
" is " + (entryOne - entryTwo));
}//Third method
public static int product(int entryOne,int entryTwo)
{
int multiply;
multiply = entryOne * entryTwo;
return multiply;
}
}