Computer Science Canada hours to days and hours |
Author: | cool dude [ Fri May 12, 2006 7:53 pm ] | ||
Post subject: | hours to days and hours | ||
i am learning java so i'm making these little programs to get myself better at java. the reason i'm posting these so called programs is because i like criticism because i learn from it and can become a better programmer. i will start making a game and something bigger when i get more educated in java and when i have more time i.e. summer. for now here is my program. you enter #of hours and it will output #of days and hours.
|
Author: | Vertico [ Fri Jun 02, 2006 2:24 pm ] |
Post subject: | |
![]() |
Author: | HellblazerX [ Fri Jun 02, 2006 4:58 pm ] | ||
Post subject: | |||
Not bad, but you could do without some of those variables, seeing as you only call them up once. Like shour. Rather than storing the input into shour, and then converting the integer with that, you could just convert the input into integer form. Same thing with your hoursleft and days. You could just perform the functions inside the output parameter. So it would look something like this:
It just seems inefficient to have variables that only store values that will be used once. And good luck with your game. |
Author: | wtd [ Fri Jun 02, 2006 5:03 pm ] |
Post subject: | |
HellblazerX wrote: Not bad, but you could do without some of those variables, seeing as you only call them up once. Like shour.
Or if nothing else, you could limit the scope of that variable. I fear Turing genuinely cripples the mind with regards to scoping. |
Author: | HellblazerX [ Fri Jun 02, 2006 5:07 pm ] |
Post subject: | |
wtd wrote: Or if nothing else, you could limit the scope of that variable.
I don't mean to go off topic, but what's scoping of a variable mean? |
Author: | wtd [ Fri Jun 02, 2006 5:35 pm ] |
Post subject: | |
HellblazerX wrote: wtd wrote: Or if nothing else, you could limit the scope of that variable.
I don't mean to go off topic, but what's scoping of a variable mean? It is one of the most important fundamental concepts with which to become familiar. In cool dude's program, the variable "shours" is declared in the method's scope. It is now available to the entire method. The thing is... it doesn't have to be. It's only ever used in the "try" block. Therefore it can be scoped locally within that block. It will not be accessible outside that block if this is done. |