# Pipe Graph Loop?

• November 1st, 2011, 02:36 PM
macko
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..

Code :

```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?
• November 1st, 2011, 02:59 PM
Tjstretch
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
Code Java:

```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:
Code Java:

```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)
• November 1st, 2011, 03:02 PM
macko
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.
• November 1st, 2011, 03:59 PM
macko
Re: Pipe Graph Loop?
Does'nt wanna read the for loop :( grr frustrating hehe.. final part of the job to :P will keep trying different things
• November 1st, 2011, 04:42 PM
KevinWorkman
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!
• November 1st, 2011, 04:53 PM
macko
Re: Pipe Graph Loop?
bahaha what country you live in? ill see if i can organise a post card :P and dont worry bout the code for the time being.. bout to goto college.. my programming teacher is teaching his networking class :P 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 ;)
• November 1st, 2011, 04:59 PM
KevinWorkman
Re: Pipe Graph Loop?
Quote:

Originally Posted by macko
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.
• November 1st, 2011, 10:15 PM
macko
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.
• November 2nd, 2011, 06:57 AM
KevinWorkman
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.
• November 2nd, 2011, 03:30 PM
macko
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
• November 2nd, 2011, 07:41 PM
KevinWorkman
Re: Pipe Graph Loop?
Quote:

Originally Posted by macko
:| 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.
• November 3rd, 2011, 07:13 AM
macko
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 :D

and yes you could call me lazy :P
• November 3rd, 2011, 07:48 AM
KevinWorkman
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?
• November 3rd, 2011, 07:54 AM
macko
Re: Pipe Graph Loop?
Meh i'd just use the nifty replace feature in eclipse :P

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 :P
• November 3rd, 2011, 07:58 AM
KevinWorkman
Re: Pipe Graph Loop?
Quote:

Originally Posted by macko
Meh i'd just use the nifty replace feature in eclipse :P

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 :P

Fair enough, then I'll stop bothering. But I used that example exactly because the "replace" feature won't work.
• November 3rd, 2011, 08:03 AM
macko
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 :P the client only wants it to WORK doesnt care how it runs lol