Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By JosAH

Thread: Need help on this program logic

  1. #1
    cotemaria is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default Need help on this program logic

    Hello,

    I am really looking for help on this program as I felt its tough program... Please help me out on this program as I am very new and this is first time I am taking Java course...

    Many Thanks,

    Maria

    Here is the program question...

    A student decided to celebrate thanksgiving break early by getting a bit smashed... Here home is at corner 0 on the main street, and the jail is at corner 10 on main street. The student starts at corner 5 and wanders one corner to the left or to the right with probability of 0.5 for each. She repeats the process until arriving safetly at home or landing in jail. That is at each corner, the drunk student has a 50-50 probability of staggering left or right, to the next high numbered or next low numbered corner.

    Write a method named dunkwalk() using a while or a do while loop that simulates student walk. The program should print whether she arrives at home or jail and have it return how many steps it took.

    Program output will look like in action with N equal to '5'

    Here we go again........time for a walk!
    Took 37 steps and
    Landed at HOME

    Here we go again.........time for a walk!
    Took 19 steps , and
    Landed at JAIL

    Here we go again.........time for a walk!
    Took 13 steps, and
    Landed in JAIL

    Here we go again........ time for a walk!
    Took 25 steps and
    Landed in JAIL

    Here we go again.......time for a walk!
    Took 15 steps and
    Landed at HOME

    Average # of steps equals 25.4

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: Need help on this program logic

    Have you tried anything yourself yet?

    kind regards,

    Jos
    Fubarable likes this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. need help in merging GUI and logic main program
    By lavender88 in forum NetBeans
    Replies: 2
    Last Post: 04-02-2011, 01:28 PM
  2. Need help on logic
    By nn12 in forum New To Java
    Replies: 6
    Last Post: 03-10-2011, 11:06 AM
  3. need a logic for this
    By rajivjoshi in forum New To Java
    Replies: 4
    Last Post: 06-12-2010, 02:18 PM
  4. Separating program logic and GUI
    By loopingman in forum AWT / Swing
    Replies: 0
    Last Post: 12-08-2008, 02:46 PM
  5. Cant get the logic right
    By jermaindefoe in forum New To Java
    Replies: 4
    Last Post: 03-11-2008, 12:22 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
  •