|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

04-22-2008, 10:25 AM
|
 |
Member
|
|
Join Date: Apr 2008
Posts: 99
|
|
|
How to Merge all classes into One class
I am having total 3 classes and i want to merge all into one class.
EG:A,B,C are different type of documents
class A
Class B
Class C
Now i want all of them into one single class
I have taken
Class D{
public void A()
{System.out.println("A");
}
public void B()
{System.out.println("B");
}
public void C()
{System.out.println("C");
}
}
class MainClass()
{public static void main(string args[]){
MainClass m=new MainClass();
string doctype="A,B,C";
System.out.println("Eneryour Doctype:" +doctype);
if (doctype="A"){
m.A();
}
if (doctype="B"){
m.B();}
if (doctype="C"){
m.C();
}
}
Am i correct???if not i need your suggestions ...
thanks in advance...
-jazz
|
|

04-22-2008, 10:38 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
Originally Posted by jazz2k8
I am having total 3 classes and i want to merge all into one class.
EG:A,B,C are different type of documents
class A
Class B
Class C
-jazz
Hi,
What exactly you want..??
If you want to merge classes you can do it with using inner classes.
But according to your description it seems that you want to merge all methods of three classes into single class..
please explain some more details.
sanjeev
|
|

04-22-2008, 11:17 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
|
Seems he wants to merge all methods in to a single class.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 11:40 AM
|
 |
Member
|
|
Join Date: Apr 2008
Posts: 99
|
|
|
Here what i want exactly...
I am having 3 different types of documents on which i written code for extracting the information from that all are different classes.Now i want t group them into one single class.I thought that by taking each class as a method it would be best...does it works???
Last edited by jazz2k8 : 04-22-2008 at 11:48 AM.
|
|

04-22-2008, 12:01 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
|
Simply you want to read three different files, isn't it?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 12:14 PM
|
 |
Member
|
|
Join Date: Apr 2008
Posts: 99
|
|
|
Yeah i want to read three and if the input argument matches to"A" Document it should invoke class A(methods)
Take for example
A=invoice
B=purchase
C=Creditors Journal
i have written separate code(classes) for invoice,purchase and Creditors journal
Now i want to merge all those into single.If the input argument is purchase it should invoke purchase class.
Now i want to merge all these 3 into single..For this requirement what is your suggestion???How to proceed for this.
i cant be more clear thatn this....
|
|

04-22-2008, 12:15 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
|
|
|
Ok, you need a program that extract data from three different document and you have written code in different three classes and now you want Single class for this.
Ok just design a class and put three method...instead one can have single method also. and then call method accordingly.
Or Post what have you done so far, so that one can give you proper solution for the same.
sanjeev
|
|

04-22-2008, 12:18 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
|
Yes, what you have to do is create all three different classes in a single class as methods. Since you have coded all three classes this is not much difficult at all.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 01:51 PM
|
 |
Member
|
|
Join Date: Apr 2008
Posts: 99
|
|
|
Here i am attaching my cde and the text please have a look into this issue.
One more thing in the above two funtions the code is same as follows
----------------------------------------------------
BufferedReader in=new BufferedReader(new FileReader ("D:\\jazz\\CSV\\abcd.txt"));
StringBuffer sb=new StringBuffer();
String line;
line=in.readLine();
while(line!=null){
sb=sb.append(line);
line=in.readLine();
}
String line1=sb.toString();
System.out.println(line1);
}
----------------------------------------------
Can i declare it as global??
if i ran the attached code iam getting errors.
|
|

04-22-2008, 01:51 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
Few error there. Defining variables as local or global is depend on the way you implementing the application.
Look at this code.
import java.io.*;
/**
*
* @author Eranga
*/
public class ReadFile {
FileInputStream fiStream;
DataInputStream diStream;
BufferedReader br;
public static void main(String[] args) {
// TODO code application logic here
new ReadFile().readFile();
}
public void readFile() {
try {
fiStream = new FileInputStream("D:\\jazz\\CSV\\abcd.txt");
diStream = new DataInputStream(fiStream);
br = new BufferedReader(new InputStreamReader(diStream));
String ss;
while((ss = br.readLine()) != null){
System.out.println(ss);
}
}
catch (IOException ex) {
System.out.println(ex.getLocalizedMessage());
}
}
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 01:53 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
Go through that given code and try to identify where you go wrong. The way you workout is no connection with the file and your application. 
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-22-2008, 02:30 PM
|
 |
Member
|
|
Join Date: Apr 2008
Posts: 99
|
|
|
did you have checked my code which is attached???
|
|

04-23-2008, 04:40 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 2,875
|
|
|
Yes I do, but I can't test it. Where is the FinalCode class. I can't find it in the attached file.
I don't know what you are trying to do in that. I give the solution for the code you have tried on the post number 9 code. Just read the file line by line. Is that not what you need?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. (Close on September 4, 2008)
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|