• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Don't know how to have java remember Overall total and add it

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:


I don't know how to get the overall total to calculate and give an overall total.. i don't know if i did it wrong i dont know what to do
 
Marshal
Posts: 80099
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

You will have problems with that code because you aren't createing objects. You have got one method, which is far too large, and should me made into lots of little methods. You should have some sort of class for Module or something like that, which has totals for all the students, and you add to it as each student is registered.
 
Nicholas Andrade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

You will have problems with that code because you aren't createing objects. You have got one method, which is far too large, and should me made into lots of little methods. You should have some sort of class for Module or something like that, which has totals for all the students, and you add to it as each student is registered.




Thank you Campbell.. I'm new to this an I'm totally lost.. Can you help guide me in the right direction ??
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nicholas,

Welcome to CodeRanch!

As Campbell has already mentioned, you need to make the code modular.

Apart from that, I haven't gone through all the code, but it will be much helpful if you TellTheDetails(<-click) - that is - what is the input you gave, what was the expected output, what is actual output etc.

Also, you can try and put some extra print statements at intermediate steps (e.g. after calculating the sum etc.) to understand in which area the code is going wrong.

I hope this helps.
 
Campbell Ritchie
Marshal
Posts: 80099
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You start small. Get the student class working (maybe) and try it out with a Student Demo (That brings back memories of the 1960s ‍) class. Start with Student having one field only, and add fields as your tests appear correct. Try the first, the add the id number. Then get a Module/Course field.
You can forget StudentDemo whenever the tests are successful. Forget about the rest of the app until you have Student working and add it later.
 
Nicholas Andrade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys.. will give it another shot an see how I end up! Thanks again
 
Campbell Ritchie
Marshal
Posts: 80099
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
Do show us what you have got, when you have some new code.
 
Nicholas Andrade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my fellow coders!! my question to you is how do you define multiple methods within java... i'm a total newie with this!! kinda feel stupid i enjoy the challenge tho
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nicholas,

It seems that you are new to object oriented concepts. I would recommend to go through those concepts (e.g. Head First Object Oriented Analysis and Design) or a decent Java book which covers the basics (e.g. Head First Java).

Short answer to your question:
You can define multiple methods in a class. Then, you can create object of the class to invoke those methods.

Of course, there are more rules to it (e.g. you cannot invoke private methods over the instance directly etc.) and going through the resources I've mentioned should help.
 
Campbell Ritchie
Marshal
Posts: 80099
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like this:-And if you can't think of more useful methods that that …
 
Nicholas Andrade
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell, i was actually just looking at a video on you tube explaining it ... you guys are great help! i'm glad i found this forum! i will attempt coding again and see... Thank you again!
 
Campbell Ritchie
Marshal
Posts: 80099
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
Some videos on YouTube are really good, others not so. Don't “try” any coding. Write down what you want on paper, then write the code. Do it a tiny bit at a time.
 
Ever since I found this suit I've felt strange new needs. And a tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic