How to merge two java files with InputDialog to select?Please help me!?

//Addition Java application
import javax.swing.JOptionPane; // import the class
public class Addition {
// main method
public static void main(String[] args)
String firstNumber, secondNumber;
int number1, number2, sum;
// read the first number
firstNumber = JOptionPane.showInputDialog("Please enter a integer: ");
// read the second number
secondNumber = JOptionPane.showInputDialog("Please enter another integer: ");
// data type conversion
number1 = Integer.parseInt(firstNumber);
number2 = Integer.parseInt(secondNumber);
sum = number1 + number2;
// display the result
JOptionPane.showMessageDialog(null, "The sum is " + sum + ".", "Results", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
//Multiplication Java Application
import javax.swing.JOptionPane;
public class Multiplication5
public static void main(String args[])
int number1, number2, number3, number4, number5, product;
String firstNumber, secondNumber, thirdNumber, forthNumber, fifthNumber ;
firstNumber =
JOptionPane.showInputDialog("Please input an integer");
secondNumber =
JOptionPane.showInputDialog("Please input another integer");
thirdNumber =
JOptionPane.showInputDialog("Please input the third integer");
forthNumber =
JOptionPane.showInputDialog("Please input the forth integer");
fifthNumber =
JOptionPane.showInputDialog("Please input the fifth integer");
number1 = Integer.parseInt(firstNumber);
number2 = Integer.parseInt(secondNumber);
number3 = Integer.parseInt(thirdNumber);
number4 = Integer.parseInt(forthNumber);
number5 = Integer.parseInt(fifthNumber);
product = number1 * number2 * number3 * number4 * number5;
JOptionPane.showMessageDialog(null, "The product is " + product, "Results", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
I seek for help to merge above two java application files.
I need to call JoptionPane.showInputDialog to prompt the user to input the operation, 1 for addition, 2 for multiplication. In this dialog, the user is expected to enter the integer of 1 or 2 for the calculation.
Please help me ! Thank you!

Hi CRay,
You just need to call the main methods of the 2 classes according to "1" or "2" entered.
It is better if the "multiplication" and "addition" are declared as methods rather than in main methods.
Example:-
public static void Addition()
Then call
Addition.addition();
than
Addition.main(new String[]{});
as shown below.
import javax.swing.JOptionPane; // import the class
public class Test{
    public static void main(String[] args){
        // read which  operation to perform
        String operation = JOptionPane.showInputDialog("Please enter which operation : ");
        if(operation.equals("1")){
            Addition.main(new String[]{});
        else{
            Multiplication5.main(new String[]{});
}Rose

Similar Messages

  • How do I open a file with an .msg extension please?

    Hello, can anyone tell me how I can open a file with an .msg extention please?

    On a Classic operating system, which predates 2001, it may be difficult, except with a really old version of BBEdit Lite from http://www.barebones.com/
    Newer versions of BBEdit or Textwrangler can probably also open it if you don't have a Classic operating system.
    Microsoft Entourage and Outlook can probably also open such documents.   Outlook Express was available for Classic operating systems as well, but it may be too new for it to read those documents.

  • How to merge two XML's with JDOM?

    How to merge two xmls's using jdom? like:
    is there a way to add the complete content one xml into the parent node of another xml?
    //in.xml
    <?xml version="1.0"?>
    <people>
    <person>
      <name>ABC</name>
      <email>[email protected]</email>
    </person>
    </people>
    //out.xml
    <?xml version="1.0"?>
    <address>
    <city> abccounty</city>
    <state> abcstate</state>
    </address>
    Merged XML:
    <?xml version="1.0"?>
    <people>
    <person>
      <name>xyz</name>
      <email>[email protected]</email>
    </person>
    <address>
    <city> abccounty</city>
    <state> abcstate</state>
    </address>
    </people>
    import java.util.List;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;
    import org.jdom.output.Format;
    import org.jdom.output.XMLOutputter;
    public class MergeXMLS {
         public static void main(String[] args) {
              try{
                  SAXBuilder builder = new SAXBuilder();
                  Document books = builder.build("D:/in.xml");
                  Document onebook = builder.build("D:/out.xml");
                  Element root = books.getRootElement();
                  List rows = root.getChildren();
                  for (int i = 0; i < rows.size(); i++) {
                      Element row = (Element) rows.get(i);
                      onebook.getRootElement().addContent(row.detach());
                      System.out.println(row.getName());
                  new XMLOutputter(Format.getPrettyFormat()).output(onebook, System.out);
              }catch(Exception e){
                   e.printStackTrace();
    }

    The above code only add's the first node.
    I changed the code little differently to
                  SAXBuilder builder = new SAXBuilder();
                  Document books = builder.build("D:/in.xml");
                  Document onebook = builder.build("D:/out.xml");
                 //trying to add second xml into the first
                  books.getRootElement().addContent(onebook.getRootElement().getContent()); 
                  new XMLOutputter(Format.getPrettyFormat()).output(books, System.out);
    here is the exception from the above code:
    org.jdom.IllegalAddException: The Content already has an existing parent "address"
         at org.jdom.ContentList.add(ContentList.java:218)
         at org.jdom.ContentList.add(ContentList.java:140)

  • How to link two .java files together?

    hello everybody,
    is it possible to link two or more .java files together? I mean is if I have 3 .java files. (a.java, b.java, c.java) then I have 3 .class files too. How do I use the method in other .java files. For example :
    public a extends Applet {
    // call b.class
    b();
    public b extends Applet implements ActionListener {
    void title1() {
    How to call the b.class? How to call the title1() method?
    Is it related to JAR or package??
    Thanks for helping me. v(^_^)v

    O.K, you do not link ".java" files together.
    You compile them into class files and they can create new instances of each other and and access their variables and work together.
    I recommend "Sam's Teach Yourself Java in 21 Days".
    It will start you out with the basics.
    --Ian                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

  • How to create a .java file with multiple classes

    I have all the below classes declared in a file say ABC.java under
    a common package called somepackage
    Abstract class A
    Void abstract metod1();
    Void metod2();
    Class B
    void method3();
    Void method4();
    Class C
    void method1();
    Void method2();
    In Client.Java
    On compiling the Client.Java I get errors
    Import somepackag.*;
    Class Samp extents A
    void Method1()
    Public class Client
    A a1 =new Samp(); //error undeclared class A
    B b1 = new B1();//error undeclared class B
    C c1 = new C1();//error undeclared class C
    is it possible to have all the class declared in one file ( i dont need mutiple classes, as this file will be autogenerated , i need all classes in one file) and use the classes inside this in the some client app
    regards
    MP

    Peetzore wrote:
    As long as you have only one public class and your .java file is named after it you shouldn't have any problem.I did exactly that, but still i get the same error "Cannot find symbol"
    i have used the import command on top as import somepackage.*;
    Edited by: mpjava on Jun 2, 2009 1:29 AM
    Edited by: mpjava on Jun 2, 2009 1:30 AM

  • How to include a static file.... Please help..

    Hi guys..
    i am going crazy here, so please help.... is it possible to use <jsp:include page="headlines.html" flush="true"/> to serve a static file( headlines.html) which is in say tomcat_home\bin.. also, i wonder why the following code creates a headline file in the bin folder in the first place.. i thought, it should create headlines.html in the same folder as this class...i am a newbie as you can see...thanks in advance
    package beanpackage;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.transform.stream.StreamResult;
    import java.io.FileOutputStream;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Transformer;
    import java.io.File;
    public class RSSProcessor {
    public RSSProcessor(){ }
    String _RSSFile;
    public String getRSSFile(){
    return _RSSFile;
    public void setRSSFile(String fileName){
    try {
    StreamSource source = new StreamSource(fileName);
    StreamSource finalStyle = new StreamSource("final.xsl");
    String outputURL = "headlines.html";
    StreamResult result = new StreamResult(new
    FileOutputStream(outputURL));
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer(finalStyle);
    transformer.transform(source, result);
    } catch (Exception e) {
    e.printStackTrace();
    }

    I am just about there thanks to you stibrian..
    as you know that i am using a bean and a jsp to transform the rss feed.. following your direction i used String filePath = getServletContext().getRealPath etc. in my JSP and i am getting my headlines.html in the ROOT folder every time i reload the JSP.. thats great ! but my <jsp:include page="headlines.html" flush="true"/> is still not working(i tried every possible combination).. is there any thing wrong? I will post my new code below and i hope that i would not bother you again (on this:-).. thanks a lot.. also, i will add some dukes to this question, as a thank you..
    package beanpackage;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.transform.stream.StreamResult;
    import java.io.FileOutputStream;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Transformer;
    import java.io.File;
    import java.io.*;
    public class RSSProcessor {
    public RSSProcessor(){ }
    String _RSSFile;
    public String getRSSFile(){
    return _RSSFile;
    public void setRSSFile(String fileName, String outputURL){
    try {
    StreamSource source = new StreamSource(fileName);
    StreamSource finalStyle = new StreamSource("final.xsl");
    //String outputURL = getServletContext().getRealPath("WEB-INF" + File.separator + "headlines.html");
         //String outputURL = "headlines.html";
    StreamResult result = new StreamResult(new
    FileOutputStream(outputURL));
    TransformerFactory transFactory = TransformerFactory.newInstance();
    Transformer transformer = transFactory.newTransformer(finalStyle);
    transformer.transform(source, result);
    } catch (Exception e) {
    e.printStackTrace();
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <jsp:useBean id="rssBean" scope="request" class="beanpackage.RSSProcessor">
    <%@ page import="java.io.File"%>
    <%String outputURL = getServletContext().getRealPath(File.separator + "headlines.html");%>
    <%
    rssBean.setRSSFile("http://www.rediff.com/rss/inrss.xml", outputURL);
    %>
    </jsp:useBean>
    <html>
    <head>
    <title>Syndicated Feeds</title>
    </head>
    <body>
    <jsp:include page="headlines.html" flush="true"/>
    </body>
    </html>

  • Re: How to merge two video files in a single file.

    If you want to get just sequence of two files, so you can use http://java.sun.com/products/java-media/jmf/2.1.1/solutions/Concat.html I suppose.
    Or some for merging on http://java.sun.com/products/java-media/jmf/2.1.1/solutions/

    Hi watergad,
    ThX good help!
    NeuralC

  • How to merge external RAW-files with iPhoto library?

    Hi,
    I have several (Aperture-) modified photos in iPhoto. When I click on any one of those photos in iPhoto (9.5.1) and then click on File -> Reveal in Finder -> Modified File – it reveals the location of a jpg-file inside my iPhoto Library. So far, so good.
    However, when I choose File -> Reveal in Finder -> Original File it takes me to an external folder (located in my Home Picture library) and reveals the original RAW-file. I don't know why they are in a folder outside the iPhoto library but I suppose it has something to do with me editing them outside of iPhoto. And this is not a library but just a regular folder containing RAW-files.
    How can I merge all my RAW-files so that they are, neat and tidy, all inside my iPhoto library?

    I am glad you found the answer useful
    What probably happened, was that you imported your original files as referenced. This feature is not recommended in iPhoto, since iPhoto does not support it well - or not at all. I did not want to point that out in the iPhoto forum. In Aperture it is very useful, however, if your library is so large, that it will not fit on one drive. Then you can store the originals on a different drive. Aperture handles referenced images very well.
    For some background reading you may want to have a look at this manual page, just in case you may want to use this feature one day:
    Aperture 3 User Manual: Working with Referenced Images
    -- Léonie

  • How to merge two .mp4 files into one file?---Help!

    When two clients make viedo chats on FMS,FMS saves two clients' audio and video informations into two seperate mp4 files.
    Now I want to get one mp4 file which contaions one cilent's audio and video informations and another client's audio information when recording
    Is there any way to deal with this problem?
    Thanks in advance..

    Hi Tibor,
    Below is the output i got.
    [Tracer_2]<?xml version="1.0" encoding="UTF-8"?><Rowsets DateCreated="2015-04-05T23:22:05" EndDate="2015-04-03T11:10:27" StartDate="2015-04-03T11:10:27" Version="14.0 SP5 Patch 11 (Aug 27, 2014)">
        <Rowset>
            <Columns>
                <Column Description="" MaxRange="100" MinRange="0" Name="col1" SQLDataType="1" SourceColumn="col1"/>
                <Column Description="" MaxRange="100" MinRange="0" Name="col2" SQLDataType="1" SourceColumn="col2"/>
                <Column Description="" MaxRange="100" MinRange="0" Name="col3" SQLDataType="1" SourceColumn="col3"/>
            </Columns>
            <Row>
                <col1>1</col1>
                <col2>2</col2>
                <col3>3</col3>
            </Row>
            <Row>
                <col1>11</col1>
                <col2>22</col2>
                <col3>33</col3>
            </Row>
            <Row>
                <col1>a</col1>
                <col2>b</col2>
                <col3>c</col3>
            </Row>
        </Rowset>
    </Rowsets>
    Please find the image below to achieve this. Please note, I have used local variables to assign input xmls and repeat through it. Repeater_0 for Headers and Repeater_1 for body.
    Kindly ignore Doc_0 here, it's for another purpose. Document_1 is what we are focussing on.
    Please note, you would not be able to see columns as those are dynamically created. Still you can map it as shown above.
    Hope this helps.
    Best Regards,
    Swaroop

  • How to compile a java file with specified jdk version in a program???

    hi,
    if we want to compile a program in another program with a particular
    jdk version as an option, how to do that,plz reply and with example.

    Hi,
    To compile from a program, read this (I've never tried, but I think it
    will work):
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Compiler.html
    To get the jre version:
    System.getProperty("java.version");
    To get the vm version:
    System.getProperty("java.vm.version");
    Other properties at:
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/System.html
    Hope it helps,
    ANeto

  • How to cretae two flat file with a single program

    Hi All,
    I am trying to creating to two files on the application server using the open data set and close data.
    lets say the first file is file1 and second file is file2. but when i go to the Tcode AL11 and check the file only second file is appears there.
    its may be coz i m using two times this open data and close data in my program.
    can u tell help me howz these two file is appears on the application server i.e AL11.
    its very urgent pls help me.
    Thanks!
    Vipin

    Hi Do one thing,
    Start ur program in debugging mode complete first open data set and close data set and then go and chekc whehter the file got created or not and also check the sy-subrc values when u r doing ur open data set.
    if the first file is not done then no file will be in AL11 including ur new file name.
    In this way you can find whether the file got created or not.
    check that u r giving differnet file names fifferently otherwise it will be keep on overwriting the existing one.
    Regards,
    sasi

  • Merge two PDF files into one with Adobe Reader

    Does anyone know how to merge two PDF files into one with Adobe Reader. Is it even possible?
    Thanks

    If you've got a Mac and OSX you can do this in Preview.  Make sure you can see the sidebar with the first PDF opened, and then drag the second PDF to the bottom of the last page in the sidebar.  Also you can reduce the size of your saved file by selecting (or making) a Quartz filter to 'reduce file size'
    Cheers

  • How can i execute "*.java " files in Workshop

    Hi,
    Im sunil,new to this weblogic workshop8.1..i dont know how to execute standalone .java files or servlets in workshop.plz help me and tell the way.
    regards
    Budati sunil

    Im not too sure about the Java project. But single normal java files with public static void maain(String [] args) are very simple to execute.
    1. Write the java code somewhere lets call this class A.
    2. Make a dummy page flow.
    3. In the begin action of this pageFlow, call the main method of the A class directly using A.main(null) since main is a static method. your code will work fine.
    4. If you have to pass a String[] as parameters. Before calling main, create this String[] and then pass it.
    In this way you can make a jsp and take the input from the user also.
    Hope it helps
    Cheeers

  • How to merge two repositories using(MUD)

    hi all,
    how to merge two repositories using mude, for example i have sh rpd and paint rpd how to merge two repositories using Multi user development(mud), please don't give venkat forums link and oracle's training doc links.
    Is this possible? if it is possible please help me .
    Thanks
    Naresh

    Hi Naresh,
    What you could do is:
    1. do a ontime command line merge of both repository using the nqudmlexec tool
    2. In the mergerd repository created two project (sh and paint) and assign one bussiness model to each project.
    3. Make this the master repository for your MUD.
    4. Check the projects in and out.
    regards
    John
    http://obiee101.blogspot.com

  • How do I merge multiple Excel files with more than one tab in each file using PowerQuery?

    Hello
    I have 12 Excel (.xlsx) files and each file has three identically named and ordered tabs in them. 
    I know how to merge multiple Excel files in a folder using M (those guides are all over the web) but how do I merge multiple Excel files with multiple (yet identically named and ordered) tabs? Surely it is possible? I just don't know how to do it in M.
    Cheers
    James

    What Laurence says is correct, and probably the best thing to do when the sheets have differing structures. Here is an alternate approach that works well when the sheets all have the same structure.
    When you first open the Excel file from Power Query, you can see its structure in the navigator at the right-hand-side of the screen. If you select the root (which is the filename itself) and click Edit, you'll see all the tabs in the sheet as a single table.
    You can now do filtering based on the Name, Item and Kind values. When you've reduced the set of things down to the sheets you want, select the Data column and say "Remove Other Columns". If the sheets don't have any header rows, you can just click the expand
    icon in the header and you'll be done.
    Otherwise, if the sheets have headers or if some other kind of sheet-level transformation is required against each sheet before doing a merge, you'll have to write some M code manually. In the following example, each sheet has a header row consisting of
    two columns: Foo and Bar. So the only step I need to perform before merging is to promote the first row into a header. This is done via the Table.TransformColumns operation.
    let
        Source = Excel.Workbook(File.Contents("C:\Users\CurtH\Desktop\Test1.xlsx")),
        RemovedOtherColumns = Table.SelectColumns(Source,{"Data"}),
        PromotedHeaders = Table.TransformColumns(RemovedOtherColumns,{{"Data", each Table.PromoteHeaders(_)}}),
        ExpandData = Table.ExpandTableColumn(PromotedHeaders, "Data", {"Foo", "Bar"}, {"Data.Foo", "Data.Bar"})
    in
        ExpandData

Maybe you are looking for

  • White Macbook (Late 2009) Case not aligned after damage

    Today I slipped on ice and fell on my back with my Macbook in my bag which unfortunately took the hit. It still starts up ok (but the fan is a little louder than it was) and every key is working on the keyboard but the force of the fall was on the hi

  • Does VMIC driver support LV RT8.2?

    Hello, Using VMIC-5565 instrument driver for LV, I am trying to setup reflective memory VMIC-5565 on LV RT 8.2. My problem is how to setup VMIC-5565 on RT and it is not detected on MAX. First, after installed the driver which is provided from GE FANU

  • Why can't I use any downloaded program on my Macbook?

    It seems to be that I can't do anything when I open a downloaded program. That includes programs such as Adobe, Microsoft Office en even the smallest such as VLC Media Player. Programs that were already on the laptop such as Safari, Finder, Apple Mai

  • Accounting Doc Change

    Hi Is there any function module to chage the accounting doc header and item data together? I Only want to change the editable fields that I can do through FB02. I will prefer to have a FM for that. Thanks for ur help. Chinmoy

  • Installation LS failed. Corrupted Disk??

    I tried to install Snow Leopard last week (upgrading), but with still 46 minutes to go.I got message to clean the disk and try again. Which I did several times. Same error. I tried via start holding "c" and starting up from installation disk, but aft