[Java] Smart Haggle

Discussion in 'Code Snippets and Tutorials' started by Zer0, Jan 19, 2009.

  1. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    Heh, I made a very simple, very concise smart haggle for Java. Only 3 lines long not including the code for the function :)

    Code (Text):
    1. private String haggle( String price ) {
    2.     String s = price.substring( 0, 2 );
    3.     while( s.length() < price.length() ) s += s;
    4.     return s.substring( 0, price.length() );
    5. }
     
  2. cooldude255220

    Joined:
    Jan 25, 2009
    Messages:
    12
    Likes Received:
    0
    how do you use this?
     
  3. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    You put this in a Java program, and you'll be able to use this method to convert any String price into a smart haggled price.
     
  4. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
    This is more convenient for you, but also, this prevents icings a lot more although I don't know how efficient this one is.

    TNT is cracking down on all kinds of sh*t especially when it is publicized like this. Anyways, thanks for the code, I stink at programming so I'll fail, lolz.
     
  5. Sapphire

    Sapphire Level II

    Joined:
    Jan 13, 2009
    Messages:
    229
    Likes Received:
    25
    Location:
    Chi Chi
    i think, this code can be use for monkeygrease as well right?
     
  6. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    Of course, you'll just need to modify it a bit to meet GM syntax