How to make a Java program that recognises a function of two variables...

How to make a Java program that recognises a function of two variables to assign values to that?
First I will give an example and then do the question.
Ex1.
We have any function, eg.y = x ^ 2 + 1 (read 'y' equals 'x' high to the square), a function of the second degree.
To build the graph of this function attach values to 'x' to find the values of 'y'
And thus mount the pair ordered (x, y) which represents a point on the Cartesian plane.
Assigning values to 'x' 'we can build up a table that gives us the pairs ordered:
We can use any numbers, but arfer interval [-3.3]
X | y = x ^ 2 + 1
-3 | Y = (-3) ^ 2 +1 = 10
-2 | Y = (-2) ^ 2 +1 = 5
-1 | Y = (-1) ^ 2 +1 = 2
0 | y = (0) ^ 2 +1 = 1
1 | y = (1) ^ 2 +1 = 2
2 | y = (2) ^ 2 +1 = 5
3 | y = (3) ^ 2 +1 = 10
We then ordered the pairs:
(-3.10), (-2.5); (-1.2), (0,1), (1,2), (2,5), (3,10)
Tabem that can be represented by a table:
X | y
-3 | Y = 10
-2 | Y = 5
-1 | Y = 2
0 | y = 1
1 | y = 2
2 | y = 5
3 | y = 10
Now I begin to explain my doubts.
See this program:
Ex2
* To change this template, choose Tools | Templates
* And open the template in the editor.
Encontrando_o_valor_de_y package;
* @ Author des Soldat Gottes
Import javax.swing.JOptionPane;
Public class (Main
* @ Param args the command line arguments
Public static void main (String [] args) (
Int x, y;
String x1;
X1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
"Assign a value for 'x',"); / / receives a value for the function y = x + 1
X = Integer.parseInt (x1); / / tranforma String in int
Y = x + 1; / / receives the value of 'x' and calculates' y '
JOptionPane.showMessageDialog (null, "The value of 'y' is: \ t \ t" + y);
/ / Displays the value of 'y'
System.exit (0);
We see that the program receives above a value for 'x' and replaces the function contained in the program, y = x + 1, and so is the value of the variable 'y'.
In: x1 = JOptionPane.showInputDialog ( "We have the function y = x + 1 \ n" +
"Assign a value for 'x',");
The entry is a number and that number is assigned aa ja existing function in the (y = x + 1).
The question is: would it be possible to come to a function?
Ex: the program ask: DIGITE THE FUNCTION?
The USUARIO DIGITARIA A FUNCTION ANY, TYPE: y = x ^ 2 +1
The program would recognize the function and give numerical values to that function as Ex1, at the beginning of this text.
And then to find the values of the x and y launch a table.
It would be possible that?
By invez of entering with a number so that the program sustitua a function ja existing as Ex2, seen above, entering with a function quaquer (type: y = x ^ 2 +1) for the program atribuisse values to that function and then create a table of values as Ex1.
I hope it has been easier to understand my doubts now.
Thank you for your attention!
God bless!

rafaelmenezes wrote:
Thanks for the explanation, could understand what fly said.
But as it applied to a program?
How to create a program that recognizes that the entry coefficients?Are you asking about how to parse out the coefficients from the string "3x^4 + 4x^3 - 8x^2 + 5x^1 + 2x^0"? If you define the format to strictly follow that example, this should get you started:
Strip out the spaces
Split the String on "x^"
That should give you [3, 4+4, 3-8, 2+5, 1+2, 0]
Split each resulting String on "+ | -", preserving the operator as a token so you can apply the correct sign to the coeff.
That should leave you with [3, 4, +, 4, 3, -, 8, 2, +, 5, 1, +, 2, 0]. Every other number is a coeff, the rest are the degrees.
You can strip out the +, since those coeffs are already positive, and strip out the - after negating the following number. This is all assuming that you have to write this yourself. There is no doubt already a library or 5 out there that does this for you.

Similar Messages

  • How to make a java program, that can be used by c++ application

    I'm developing a Java web application (WEBapp), but I have also a c++ program.
    C++ program must use WEBapp method to communicate on the web.
    How to make a Java public function that accept value, elaborate, then return the resul to c++ application?

    jschell wrote:
    You have C code.
    You have Java code.
    The two must communicate.I have a c++ program, and a Java program.
    C++ program wants to communicate on the web (send text), and I'm trying to add this functionality to it creating a Java program.
    NOW THE PROBLEM? How c++ program can use java-program (in local) to send data on the web?
    You can just JNI to communicate either from java to C++ or from C++ to java. That is direct communication in that there is a single process involved. Thus you will no longer have a java application and a C++ application but rather a single application.I don't know JNI, i found http://java.sun.com/docs/books/jni/ and I think is too difficult to implement?
    You can use files or sockets to communicate. Using sockets allows for any number of additional protocols including the previously mentioned web services. Those methodologies would allow more than one application to exist.I developed yesterday a java-side-interface using socket (in local host 127.0.0.1). So the c++ program must write or read to/from the socket to comunicate to java (then the java program send data on the web).
    Finally it might be the case that you have a C++ application which you cannot modify. In that case then you MUST use whatever input/output mechanism that it supports. There is no choice. And until you have fully determined what those mechanisms are it is pointless to discuss a solution.I can modify the application, but I don't have developed it. The c++ application use a third-part dll (taken from SKYPE) to comunicate on the web: I have to remove the dipendence from this dll, and add the java program: java program must substitute the dll. It must be non-invasive to the c++ program. DLL calls can be "send(data)" or "receive(data)" or similar.
    For this do you think that JNI is a must, or I can use soket on local host?

  • How to make a java program that will give you the list of files in the dir

    How can you make a program in java that will list all the files in a directory with out useing the File,FileWriter,FileReader,InputStreamReader,FileInputStream,RandomAccessFile etc. classes

    What is with these instructors? So far today I have
    seen
    Do something 100 times, but don't use a loop
    Format numbers, but don't use NumberFormat
    and now this.
    What are these people trying to teach?
    Java??? I don't think so.Perhaps it is because these instructors are learning Java at the same time as their students. They are only one chapter ahead of the students. :(

  • How to make a Java application that will change the client box's IP address

    HI how to make a Java application( that application would be run on the client ) that will change the client box's IP address ( IP address of itself )

    If you can do that through the command line, then use Runtime.getRuntime().exec(...) to execute your command.

  • How to make a java-program to a exe file runing on windows?

    i kown that there were many topics on this problem.
    i want to kown how many kinds method to do this i can use now!
    i met a java-program can run on windows,but i don't find ant *.class
    files and *.jar files.it's extended file type is ".ese".
    thanks very much

    There are commercial products that allow you to do this (e.g. InstallAnywhere from http://www.zerog.com).
    One issue is that you have to decide whether you want to bundle a JRE with your program or not. If you do (and you should, in these days of XP shipping without any VM of its own), your program will be a minimum of about 9MB + whatever you actually add as part of your program :-).
    In any case, this is not a trivial undertaking.

  • How to make a java program run as a background process.

    </pre>
    writing a client server application.
    a program is supposed to run on a the client right from the time the client turns on the computer till the computer is turned off.
    the catch is the client should all the time be unaware of the program running in his computer, no dos prompt window, no icon on the taskbar,etc. can i convert it the class file into an exe file through software and put the exe filename in autoexec.bat. But then i think that the dosprompt window will open up on starting, but the client should see nothing.
    please help
    </pre>

    </pre>
    Thanks Daniel and jesper,
    could not really fully understand what you mean.
    creating a batch file is okay, but do you configure it
    to run in a an hidden mode.
    Also I have no idea of how to make a window
    service.can you please elaborate a bit
    </pre>

  • Java program that create a graphic interface of the WGET program

    Hello,
    How can I make a Java program that create a graphic interface of the WGET program.
    Please post something already developed.
    No Applet.
    Thank you.

    You can use java.lang.Runtime.exec or java.lang.ProcessBuilder to execute external programs like wget. Generally you pass one of those methods an array of Strings; the first String is the name of the executable, and the rest are arguments. You get a Process object that represents the running process that you've started; you can get standard input and output streams from that Process to read output. This is probably stuff your teacher already told you...but if not, hope it helps.
    You should read this article about pitfalls around Runtime.exec:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Much of the information there also applies to ProcessBuilder.
    Good luck on your homework.

  • Creating java program that orders 3 numbers in ascending order using if els

    Does anyone know what code to use for creating a java program that uses the if else operators to order 3 variables in ascending order?

    nar0122 wrote:
    correct on the homework assumption...you have a good nose...the thing is...i know i need to make an if statement saying if a is less than b, and a is less than c...print a first...but how do i get it to "print a" first? if a is less than c and b...and so on for b and c? sorry if that was confusing...
    int a = ..., b = ..., c = ...;
    if(a > b AND a > c) {
      print a
      if(b > c) {
        print b, print c
      } else {
        print c, print b
    etc.

  • How to execute a java program by clicking !?!?

    Just a click to execute a java program?!!
    Like the ".exe" in Windows or "x" permission in Unix ?!?!?!
    How can I do that?
    And how to set a java program file to display as a personal icon? (My Icon)
    :-)

    Well this is what I do in Windows (I use XP but it works in others):
    First you have to make sure all the class files are in the same folder (duh)
    Then you copy your java.exe from your jre folder into the folder with all your class files.
    Finally, you create a shortcut to java.exe and add your class name to the command line on the shortcut.
    Now all you have to do is double click on the shortcut and your program runs. Sure it's not that pretty but it works.

  • How to find directory java program .jar file is in?

    I have a Java program that needs to save some configuration and data files in the same directory as the .jar file that contains the program.
    If the user launches the app from that directory, it's easy.
    The problem is when they do something like "java -jar /dir1/dir2/program.jar".
    When they do that, HOW can I find the directory the .jar file is in - from within the program?

    CasaDelGato wrote:
    I have a Java program that needs to save some configuration and data files in the same directory as the .jar file that contains the program.
    If the user launches the app from that directory, it's easy.
    The problem is when they do something like "java -jar /dir1/dir2/program.jar".
    When they do that, HOW can I find the directory the .jar file is in - from within the program?There is an obscure way that basically consists of the following.
    1. Get the class loader of the class (obviously one in the jar)
    2. Find the 'resource' of that.
    3. Resolve that to a path
    4. Make it absolute if not already.
    5. Extract the directory part.
    2 and 3 are always the hard ones (conceptually and figuring out from the javadocs). There are examples somewhere on the forum.

  • How To Get A Java Program To Initiate Auto Dial in Windows???

    I have a Java program that opens a connection to a server (another Java program) using sockets and streams. On some windows machines (various versions) with auto dial enabled the connection is made without human intervention. However on some windows machines (even same as others) the autodial doesn't work and all I receive is NoRouteToHostExceptions.
    What I need is some way of initiating the autodial from within Java explicilty rather than assuming that the OS will do it when a request is made to a remote IP address.
    I emplore anyone with some knowledge of this to provide assistance as I am going nuts trying to solve this problems.

    A long time ago I figured out how to create, find, and manipulate items in the DialUp Networking using an InstallShield program. I am sorry I can't remember specifics (I wouldn't have even replied except no one else has either...) but I remember that I did a LOT of hunting on Microsoft's website for how to do this on the various platforms of the day (Win95, Win98, NT4.0).
    I imagine that in order to accomplish this from java, you will probably need to find the system-specific commands (at Microsoft) and exec them from your java program.
    /Mel

  • How to make my java bean internationalization?

    hi,
    I have a project on tomcat. I have rewrite my jsp to multi-language according to user's browse language setting. User's language is English, the jsp shows them English. User's language is Chinese, the jsp shows them Chinese, and so on. But in my java bean code, some exception are thrown out with some message or alert. Can anybody tell me how to make these java beans show the language string acording to user's browse language setting?
    thx
    Pierre

    Dear one_dane,
    Thank you. That is a great document to me. The fact is that my owner code throws exception with a string. The code is:
    if(amount<0) throw new Exception("Please input correct amount.");
    If the code is in jsp, I can convert it to a internationalized String using struts tag <bean:message...>. But it is in a deep function of java class. So must I add a Locale object parameter to the function and all calling functions?
    thx
    yours,
    Pierre

  • How to make add the program system.out messages to a applet text field?

    How to make add the program system.out messages to a applet text field?
    System.out.println("I wanna displany this message on a applet text field, thanks");

    You may wish to change the output destination to a JTextArea. Please have a look at this link that likely shows what you want:
    [http://forums.sun.com/thread.jspa?forumID=54&threadID=640376|http://forums.sun.com/thread.jspa?forumID=54&threadID=640376]
    If you need other examples, search the forum. I found the search terms -- redirect system out textarea -- very helpful.
    Good luck

  • How to invoke a Java Program from Oracle 10g?(uRGENT)

    Hello.
    I've a query, that i have a program, that basically retreives the records from the
    oracle table and then parser this information and then insert the values in corresponding database base tables. I want that, whenever the new program is inserted, a Trigger should fire and pass the most recently entered record to the Parser Program, means
    1) Firing a Trigge
    2)Storing the most latest data and pass it to the Parser PROGRAM
    Can someone tell me how to do this? How to invoke a Java Program from within the database? Please if anyone has examples provide me. Its very urgent and tell me what is the basic mechanism.
    Thankyou.
    Ben

    With Java Stored Procedures Java may be caleed from a database.
    http://www.oracle.com/technology/tech/java/jsp/index.html

  • How i can call java program in VB2005 ?

    Hi members...
    Please...please...please...
    If any one now how i can call java program in VB.net program and open it ,please i want now the way to do it by details and by examples and step step to do it ,,..
    thanks ...

    If your server does not return to the command prompt, write a java programm which starts your server and returns to the command prompt.
    An example for an application like this:
    import java.io.IOException;
    public class StartApp
    public static void main(String[] args)
    if (args.length > 0)
    StringBuffer cmd = new StringBuffer();
    for (int index = 0; index < args.length; index++)
    cmd.append(args[index] + " ");
    try
    Runtime.getRuntime().exec(cmd.toString());
    catch (IOException ioe)
    System.out.println("Error: command not found: " + cmd.toString());
    else
    System.out.println("Error: missing arguments");
    An example for starting your server with that programm:
    /usr/bin/java -jar ./StartApp.jar /usr/bin/java -jar ./myServer.jar
    It works. Have fun.

Maybe you are looking for