Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Top Posters

Who's Online (0)

Powered by Vanilla. Made with Bootstrap.
Can you help me in my program?
  • Imagine that you have 2 jugs, a small one and a large one, with integer capacities of sCap and lCap gallons,
    respectively (sCap < lCap).

    1. Initially both jugs are empty.
    2. You are allowed to completely fill each jug from a tap, or empty them on the ground.
    3. You can also pour one jug into the other: pouring stops when either the receiving jug is full or no water is left in the pouring jug (i.e. no water is spilled).
    4. Note that each pouring action will cause a positive number of whole gallons to be transferred.
    5. Given the final state of the jugs, the problem is to find a valid sequence of actions such that after performing the actions, the small and large jugs show exactly the final state given.
     
    Input: capacity of jug A, capacity of jug B, desired output
    Output: current state of the jugs, steps in solving the problem
     
    Important: Your group must use RECURSION in solving the problem.
    Bonus: Implement a three jug problem.
     
    Sample run:
     
    Enter capacity of jug A:  10
    Enter capacity of jug B: 3
    Enter the goal: 4 0
     
    A      B
    ---------
    10    0   :  Fill A
    7      3    : Pour A to B
    7      0    : Empty B
    4      3    : Pour A to B
    4      0    : Empty B
     
    Sample run:
     
    Enter capacity of jug A: 5
    Enter capacity of jug B: 3
    Enter the goal: 2 0
     
    A      B
    ---------
    5      0   :  Fill A
    2      3    : Pour A to B
    2      0    : Empty B
     
    Sample run:
     
    Enter capacity of jug A: 5
    Enter capacity of jug B: 3
    Enter the goal: 1 0
     
    A      B
    ---------
    0      3   :  Fill B
    3      0    : Pour B to A
    3      3    : Fill B
    5      1    : Pour B to A
    0      1    : Empty A
    1      0    : Pour B to A
  • Phage
    Posts: 78
    I have absolutely no ideea about what you are doing? Please add some more information.
  • Sh3llc0d3
    Posts: 1,910
    Can you not edit your post and format the code properly?
  • looks like a homework copypaste.. try putting some effort in first before asking for help, and when you do that, you might want to put some effort into your post too, i mean; letting us know where you are struggling to solve your problem specifically. no-one is going to do your homework for you, or at least i would hope not D:
  • m0rph
    Posts: 332
    Sorry, forgot to mention that I took out all of the stuff he was trying to put into this post. It's formatted as properly as I could make it.
    while( !(succeed = try() ) );
  • Sh3llc0d3
    Posts: 1,910
    Yeah I agree with above, does look like a homework/coursework type project.
  • yes, it is a homework from my programming subject.my problem is i dont know how to program it using java creator,but i know how it works in algorithm..

    sorry for the format,

    this is the output of my program.. node the java code itself..

    Please do not triple post. Thank you. -m0rph
  • Hey,
    ReverseEngineering


    If You are Learning  to design some Shopisticated
    algorithm I Highly recomeds you to search for Java Source code example...