Results 1 to 13 of 13
  1. #1
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Thumbs up 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

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by jazz2k8 View Post
    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

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    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.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  6. #6
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Unhappy

    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....

  7. #7
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    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

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  9. #9
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    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.
    Attached Files Attached Files

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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());
            }
        }
    }

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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. :)

  12. #12
    jazz2k8's Avatar
    jazz2k8 is offline Senior Member
    Join Date
    Apr 2008
    Posts
    149
    Rep Power
    0

    Default

    did you have checked my code which is attached???

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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

  1. Merge Two Xml files ????
    By alwz_nikhil in forum XML
    Replies: 5
    Last Post: 01-18-2011, 10:18 AM
  2. Replies: 3
    Last Post: 04-08-2008, 08:12 AM
  3. Replies: 1
    Last Post: 03-27-2008, 06:06 PM
  4. Merge 2 button become one
    By banie in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2008, 06:26 PM
  5. Merge Sort Help
    By Hollywood in forum New To Java
    Replies: 5
    Last Post: 01-30-2008, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •