-
April 11th, 2018, 12:28 PM
#1
Calling Method from other Class
Good afternoon! I am trying to call a method from other class and it wont work. Do i have it written wrong or in the wrong place?
Code:
public static void main(String[] args)
throws FileNotFoundException, IOException
{
try
{
InputStream Filename=new FileInputStream("input.txt");
BufferedReader br=new BufferedReader(new InputStreamReader(Filename));
for (String line = br.readLine(); line != null; line = br.readLine())
{
System.out.println(line);
}
StringConversion.(lowerCaseString);
br.close();
}
catch(IOException e)
{
System.err.println("Error: Target File Cannot Be Read");
}
}
class StringConversion
{
public String lowerCaseString = "";
public String lowerCaseString(String trimmed)
{
lowerCaseString = trimmed.toLowerCase();
return this.lowerCaseString;
}
}
}
any help would be appreciated. I have looked at tutorials and still cant figure out what i am doing wrong.
-
April 11th, 2018, 02:40 PM
#2
Re: Calling Method from other Class
trying to call a method from other class
Not sure what class and method you are talking about.
Can you give some details?
Here is an example from your code of calling a method that is in another class:
Code:
BufferedReader br=new BufferedReader(new InputStreamReader(Filename)); // define an instance
for (String line = br.readLine(); line != null; line = br.readLine()) // call readLine method from this class
If there are error messages, copy the full text and paste it here.
Norm
-
April 11th, 2018, 02:45 PM
#3
Re: Calling Method from other Class
I got it!!! Thank you for looking though! I was fighting it and figured out how to do it. Now on to bubble sort and selection sort! OH the joy
-
April 16th, 2018, 07:40 AM
#4
Re: Calling Method from other Class
Glad you got it worked out. While it's technically fine in Java to have an instance variable with the same name as a method, I kind of like to avoid doing it. In your code above, you have lowerCaseString as a variable and a method. I guess for me having StringConversion.lowerCaseString and StringConversion.lowerCaseString() may cause some confusion, but I guess to each his own.
-
April 16th, 2018, 07:46 AM
#5
Re: Calling Method from other Class
Good point.
variable names should be nouns
method name should be verbs
Norm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|