Results 1 to 10 of 10
  1. #1
    bkim33 is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default Need help with homework

    Hi guys,

    Im having some trouble figuring out how to write this program
    Last edited by bkim33; 02-11-2011 at 05:35 AM. Reason: mistake

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

    Default

    The first problem is that you set value and prevalue to v. Does that sound right to you? I would have thought you set prevalue to the last value the user entered not the current one. And you would only do that for a given situation such as IF the current value is greater than the previous value. Also, you might find this simpler if you use a boolean in the while loop instead.

  3. #3
    bkim33 is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    So how would I set prevalue to the last value while being able to enter in a new value ? sorry if im asking a dumb question im new to java and like I said, Im having a hard time learning this because I have to rely solely on the book.

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

    Default

    Well everything depends upon what the current value the user enters. So how about after you get the value and store it into v* why not do a few tests to see if it is a valid input and what happens next is determined by those tests. I gave you a capital hint in my previous reply.

    *you can actually do away with the v variable but lets not worry about that right now.

  5. #5
    bkim33 is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    I think i get where you are going so I got this so far but im still having the same issue


    I know this is such a simple problem but my brain is so fried right now from an exam I have tomorrow as well
    Last edited by bkim33; 02-11-2011 at 05:36 AM.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    You have four conditions and you have only handled one.

    1. If value is outside acceptible range
    2. If input is not an integer. Check with teacher if you need to handle this one.
    3. If current value is less than previous value
    4. Happy days - valid input so we can do stuff.

    Also, examine your if statement carefully. What happens if user enters -1?

  7. #7
    bkim33 is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    ok I made a lot of progress!! thanks a lot sir!

    I stil have the issue of the initial value of 50 if i enter something larger than 50 I will have issues..
    Last edited by bkim33; 02-11-2011 at 05:36 AM.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    Now you have handled 2 of the possible 4 situations. Keep going.

  9. #9
    bkim33 is offline Member
    Join Date
    Feb 2011
    Posts
    18
    Rep Power
    0

    Default

    I made a variable of count initialized to 0 above the while loop; under else part of the loop i put count ++; after the while loop i print out the variable sum but the loop runs twice and stops why is this happening?

  10. #10
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default

    My magic 8-ball says: "Cannot predict now"

    Do you think posting your lastest code might help?

Similar Threads

  1. Need some help with my homework.
    By JacobM in forum New To Java
    Replies: 11
    Last Post: 02-04-2011, 02:42 AM
  2. Homework help please
    By chick in forum New To Java
    Replies: 22
    Last Post: 03-19-2010, 07:39 AM
  3. Homework help
    By rclausing in forum New To Java
    Replies: 26
    Last Post: 11-24-2009, 06:06 AM
  4. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 03:37 PM
  5. Homework help...
    By robrobrob in forum New To Java
    Replies: 4
    Last Post: 10-17-2008, 04:24 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
  •