Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default Array help! - Grand totals

    Okay, I am very new to programming and need some help on an assignment. I need to create a program that tracks a Jog-a-thon. Prompt. I'm having issue working with the "Grand total" array. Which is to say I have no idea where to begin.

    My prompt: http://pastebin.com/raw.php?i=jf4anpjn

    This code has a kink or two to work out, but right now I need to add the showTotals() method, and could use some help on how I go about doing that. As well as updating the grandtotals in the gettotals() method. Ultimately I just need help on working with the grand total array.

    edit: removing code.
    Last edited by Gaebril; 04-14-2011 at 03:10 AM.

  2. #2
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default

    since you don't provide any details of what the showTotals method should do how are we supposed to help?

    I have a few problems with your design. Why is the names array in the Student class? Why does Tom need to have a copy of Ryan's name, Mandy's name etc? Also "Donations" is not a name so why is it in the array?

    Why does the Student class print the Jog-a-thon banner? A Student can certainly exist without the need to print that. Same with the getChoice method. You are making every Student object have these methods/variables and yet not every Student will be part of the Jog-a-thon.

  3. #3
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    If you click on the link for the prompt, it will describe what the showTotals method should do. Sorry for the confusion. I didn't want to take up room for the prompt but here is the link again: http://pastebin.com/raw.php?i=jf4anpjn

    As for the other items mentioned let me review that. *Edit* I need to have 2 different codes. One is just a set of methods that the other calls upon. So, the names array is in the Student class because that's the way the teacher would prefer it. I need to set the all the data with the methods, then call upon them in the Jogathon class. The banner is necessary, because it says so. :P Donations is not a name, you are correct, however it is a way for other students to make a "donation" without being named. View it as "anonymous". "Why does Tom need to have a copy of Ryan's name, Mandy's name etc?" - I'm not really sure what you mean by this? Sorry, view me as a programming infant. Either I am misinterpreting much of what you are saying or you just missed the prompt. I know the code is rough, but right now I need to know how to make a grand total for items....

    Let's say we input a pledge for Tom 3xs, I need to have a way to update his "grand total" and then print it.

    -Another issue which I don't know how to figure out is my toString prints as "null".
    Last edited by Gaebril; 04-14-2011 at 12:50 AM.

  4. #4
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default

    Quote Originally Posted by Gaebril View Post
    If you click on the link for the prompt, it will describe what the showTotals method should do.
    Why should I do that. If you can't be bothered providing enough relevant information in your post why should I bother providing an answer?

  5. #5
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    I apologize. I found the prompt was more inclusive in the information that it provided, which would give a better understanding of what i needed help with. For now, lets forget about my shit formatting.

    My issue, sans-prompt:

    I have 2 arrays. 1 for students and "donation" (names). 2nd for Grand totals (grandt). I don't understand how to make adjustments to the grandt array, that cumulate. Or even how to assign totals that will associate with each student.

    Let's say we selected Tom. Input that he ran 4 laps, and had a pledge of 2.00. His grand total as of now would be 8.00. But Tom has 2 people that pledged for him. So, we input a 2nd pledge. This pledge is for 5.00 and Tom still ran 4laps. Now Tom's grand total is 28.00.

    I am not sure on how to even do 1 grand total, much less if we put him in twice. I hope this helps.

  6. #6
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    @Junky
    Really? Read the attached prompt then you can ask questions.

    @OP
    snumber should not be static, because in the prompt it says only 2 variables will be static, aka both arrays.

  7. #7
    Junky's Avatar
    Junky is online now Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default

    Quote Originally Posted by ra4king View Post
    @Junky
    Really? Read the attached prompt then you can ask questions.
    Don't tell me what to do. If an OP is too lazy to provide information then I have the right to be too lazy to follow a link!

  8. #8
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Too lazy? The link is better than copying and pasting into this unformatted forum ;)

  9. #9
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Don't tell me what to do. If an OP is too lazy to provide information then I have the right to be too lazy to follow a link!
    Had nothing to do with laziness. I actually went out of my way to make it a link, so as not to clutter the forum. Figured it was better than cut and pasting. Just trying to help out the people willing to help me out. But I'd rather not turn this is into a debate on whether or not I'm lazy. I was just looking for help. I will do whatever is helpful for the helping process to happen. As, I'm still clueless on how to go about this.

    From what I've gathered I need to make the showTotals() method a for loop and store the amount in the grandt array. But I could use some help on how to specifically go about that. Or if that is the best solution.
    Last edited by Gaebril; 04-14-2011 at 01:51 AM.

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Well back on topic, showTotals would have to be static and just print the name with the grand total from the arrays. Thus you would have a loop that prints out names[i] + grandt[i].

  11. #11
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    Well back on topic, showTotals would have to be static and just print the name with the grand total from the arrays. Thus you would have a loop that prints out names[i] + grandt[i].
    That makes sense. Now, how do I update the grand total under the gettotal() method? This would update the array, assuming there would be 7 items in the array. Then I can just associate each item with its associated names array. But I need to find a way to assign the grandtotals, and keep them updated.

    I also assume I need to change, by setting variables or is it good as is?
    Java Code:
    private static double[] grandt;
    Also, I have no idea why my toString is coming out null.
    Last edited by Gaebril; 04-14-2011 at 02:00 AM.

  12. #12
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    I think you are supposed to call gettotals() for each student so their donations and pledges will be added to the grandt. All you would do is store "laps*pledge" into "amount" and then store "amount" in the grandt[snumber] (btw, snumber cannot be static so change that to private int snumber;)
    Also don't forget to initialize grandt ;)

  13. #13
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    Haha, yea. I removed static from the snumber. I was playing with a conditional in the jogathon class, then changed my conditionals and just forgot to remove the static. I'm gonna play with what you just said, but it seems like the amount wouldn't add to itself. So, if we ran the gettotals twice for Tom, wouldn't the amount just replace the previous amount?

    Looks I got everything working, essentially. But I still have the toString issue. It prints as null, and then when I call the array it will print out the 6 students and 44 nulls. I feel like this must be an easy fix.
    Last edited by Gaebril; 04-14-2011 at 02:14 AM.

  14. #14
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Well of course it prints null, that's because you haven't set "name" to equal anything for the other 44 students!

    EDIT: Also noticed, getchoice() should be integrated in getdata(). Also add in your getdata(), if(snumber > 0) { //code for getting data } because if the person is doing a donation, they wouldn't be prompted for the laps and pledge.
    Last edited by ra4king; 04-14-2011 at 02:21 AM.

  15. #15
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    Hmmmmm.... I need it to be set for 7 students, donations then the names. But limit of 50 pledges. How would I do that? Do I need to make a 2dim array? Shouldn't my toString print out regardless of that? I can understand the 44 nulls. But I get a null when I call the toString at all.

  16. #16
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    What you currently have works fine.

    And do you mean toString() returns a null?!? How is that possible?

  17. #17
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    Edit: I think its because the gettotals calls the name, and gettotals is under the if conditional.

    My exact thoughts. Here is a cut and paste of what it does.

    Gonna use the code tag for it. But this is a clip from when i run the code.
    Java Code:
    Enter choice (1-6, or 0 for Donation): 
    1
    Is selection a Donation? (Y/N)
    n
    
    Enter laps ran: 
    2
    
    Enter pledge amount: 
    3.00
    null //the toString
    Last edited by Gaebril; 04-14-2011 at 02:30 AM.

  18. #18
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    For debugging purposes, see what prints out when you change the spaces to '-' in the toString() so it would be "stats = name + "-" +//etc..."

  19. #19
    Gaebril is offline Member
    Join Date
    Mar 2011
    Posts
    21
    Rep Power
    0

    Default

    I'm looking at the prompt, and it doesn't say I actually need to call the toString right after. If I didn't call it, then everything seems work, aside from getting 44 nulls. So, lets work on that.

    How would I remove the 44 nulls? Rather 50 nulls - pledges input.

  20. #20
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    I told you, you have to set the name for the anonymous ones. Try also checking if "dollarFormat.format(pledge)" and "dollarFormat.format(amount)" work.

Page 1 of 2 12 LastLast

Similar Threads

  1. Finding totals - HELP!!
    By mikeg in forum New To Java
    Replies: 20
    Last Post: 11-19-2010, 05:37 PM
  2. Running totals in java. HELP!
    By mikeg in forum New To Java
    Replies: 8
    Last Post: 11-19-2010, 09:29 AM
  3. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  4. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  5. Java Loops - accumulating totals
    By iv3java in forum New To Java
    Replies: 6
    Last Post: 12-15-2009, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •