aspose file tools*
The moose likes Beginning Java and the fly likes I Just Want One Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I Just Want One Method" Watch "I Just Want One Method" New topic
Author

I Just Want One Method

Gary Lineker
Greenhorn

Joined: Sep 20, 2012
Posts: 2
Greetings all. Beginner here struggling with a school project. The problem areas I have highlighted in red within the Java program. For the modules that I am struggling with, you will notice I have created four four calling statements each referring to a separate module:



The modules look like this:



Essentially I need to calculate the sums for each of these but I need to do it within one module called calculateSubjectSum. My brain has really shut down and although I'm convinced it's something really glaring, for the life of me I'm stumped. Thank you!

Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

First, please use code tags. The make code much easier to read. Second, when posting code, less is more. Try to narrow the code sample down as much as you can and still have a complete example that demonstrates the problem.

I'm not clear on what you mean by module in this example. I do notice that your four methods all do exactly the same thing. They just have different names and different parameters names. So maybe what you mean by only one module is that you want only one method. Something like



You can call that method four times, passing in the same parameters you pass into the four differently-named methods now, and you'll get the same results. If that's not it, then what problem are you having exactly?
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Greg Charles wrote:Something like



You can call that method four times, passing in the same parameters you pass into the four differently-named methods now, and you'll get the same results. If that's not it, then what problem are you having exactly?

Ponder Mr. Linekar. I think this is the solution considering your module means a method.


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
Gary Lineker wrote: . . . . The problem areas I have highlighted in red within the Java program. . . .
No, you haven’t. Colour tags don’t work inside code tags, so I shall delete them.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8016
    
  22

Greg Charles wrote:Something like

Actually, my suggestion would be: What that does is to take an array of (or several individual) values and calculate their sum; and it's properly decoupled.

@Gary: What your method is doing is not summing, it's accumulating; and that's very difficult to do in a loosely coupled way.

And, whatever you do decide on, don't forget that an int that is the sum of several other int's might overflow.

Winston
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I Just Want One Method