Results 1 to 13 of 13
- 04-22-2008, 09:25 AM #1
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, 09:38 AM #2
- 04-22-2008, 10:17 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Seems he wants to merge all methods in to a single class.
- 04-22-2008, 10:40 AM #4
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 10:48 AM.
- 04-22-2008, 11:01 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Simply you want to read three different files, isn't it?
- 04-22-2008, 11:14 AM #6
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, 11:15 AM #7
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, 11:18 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 04-22-2008, 12:51 PM #9
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, 12:51 PM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Few error there. Defining variables as local or global is depend on the way you implementing the application.
Look at this code.
Java 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()); } } }
- 04-22-2008, 12:53 PM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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. :)
- 04-22-2008, 01:30 PM #12
did you have checked my code which is attached???
- 04-23-2008, 03:40 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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?
Similar Threads
-
Merge Two Xml files ????
By alwz_nikhil in forum XMLReplies: 5Last Post: 01-18-2011, 09:18 AM -
[SOLVED] Using classes and overriding one class for another
By StealthRT in forum New To JavaReplies: 3Last Post: 04-08-2008, 07:12 AM -
How do merge two xml files into one xml?
By veera in forum XMLReplies: 1Last Post: 03-27-2008, 05:06 PM -
Merge 2 button become one
By banie in forum AWT / SwingReplies: 1Last Post: 02-17-2008, 05:26 PM -
Merge Sort Help
By Hollywood in forum New To JavaReplies: 5Last Post: 01-30-2008, 03:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks