Results 1 to 11 of 11
- 01-17-2009, 06:13 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
Hi there, and i have little problem with readLine
Hi there, I am currently doing my second year at uni doing Business Information Technology and seem to have forgotten everything over the christmas holidays!
I get an error message saying
"cannot find symbol - method readLine()"
when i try to compile this code
Java Code:import java.io.*; final public class Checking extends bankAccount { private String indata; public Checking(String accountNameIn, String custNameIn, float balanceIn) { super (accountNameIn, custNameIn, balanceIn); } public void setAccountName(String accountNameIn, String args[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print ("Enter the name of your account: "); accountNameIn = indata.readLine(); } public void setCustName(String custNameIn) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print ("Enter the name of the holder of the account: "); custNameIn = indata.readLine(); } public void deposit (float balanceIn) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print ("Enter how much you would like to deposit in your checking acount: "); balanceIn = indata.readLine(); } public void withdraw() { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print ("Enter how much you would like to withdraw from your checking account: "); balanceIn = indata.readLine(); } public String getAccountType() { return ("Checking Account"); } }
-
You are remembering more than you realize. Your main problem that I see is that you're calling readLine on the "indata" String not on the BufferedReader object, "in".
- 01-17-2009, 06:20 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
AH so if i just put
"accountNameIn = in.readLine();"
instead of
"accountNameIn = indata.readLine();"
should it work?
The thing is i have just taken that part of code just to save writing it out from another program i have written and didnt have any problems with that, if possible i would like to be able to keep it as indata just to prevent me confusing myself?
Is that possible or have i got the wrong end of the stick?
- 01-17-2009, 06:22 PM #4
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
AAHHHHHHH thank you sooo much for pointing that out, just noticed that it was "BufferedReader in" instead of "BufferedReader indata"!
Was tearing my hair out over that thank you fubarable lol!
-
I am a bit worried that you are creating multiple bufferedreaders but never closing them (that I can see at least). If you are not doing so, you will want to take care to manage your limited resources here.
- 01-17-2009, 06:44 PM #6
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
I am sorry I do not understand what you mean by not closing them. Please explain and i will do my best to implement it.
I havent been taught about closing the bufferedreaders?
-
Java is pretty good at preventing memory and similar leaks, but AFAIK, your system has a limited number of resources for I and O, and whatnot, and when you open a Reader object such as a BufferedReader, you are using one of these resources. When you are done with it, you close it so as to free the resource and allow it to be used by something else. I usually use my resource within a try block and close the resource (after checking that it's not null) in the finally section of the try/catch/finally block.
This is even more important when you are writing to a file as if you don't close the resource that does the writing, it may not be flushed, and there may be data left in the resource that never gets written to the disk.
Also note that if you create a nested reader such as you do here:
it is only necessary to close the outer resource, here the BufferedReader, and not the inner resources, here the InputStreamReader.Java Code:new BufferedReader(new InputStreamReader(System.in));
- 01-17-2009, 07:55 PM #8
you have more than just readline errors
Java Code:import java.io.*; public class test{ public static void main(String[] args) throws Exception { float balanceIn = 10.0f; System.out.println("B4 deposit: " + balanceIn); deposit(balanceIn); System.out.println("After deposit: " + balanceIn); } public static void deposit (float balanceIn) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print ("Enter how much you would like to deposit in your checking acount: "); balanceIn = Float.valueOf(in.readLine()); System.out.println("during deposit: " + balanceIn); in.close(); } }Java Code:OUTPUT: S:\Temp>java test B4 deposit: 10.0 Enter how much you would like to deposit in your checking acount: 2 during deposit: 2.0 After deposit: 10.0
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-17-2009, 08:07 PM #9
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
Fubarable: ok so what I gathered from that, you can't use bufferedreader as many times as you like, there's only a certain number of bufferedreaders.
If this is right, how can I either use just the one bufferedreader for the whole class or how do I close each instance of bufferedreader?
Angryboy: afaik this shouldn't be a problem I won't actually be running re program from this class but I will tackle that when it becomes one!
- 01-17-2009, 08:26 PM #10
- 01-17-2009, 08:30 PM #11
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
problem with console.readLine()
By thatguy in forum New To JavaReplies: 1Last Post: 12-14-2008, 07:40 PM -
[SOLVED] ReadLine(String fmt,Object... args) of Console class
By Pooja Deshpande in forum New To JavaReplies: 4Last Post: 04-25-2008, 05:51 AM -
DataInputStream readLine()
By ravian in forum New To JavaReplies: 2Last Post: 11-26-2007, 10:44 PM -
Problems with readLine() and calling methods
By peachyco in forum New To JavaReplies: 2Last Post: 11-24-2007, 07:44 AM -
BufferedReader: readLine method problems
By bbq in forum Advanced JavaReplies: 2Last Post: 06-30-2007, 02:27 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks