File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""dummy" code" Watch ""dummy" code" New topic
Author

"dummy" code

apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
I have written a "dummy" code, because i need to understand a concept, then apply it to other programs. So, help me solve this dummy code, it is not homework.
what i need is:
1. how to use a boolean properly.
2. use the object num in the tester // i dont know why it doesnt work.
3. make a do-while in the tester, so it will ask "enter a number" until the user enters a number greater than 10. if the user enters less than 10 i want the program to loop the question until done right.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18834
    
  40



A do-while expects a boolean expression. You are providing an int.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
i figured. however, i've tried many different options like
while(dido.getNum) // it doesnt read dido.
while( num ) // anything with num doesnt work. i know im close, but what am i missing to make this dummy code?? i need this concept so i can move on a bigger much bigger project.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi apollo,

What Henry's saying is important. Unlike c, java's zero is not equal to false. A Java while loop expects a boolean condition.

Thus, #1 is legal

1. while (dido.getNum != 0)

but #2 is not

2. while (dido.getNum)

The difference is that #1 is comparing a boolean condition is dido.getNum equal to zero, while #2 is trying to evaluate an number dido.getNum as a boolean: that just doesn't work in Java.

hth,
M
[ April 01, 2006: Message edited by: Max Habibi ]

Java Regular Expressions
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32

i dont really understand what you are saying. however, this code isnt working, i get an error: " cannot find symbol
symbol : variable dido
location: class Ktester
while(dido.getNum != 0);"
if its not asking too much, could you please fix the code so it works, then explain me what you did.
thanks for the support.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
Anything declared inside a set of brackets is only available inside those brackets. Declare dido above the do-while loop. Also read about scope, it is an extremely important concept and you will have nothing but frusterations until you understand it.

People already told you want you need, a loop condition requires a boolean value, not an integer.
[ April 01, 2006: Message edited by: Rusty Shackleford ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
Ok, thanks alot, i know now how to make the "dido" work so simple yet so complicated if you dont know.
now the problem i have is that the boolean is not doing what it is supposed to.

this is what i need to change:
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
i've got the problem to loop "enter number" if i enter a number less than 10 or greater than 10. however when i enter 10, the loop stops.

I guess the part that i dont understand is that my boolean method says that it if its greater than 10 is true and if its less then is false - in my mind, i understand this as if you enter greater than 10 well you end the loop correctly, but if you enter less than 10 the question "enter number" will be asked again. is that how it works?? and how do i make it work so if the user enters any number below 10 it asks again, and if it enters a number greater than 10 it end the loop.
phew, i hope you guys can help me. thanks.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
You can say


Incidentally, as far as naming conventions go, getXXX() usually implies a non-boolean return value. For booleans the convention usually isXXX() or hasXXX(). However these are just conventions and they can be (and frequently are) broken all the time. I only mention this because a more conventionally desciptive namr for your method might be hasGoodData()
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
I think i've found a solution, i was calling the wrong method!
apollo abel
Ranch Hand

Joined: Mar 31, 2006
Posts: 32
Originally posted by Garrett Rowe:
You can say


Incidentally, as far as naming conventions go, getXXX() usually implies a non-boolean return value. For booleans the convention usually isXXX() or hasXXX(). However these are just conventions and they can be (and frequently are) broken all the time. I only mention this because a more conventionally desciptive namr for your method might be hasGoodData()


LOL u beat me to it, thanks anyways, that was the solution, man it was right in front of me the whole time =D
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "dummy" code