• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I Just Want One Method

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic