• Post Reply Bookmark Topic Watch Topic
  • New Topic

TextIO vexations  RSS feed

 
Clemz Chins
Greenhorn
Posts: 10
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys. I a brand new Java student using Netbeans 8.2. I recently ran my first program, the typical 'Hello World' type of program. Well, now, my class has progressed to the point of having to read files and get user input. I am not quite sure how to incorporate TextIO into my code. Do I add it in a 'Source Packages?" If so, How do I do that. I notice that there is an order here which goes like this:

Name Of Project
            Source Packages
                     project.name.name
                                ProjectName.java

Of the above, the .java 'file' contains the main class and it is where my source code goes.

The question then is- where would I place TextIO if I am to import it?
Secondly, do I need Scanner to read files from elsewhere with Netbeans 8.2?

Thanks in advance for setting me up straight. I'm in a state of mild exasperation.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

You'll need to give more details. What is this TextIO you're talking about?  You can't assume that we know what it is. Is it a class? Is there a JAR file that was provided by your instructor?
 
Clemz Chins
Greenhorn
Posts: 10
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to my the book that my class is using, the author defines it as: I've written a class named TextIO that defines subroutines for reading values typed by the user. The subroutines in this class make it possible to get input from the standard input object, System.in, without knowing about the advanced aspects of Java that are needed to use Scanner or to use System.in directly. TextIO also has a few other capabilities that I will discuss later in this section. It is found here http://math.hws.edu/javanotes/c2/s4.html

My professor say: You must use TextIO methods to read the file. As you read the file.

The file is a .txt file that he gave us to create a program that reads it and calculate amounts of items on the list sold and other things like that.

Can I attach the problem here? I'm new here so I'm trying to figure the buttons out.
 
Liutauras Vilda
Sheriff
Posts: 4926
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clemence Chinyani wrote:I'm in a state of mild exasperation
Maybe it isn't too late to drop the course of this discipline? A bit with irony, but, you just started. Seriously, where this exasperation comes from?

1. What google search results gave after you typed in "How to get user input in Java" ?
2. And later "How to read file in Java" ?

The point I'm making is, that probably lots of people here won't mind to answer or hint you, but you'd do a lot more for yourself if you'd research first and then would ask some more specific questions.
That would give members some hints that you really spent some time before you got "exasperated".
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to attach anything. What you do need to do is read through your course materials more thoroughly. I followed the link you provided and in Section 2.4.2, fourth paragraph there is this:
To use the TextIO class, you must make sure that the class is available to your program. What this means depends on the Java programming environment that you are using. In general, you just have to add the source code file, TextIO.java, to the same directory that contains your main program. See Section 2.6 for information about how to use TextIO.

Now, I just did a lot of your work for you. you should read that paragraph carefully and follow the instructions given.
 
Liutauras Vilda
Sheriff
Posts: 4926
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Clemence Chinyani wrote:It is found here http://math.hws.edu/javanotes/c2/s4.html
And if you'd have looked at it - you'd have noticed that there is written code for you, you just need to use it. Examples how to use it are there too as far as I understand.

Probably professor made a mistake that did that (wrote code for students), it seems that isn't even enough. I'd suggest start by reading this website you posted.
 
Clemz Chins
Greenhorn
Posts: 10
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right on, I realize that. Well, let me have a crack at it then.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

A lot of courses use a ready‑made IO class to start their students off, because it can be awkward to write one's own IO code as a beginner. Please search this forum, in case somebody else has had to use the same class. We are not familiar with it. Please post a copy of the instructions you were given about that class.
You might be provided with a simple .class file, in which case you need to know more information about it. There is one trick you can use:-
  • 1: Put the .class file in a folder somewhere.
  • 2: Use the following instruction at a command line in the same folder:
    javap -c TextIO
  • 3: Copy and paste the first 4 lines of the output. The important information will be on the 2nd or 3rd line: the official name of the class.
  • This is an example of a little class I wrote to test this technique:-From a different location:-Most of the output is omitted. You will still get what you need if you omit the -c tag. It is line 3 in the first printout and line 4 in the second that contains the information you need.
    If you were provided with a .jar file, you will need to save it in some easily accessible location and add it to your CLASSPATH. Don't set a system CLASSPATH.
    * * * * * * * * *
    I see Junilu has beaten you to it, finding the instructions. You would do well to read the code in TextIO carefully and see how much of it you can understand.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!