Well I am stuck on how to do this..
I know I need something like
System.out.println("Do you want to enter more pets?");
System.out.println("Enter y for yes, or n for no.");
answer = SavitchIn.readLineNonwhiteChar();
} while ((answer =='y') || (answer =='Y'));
But I'm not exactly sure where to put it. I know my code so far, only lets you input five pets at a time, and I did that on purpose....but now I want them to be able to enter any number of pets.
Can you give me some hints...and remember...talk in small talk for me...I'm not that well versed yet with Java.
Thanks a million!!!
Around and around you will go until the user answers NoLetMeOut, upon which the loop terminates.
Hope that helps!
and remember...talk in small talk for me...I'm not that well versed yet with Java
That's okay. I'm not that well-versed in Smalltalk.
I have seen your posts on this message board several times in the past and I admire the effort you are giving towards learning how to program in Java. I admit that it is a challenging task at times. However, I wonder if there is something missing in your learning process. I find it helpful to understand when to use certain tools. For example, I'm sure you have learned about the basic control structures that are available in Java such as if statements, for loops, and while loops. However, it's not enough to know that these tools exist. You also need to be intimately familiar with the kinds of situations that warrant there use.
In this case, you describe in your original post a situation where you need to repeat something over and over again. To me, this just screams "LOOP!" That's still not quite enough information, though, because Java has two different types of loops: for and while. Typically, you use a for loop when you know EXACTLY how many times the action is repeated; it stops after a certain number of repitions (or iterations). On the other hand, a while loop uses some situation arises that determines when to stop looping. So this implies that, since you don't know how many times to repeat, that you need to use a while loop.
My point here isn't to just answer your question directly, as you can see by my rambling. I hope you can make some effort to understand when it is appropriate to use each of the tools that you learn about while you learn about programming computers. If you can do this then you will find that learning other programming languages will be much, much easier. As much as I like Java, I would be willing to bet that other languages will come along to replace it. This means that learning how to learn a programming language is much more important than just learning the language itself.
1)Learn to use the API.
2)Create a program on your own, find something you're interested in and create a program for it. If you love to cook you could do a recipe program, or you could do a simple banking program, or even a program that keeps track of your favorite TV shows or something. The point is sometimes by only doing your school/book assignments you just do whatever is needed to complete the assignment and don't think that deeply about what your doing, or more importantly why your doing it.
3) This forum is wonderful place, but if you use it as a crutch to answer every question you don't really learn to think and find things for yourself.
4) Learn to think as a programmer in everyday life. It may sound stupid but while you're driving to school or work or whatever imagine you're in a program. If I turn left here this happens, else I keep on the same path. While I have my foot on the gas my going forward loop continues. For every mile I go I get one mile closer to having to fill my gas tank. Programming is all about decisions, everything else is just syntax.
Keep working at it, you'll get there.
Originally posted by Hentay Duke:
4) Learn to think as a programmer in everyday life.
All good advice from Hentay and Layne both. And these things go for just about any programming language, not just Java.
I'll add a corollary to #4:
5) Learn to think as a human in programming life.
In other words, if you had to do the problem yourself, or (better yet) if you had to tell someone else how to do it, rather than get a computer to do it, what would you do? What sort of instructions would you write down? I recommend imagining a really, really dumb intern.
Or, as Peter Halpern once put it, "if you can't write it down in English, you can't code it."
Did you take an algorithms class before jumping into Java? This question is so common that many (if not all) algorithm books cover it in some detail.
I wish so badly that I had more time to just spend with my programming, I honestly, truly love programming, but it's so hard to concentrate on just that, when I have four other classes to study for too. That's what keeps me from learning as much Java as I need to. My classes this semester, all of them, require a great deal of study. Not an excuse, just the facts.
Trust me, I wake up at night, and think to myself, "Oh, I'll try this in the morning to see if it will work". Programming fascinates the heck out of me. I haven't learned the API thing to tell you the truth. Actually, I had never even heard of it, till you guys mentioned it on here one day. I've got to teach myself how to use that.
I do understand my program needs a loop, I just have a hard time figuring out how to actually code that where it belongs, without getting some type of syntax error.
I figured out something yesterday on a program just by trying different things until I made it do what I wanted it to do, and I was very proud of myself!!
As far as my school assignments go. I ALWAYS want to do more than what the assignment asks for. I can see all kinds of improvements to the assignments, that I believe could be made, it's mainly the time thing that hinders me.
And yes, I agree, it's nice to write pseudocode or some type of code in 'dummy terms', so that any idiot could write the program.
I thoroughly believe in great instructions for any type of job, with no pieces left to figure out.
I try not to use this forum as a crutch....I just love to get feed back, hints as to what I am doing right or wrong. I want to write the programs myself and figure them out, but I have found that two heads are better than one, and one programmer might see a great way of doing something better than you had coded, and vice versa. I love learning from others, especially if they know the language well. They can always teach me things.
I love to teach myself. Strange as it may seem, actually sometimes 'I' have shown my class mates how to do something, whether it be in Java, Visual Basic.NET, or other languages I have learned.
You can learn so much from others.
I tried to answer all of you in one post. Sorry for the delay in my response....had to go to a funeral today out of town, and it's now 4:30, and I am just now getting to work. I'll be here till 9 Pm....Ouch!!!
Thanks for all your comments!!!
Trust me, I wake up at night, and think to myself, "Oh, I'll try this in the morning to see if it will work".
Heh, I've done that so many times. I hate it when I wake up in the morning and forgot my brilliant idea. I used to have a notebook or paper by my bed so I could write something down to help me remember. Unfortunately, I got out of the habit of doing that.
Also, I DEFINITELY understand the time constraints. I'm not very good at managing my time and often my OTHER classes suffer because I really get into a programming project.
Well good luck with your further coding endeavors and come back with more questions. I hope I didn't come off like we won't answer them. We certainly will, although maybe not in the way you expect.
Thanks for all of your help!!! It is truly appreciated!!! I haven't put a notebook beside my bed yet, but I think I will.
Good Luck and keep coming back with questions. I always enjoy your posts because you always seem to have a smile on your face!
Thanks for your post. I always read everyone's advice and try to look on the bright side of it all. I do appreciate everyone's help.
Thank you all so much!!!
I'll keep at it, and see where it takes me. It's time to go home for the day, so everyone have a great weekend.