Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: Pipe Graph Loop?

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Pipe Graph Loop?

    Hmm now wondering if there is an easier way to do this.

    Now ive got the doubles as the scores of each line..

    now the max score can be 6.0
    the min score is -6.0

    i guess i want to add the pipes to the end of the line..

    0.1 score is equal to 1 pipe..

    instead of going:

    if(score[m] == 0.1){
    Out.println("                                                            |");
    }
    else if(score[m] == 0.2){
    Out.println("                                                            ||");
    }
    else if(score[m] == -0.2){
    Out.println("                                                           ||");
    }
    etc.. is there a easier way of doing it. The graphs go like this. the blank space before the start is the 60 negative scores.. if its negative the bottom 1 will show how it goes.. the opposite direction to the positive..

    so is there an easier way?


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Pipe Graph Loop?

    How do you have negative pipes? Anyway, I would recommend convert the double scores to int pipes.
    Create a seperate method for printing number of pipes.
    Call print() rather than println, inside your method, that will probably give you your solution.

    Difference between print and println
    System.out.println("||");
    //is the same as
    System.out.print("|");
    System.out.print("|");
    System.out.println();
    //Which allows for easy looping
    Or if you don't want to use that type of loop, save it to a string variable and than print that variable. This however may cause the program to slow down a tad
    Example:
    public static void printPipes(double score)
    {
      //You should probably check to see if the score is less than -6 or greater than 6
      int pipes = (int)score*10;
      //for loop, printing one | per pipe.
    }

    The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    thanks. And the negatives are posted backwards. you have say a time line. -------.------- where the . is equal to 0. if the score is negative it will post backwards hence meaning positive frontwards.

  4. #4
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    Does'nt wanna read the for loop grr frustrating hehe.. final part of the job to will keep trying different things

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Pipe Graph Loop?

    A for loop seems like the way to go. Where is it stuck? Post an SSCCE (similar to what I posted in your other thread), and we can maybe go from there.

    PS- We're getting a cut of the money you're making on this, right? Heck, I'd love a postcard from Australia!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    bahaha what country you live in? ill see if i can organise a post card and dont worry bout the code for the time being.. bout to goto college.. my programming teacher is teaching his networking class cuz i study 2 colleges.. n his other job is this networking course.. gunna anoy him see if he can give me a hand.. so will let u know later if its fixed..

    send me your country and ill try find out costs to send ya a pc

  7. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Pipe Graph Loop?

    Quote Originally Posted by macko View Post
    send me your country and ill try find out costs to send ya a pc
    I live in the US!

    But for the code, once again I agree completely with Tjstretch's hints.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  8. #8
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    Yes my teacher was no help, Heh told me to come back after half hour but wanted to get home.

    Got to go meet with this client and get the payment, and other details out of the way shortly...

    I'm still not sure how

    int pipes = (int)score*10;


    would work though. Isn't that just like saying multiply the value of score by 10 or is that simply the way to remove the decimal point? to make it into an integer.

    Could you post abit more of an example mate?

    I'm still brain dead how to post 1 pipe per .1

    if not give me a tutorial i can have a little read on about declaring .1 equal to 1 pipe.

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Pipe Graph Loop?

    What I would do is draw a bunch of these out by hand. If the score is .3, how many pipes are on the left, how many are on the right? What about .4, .5, .6? You should start to see a pattern, and then Tjstretch's suggestion will make more sense.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. #10
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    due to my all nighter.. i passed out at 5pm had 12 hr sleep haha.

    I'm thinking of doing it dodgy.. like jus do it manualy if score(3.0) post 30 blank spaces b4 i start that pipe for positive.. doesnt matter really as long as it works lol... i aint bothered got 1 week to do it xD

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Pipe Graph Loop?

    Quote Originally Posted by macko View Post
    due to my all nighter.. i passed out at 5pm had 12 hr sleep haha.

    I'm thinking of doing it dodgy.. like jus do it manualy if score(3.0) post 30 blank spaces b4 i start that pipe for positive.. doesnt matter really as long as it works lol... i aint bothered got 1 week to do it xD
    Like I said, if you draw a bunch of these out, you'll start to see a pattern. Use that pattern to your advantage.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  12. #12
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    Yep you're right, Although as i said it doesn't matter either way you do it.. either figuring out the quicker syntax to use or making the code alot longer then it has to be.. Although making it longer will of course take more time although if you know what your doing it wont really matter and since the job will be getting $$ out of it..

    I do not mind spending another 10 or so minutes on the syntax

    and yes you could call me lazy

  13. #13
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Pipe Graph Loop?

    That's not the only benefit of figuring out the pattern. Down the road, you might want to change the program- let's say in addition to the line, you want to add the score. With your "lazy" approach, you're going to have to make changes in ten different places every single time you make one little change. With "my" approach, you'd only have to make one change- now which way seems like less work?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #14
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    Meh i'd just use the nifty replace feature in eclipse

    replace | with - hehe solve your problem?
    and yes, I agree with you if the program is my own then of course i would be updating it quiet frequently.

    Although for this job ive got the attitude of "Just get it done" LOL.. wont be changing it at all

  15. #15
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Pipe Graph Loop?

    Quote Originally Posted by macko View Post
    Meh i'd just use the nifty replace feature in eclipse

    replace | with - hehe solve your problem?
    and yes, I agree with you if the program is my own then of course i would be updating it quiet frequently.

    Although for this job ive got the attitude of "Just get it done" LOL.. wont be changing it at all
    Fair enough, then I'll stop bothering. But I used that example exactly because the "replace" feature won't work.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  16. #16
    Member
    Join Date
    Mar 2011
    Posts
    198
    My Mood
    Daring
    Thanks
    7
    Thanked 4 Times in 4 Posts

    Default Re: Pipe Graph Loop?

    Probably won't be to difficult to work out syntax for the easier method tho..

    for(int i = -30; i < 31; i++){
    //CODE here to display 1 pipe per 0.1 && position of start...
    }

    I'd just have to have a walk, come back with a fresh mind, a smoke, a coffee, sleep and have a think LOL.. but tbh the amount of work ive had for past week is over stressful.

    It's why i'm not bothered about the easier approach lol.. but as i said of course id do it for my own task the client only wants it to WORK doesnt care how it runs lol

Similar Threads

  1. send image file from java to php broken pipe exception occured
    By ashi123 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 21st, 2011, 02:53 PM
  2. sudoku using graph coloring algorithm
    By priyank in forum Algorithms & Recursion
    Replies: 3
    Last Post: April 21st, 2011, 02:22 PM
  3. Java Bar graph takes user input to create graph?
    By kenjiro310 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 31st, 2011, 07:37 AM
  4. How to make a graph like this
    By sugarhigh in forum AWT / Java Swing
    Replies: 1
    Last Post: August 27th, 2010, 09:05 AM
  5. Replies: 1
    Last Post: October 7th, 2008, 07:35 AM