Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Java OOP problem...ASAP?
I'm having problems understanding a few questions...It's an OOP assignment...I need 2 submit this on Monday...So any1 kind enough 2 share they're codings wit me...It's 4rm Interactive input & Methods...
a)Create an application named Numbers whose main() method hold three integer
variables. Assign values to the variables. Pass both variables to methods named
sum() and difference().
Create the methods sum() and difference(); they compute the sum of and difference
between the values of three arguments, respectively. Each method should perform
the appropriate computation and display the results. Save the application as
Number.java
b. Add a method named product() to the Numbers class. The product() method should
computed the multiplication product of three integers, but not display the answer.
Instead, it should return the answer to the calling method, which displays the
answer. Save the application.
Plzz & TQ
4 Answers
- 1 decade agoFavorite Answer
This is quite a simple assignment, it doesn't really involve any OOP. You need to have basic understanding of the following rules:
- You must have a main() method in Java, it's the first method that's going to be executed when the program runs, and it's basically the method that starts it all.
- Variables and they're different types (string, int, float, etc.)
- How to create a method and pass variables as arguments.
- How to return a value from a method
a)
public class Numbers
{
public static void main(String[] args)
{
int a = 5, b = 3, c = 8; // Declaring and initializing the variables
sum(a, b); // Calculating the sum of variables a and b by passing them as arguments
// trhough the sum method
difference(b, c); // Calculating the difference between b and c
}
static void sum(int a, int b) // Creating a method called sum with two possible integer
//arguments called a and b
{
System.out.println(a + b); // Printing the result
}
static void difference(int a, int b) // Creating a method called difference with two possible
// integer arguments
{
System.out.println(a - b); // Printing the result
}
}
Now you fgure out how to do the second one.
Source(s): Freelance programmer. - 7 years ago
Write a program whose main() method hold two integer variables. Assign values to the variables. Create two additional methods, sum() and difference(), that compute the sum and difference between the values of the two variables, respectively. Each method should perform the computation and display the result. In turn, call each of the two methods from main(), passing the values of the two integer variables.
*** Add a method named product() to the program. The product() method should compute the multiplication product of two integers, but not display the answer. Instead, it should return the answer to the calling main() program, which display the answer.
- Anonymous5 years ago
Ok that should not be too hard. Read all the sells into the array then use a sort method (like bubble sort) to find the 3 best sells and display them. You can use a for each loop to add up all the sales. Hope this helps.
- SAMLv 41 decade ago
Well you have the answer in the question itself...
Anyways... I will try to help you if you can tell me what do you mean by "difference between the values of three arguments"????
Regards
SAM