The Big Programming Thread - Page 109
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
fabiano
Brazil4644 Posts
| ||
woozie
Sweden53 Posts
On January 22 2012 14:07 fabiano wrote: looks like milesTraveled doesnt exist in the class scope, it only exists in the button1_Click method. Make the milesTravelled an attribute to the class you are working with. How do I make it an attribute to the class I'm working with? Edit: I managed to make it work. Thanks for the help. | ||
Warri
Germany3208 Posts
Basically i want a loop to be run permanently and have it paused/resumed when i press a button. I have created a new thread for the loop public class loop extends Thread{ public void run(){ do while } } and initialize it in the main(); (in another class) public static void main(String[] args) { Thread thread1 = new loop(); thread1.start(); } Now, ive read that to make the thread pause i should use thread1.wait(); and thread1.notify(); but i just dont understand how to implement the keylistener in main(); | ||
freelander
Hungary4707 Posts
If you just start out learning about threads I don't recommend that, because the GUI starts its own threads. So it gets a bit complicated. I recommend putting the sleep in your run() method in the loop class: public void run(){ while(true){ sleep(); "Someone pressed A"; } } | ||
Warri
Germany3208 Posts
^that would mean it would only pause once every cycle of the loop, which can be quite long. I need it to pause immediately when i push the button. | ||
Kentor
![]()
United States5784 Posts
On January 20 2012 12:59 D4Lorg wrote: hey, today at work ive been thinking, what are each languages respective "bibles". C is obviously the K&R and C++ is arguably C++ programming language by stroustrup. anyone know any others? maybe "the rails 3 way" for rails and "programming perl" (o'reilly) for perl? Ruby is The Ruby Programming Language by Matz | ||
divito
Canada1213 Posts
If anyone is looking for some material outside of physical books or websites with reviews, I'd be more than happy to share them; just send me a PM with your request. | ||
billy5000
United States865 Posts
While I do understand how the conditionals and loops work in such examples, I just can't seem to figure out the steps in between. I'm not even sure if we're supposed to understand it either. For example: http://introcs.cs.princeton.edu/java/13flow/Sqrt.java.html http://introcs.cs.princeton.edu/java/13flow/Binary.java.html http://introcs.cs.princeton.edu/java/13flow/Gambler.java.html Like I understand what they do and how they are processed. But I'm not sure if we're supposed to have a deeper understanding, as if we're supposed to recreate a similar program to a particular example. However, even if we don't have to know exactly how everything's in place, I'm really curious as to how. The book doesn't really go in depth other than the fact that they have conditionals and loops. Can anybody tutor me? i get the concepts that we cover in class, but these examples have a deeper understanding that I can't seem to grasp w/o help. and that deeper understanding is what I'm trying to get. if someone can offer a hand as a regular tutor just explaining how example-specific programs work throughout the semester via pm or w/e, that'd be great. excuse my writing, it's 6 am here and we just had a tornado drill sometime around 4am which is why i am still awake, and holy shit my first 10am class prof just emailed me saying that class is cancelled as i have been typing this tldr; I need a tutor who can help me throughout this semester for intro to programming in java. i went to some tutor sessions offered by my class, but they tell me that i don't need to know these stuff in-depth and acts like i'm a regular cs noob in need of noob type help. i have example-specific questions like the ones above. All of the examples are off this site: http://introcs.cs.princeton.edu/java/10elements/. | ||
ranshaked
United States870 Posts
for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this: I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements? This is all in basic C Thanks <3 | ||
RoyGBiv_13
United States1275 Posts
What the f*&% is up with heap allocation? If you ever wonder how your variables actually get stored in memory, take a look at the unix malloc/free implementations. protip: its easily too complicated for one person to comprehend all of what is going on. | ||
morty
Germany38 Posts
![]() lvl 8 begginer at the moment : Online Version: http://www.trybloc.com/courses/ruby-warrior/chapters/beginner#/1 Download: https://github.com/ryanb/ruby-warrior/ | ||
![]()
MisterD
Germany1338 Posts
On January 24 2012 04:17 ranshaked wrote: Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3. for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this: I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements? This is all in basic C Thanks <3 try to rephrase your question, i have not understand what your problem is at all. | ||
green.at
Austria1459 Posts
On January 24 2012 04:17 ranshaked wrote: Hi guys! I'm stuck right now. I have to create a count that basically says "when it's true increase by 1" and stop once it hits 3. for(i=1;i<=num;i++) I have something like that, but I'm not sure exactly how it works. The jist of the problem is this: I have several if statements, which tell when a STATE will win in the electoral college. The last part I need to printf a statement that says "Your candidate can win in X ways" X ways will be the count. The program is running perfectly well, but I do not understand the counts. Do I have to put a count inside the IF statements? This is all in basic C Thanks <3 if it is working perfectly fine and you just dont get it, why not debug it step by step? do you not unterstand the for() loop? oO edit: and what MisterD above wrote ^^ edit2: is it that you do not know where to put the counter? if so you might have to post that part of your code | ||
ranshaked
United States870 Posts
On January 24 2012 08:30 green.at wrote: if it is working perfectly fine and you just dont get it, why not debug it step by step? do you not unterstand the for() loop? oO edit: and what MisterD above wrote ^^ edit2: is it that you do not know where to put the counter? if so you might have to post that part of your code I'm afraid to post it because it is homework and I'm not sure if they would consider that cheating? Your candidate wins if he/she wins Florida. Your candidate wins if he/she wins Indiana. Your candidate wins if he/she wins Florida and Indiana. Your candidate can win in 3 number of ways. Those are the outputs for instance. I can get the first 3 outputs, but the last one "Your candidate can win 3 number of ways." isn't working. From what I understand I need to use a count in order to produce that output. //Calculations //int value; is this the right way to set it? if (FIRSTSTATE+FIRSTCAN >= 270) printf("You will win the election if you win %s.\n", &STATE1); //value++ would it go like this?} if (SECSTATE+FIRSTCAN >= 270) printf("You will win the election if you win %s.\n", &STATE2); if (FIRSTSTATE+SECSTATE+FIRSTCAN >= 270) printf("You will win the election if you win %s and %s.\n", &STATE1, STATE2); else if(FIRSTSTATE+SECSTATE+FIRSTCAN < 270) printf("You cannot win this election even if you win %s and %s.\n", &STATE1, STATE2); //printf("Your candidate can win %d ways.\n", &value); not sure exactly how to use ++value etc.... Here is the math part, basically I'm unsure of what to put within this section to get it to count if the "if's" pass. If it passes the first if, it will mean that you can win with just the first state and so forth. I can PM the entire code if you want to test it. We haven't been taught how to "debug" yet aside from inserting printf's and testing line by line. I'm using Dev C++ compiler I hope this helps a little. | ||
chiboni
15 Posts
On January 24 2012 11:48 ranshaked wrote: I'm afraid to post it because it is homework and I'm not sure if they would consider that cheating? Those are the outputs for instance. I can get the first 3 outputs, but the last one "Your candidate can win 3 number of ways." isn't working. From what I understand I need to use a count in order to produce that output. Here is the math part, basically I'm unsure of what to put within this section to get it to count if the "if's" pass. If it passes the first if, it will mean that you can win with just the first state and so forth. I can PM the entire code if you want to test it. We haven't been taught how to "debug" yet aside from inserting printf's and testing line by line. I'm using Dev C++ compiler I hope this helps a little. So you want to count if one of the '>=270' conditions is true. You have it almost solved!! //initialize counter variable int counter = 0; // <- always initalize variables with an value //if this is true, increment counter by 1 if(...>=270) { printf(...); counter++; //<- you could also write it as 'counter = counter + 1;' or 'counter =+ 1' } //next condition and so on ... //print value of counter printf("...%i", counter); | ||
ranshaked
United States870 Posts
![]() DUN DUND DUN. I love this stuff. It's making my mind hurt. I'm glad I won't need this in my degree, but it's nice to know. Thanksss | ||
Adeny
Norway1233 Posts
On January 25 2012 00:13 ranshaked wrote: I got the count working ![]() DUN DUND DUN. I love this stuff. It's making my mind hurt. I'm glad I won't need this in my degree, but it's nice to know. Thanksss + Show Spoiler + I don't know which language you're working in but the user input is probably a string, and you're probably trying to shove it into an int. You need to look up int-parsing or -casting, depending on language. | ||
![]()
tofucake
Hyrule18975 Posts
| ||
WerderBremen
Germany1070 Posts
| ||
![]()
tofucake
Hyrule18975 Posts
| ||
| ||