Why can't I use TextIO.getInt() for my simple age getting program?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
TextIO.putln("Hello World!");
TextIO.putln("What is your age?");
int age = TextIO.getInt();
TextIO.getInt();
TextIO.put("Your age is ");
TextIO.putInt(age);
}
}
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
A very warm welcome to the ranch. Mistakenly you put the code inside the quotes instead of code tags. Anyways, this is the right one:
What is TextIO class by the way? Never heard of it. Which package is it in?
~ Mansukh
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
also, saying "why can't i do XYZ" is kind of pointless. What happened when you tried it? Either the compiler or the JVM will tell you EXACTLY why you can't do it. you will have gotten some kind of error message. Post the full and complete text, and perhaps we can help interpret it for you.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I downloaded the TextIO class from here. So far as I understand, the TextIO class is primarily for input/output and is an alternative to System.in and System.out. The beginner java book I am reading (don't have the title on me) suggested that it has some advantages over Scanner.
The code I posted above is intended to get the user input (years old) and print out user's age. So long as I keep the variable a string my code runs fine, but when I try to make my 'age' variable an integer it fails to return my age to me after a carriage return during run-time.
I hope this reply is more sufficient for explaining my issue. Any help is much appreciated.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
~ Mansukh
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I google'd the TextIO.java class and looked at examples. In the examples I found, the author just used System.out.print for output and stuck to TextIO.java for getting user data. This was really my first attempt at problem solving in java and I hope it wasn't to painful for those of you that helped!
So thanks and bear with my posts in the future! -
-
Number of slices to send:Optional 'thank-you' note:
-
-
This was really my first attempt at problem solving in java and I hope it wasn't to painful for those of you that helped! So thanks and bear with my posts in the future!
No No! Not at all buddy. Don't ever hesitate to ask anything. We are all here to learn and help. So don't be formal.
I am using Eclipse and missed the what should have been obvious reminder about the syntax error.
If these are the first few of your tryouts at writing Java code, as you said, then my suggestion would be get rid of the IDE for now. Use a simple text editor to write the code yourself. Starting from package statements to imports, defining classes, methods instance variables etc. The reason is IDEs like Eclipse assist you with many things. So, you will never fully understand what is really happening under the hood. Write the code yourself in the editor, compile it and run from the command prompt. Make mistakes and get your hands dirty. Then you can home in on the exceptions and errors. It will not only teach you Java coding as such, but many other things that are a must know for a novice like classpaths, jar file issues etc.. Which book are you referring to by the way?
~ Mansukh
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Mansukhdeep Thind wrote:
I am using Eclipse and missed the what should have been obvious reminder about the syntax error.
If these are the first few of your tryouts at writing Java code, as you said, then my suggestion would be get rid of the IDE for now. Use a simple text editor to write the code yourself. Starting from package statements to imports, defining classes, methods instance variables etc. The reason is IDEs like Eclipse assist you with many things. So, you will never fully understand what is really happening under the hood. Write the code yourself in the editor, compile it and run from the command prompt. Make mistakes and get your hands dirty. Then you can home in on the exceptions and errors. It will not only teach you Java coding as such, but many other things that are a must know for a novice like classpaths, jar file issues etc.. Which book are you referring to by the way?
That's really a good suggestion, but it's applicable only for people with huge level of motivation (or rich experience with other programming languages), rest won't be able to get out of this "dirt" and abandon java at all. I personally started with Netbeans, and despite that IDE did 95% of work for me, there was a huge mass things that I need to learn first, besides classpaths, jar problems and starting jvm myself.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
About IDEs, I definitely see the advantage of them but as I'm working from a netbook for the time being it may make sense to take my first steps using Notepad or something less memory dependent than Eclipse.
The book I'm reading has been adapted to Android App form but seems to match what I'm seeing here.
I like the writing. Seems straight forward without talking down to me. Get what I mean?
Any thoughts or recommendations on reading material? I'm mostly interested in gearing up to write an Android app eventually.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I like the writing. Seems straight forward without talking down to me. Get what I mean?
You mean to say some authors talk down to people? Interesting viewpoint. I hope we don't fall in that category.

~ Mansukh
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'd like to find an IDE that is more lightweight than Eclipse to run on my slow netbook. Any suggestions?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'd like to find an IDE that is more lightweight than Eclipse to run on my slow netbook. Any suggestions?
Try either this or this one here. Let me know how each one fares.
~ Mansukh
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Campbell Ritchie wrote:Probably better to go back to the command line.
Hardcore. But if OP has such a rich experience as working at machine workshop, so he knows nuts and bolts of computers, I suspect he can prefer that way. Please put me right if I'm wrong.
@OP: try Sublime text editor, I like it.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Campbell Ritchie wrote:you have to put so much effort into learning the IDE, which would be better used for learning Java
You will have to learn to use IDE anyway. But I agree that if you plan to go deep into java it's better to start from fundamentals.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Jayeemsuh Allen wrote:I checked out both DrJava and JEdit and I'm going to give DrJava a try for a little while.
That's all "noname" IDEs to me. I've never used any of these before and didn't even hear any suggestions to start using it.
If you plan to start with IDE, it would be wiser to invest your time in learning popular and proven IDE.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
That's all "noname" IDEs to me. I've never used any of these before and didn't even hear any suggestions to start using it.
If you plan to start with IDE, it would be wiser to invest your time in learning popular and proven IDE.
Noted! As I mentioned though, the hardware on my netbook is pretty meager so I need something pretty lightweight. I'm using DrJava for now and it seems to be doing the trick for compiling and running simple input/calculate/output type programs. That's mostly all I'll be doing for the time being. Maybe I'll upgrade my PC and IDE once I get some more experience.
On a somewhat unrelated note, I'm looking to read up on conventions for style and specifically how to form good habits with indentation. I'd like to start these habits early and have them stick. Any suggestions on where I can learn this sort of thing?
Here is some code that I'm looking to practice on:
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Do you really need these uninitialized vars? Is it really needs to be double instead of float, int instead of short (byte)? Can you opt out of TextIO custom class, to make folks from the ranch understand the code?
Personally I like to stick to standard APIs to show the code (otherwise dependent I need to share dependent classes).
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
That is not at all a good suggestion; floating‑point arithmetic is done with doubles as a default and integer arithmetic with ints. In the days when memory was expensive, it might have been worth being economical with it, but that has not been the case for, probably, twenty years.surlac surlacovich wrote: . . . Is it really needs to be double instead of float, int instead of short (byte)? . . .
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
TextIO appears simply to be a utility class which writes things to the command line and reads from it. Its methods have simple names, so we can easily work out what they mean.surlac surlacovich wrote: . . . Can you opt out of TextIO custom class, to make folks from the ranch understand the code?
Personally I like to stick to standard APIs to show the code (otherwise dependent I need to share dependent classes).
Agree it would be better to write your own utility class for text input and simply use System.out and System.err for output, but OP specifically said he wanted to use TextIO.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Agree it would be better to write your own utility class for text input and simply use System.out and System.err for output
Sadly, I don't even know what a utility class is but I'll look into it. I did take a quick look at Scanner and how it is used for simple input/output. I used it successfully, but I am drawn to the simplicity of TextIO for the simple needs I have now.
That is not at all a good suggestion; floating‑point arithmetic is done with doubles as a default and integer arithmetic with ints. In the days when memory was expensive, it might have been worth being economical with it, but that has not been the case for, probably, twenty years.
Interesting! I simply used type double and int because they were used for variables with similar purposes in examples that I saw.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
| WARNING! Do not activate jet boots indoors or you will see a tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |










