Math in Java

What is wrong with Java's math. It adds double wrong sometimes. Why is this? Is there a way to hard-code it so it will add right?
Regards,
Collin

And it's not a Java thing. C/C++ have it, as I'd imagine C# does, as do many other languages.
It's a natural consequence of two things:
1) trying to represent an infinite number of values with a finite number of bits.
2) the fact that some things that can be represented exactly in base-10 (what we humans use) cannot be represented exactly in base-2 (what 'puters use).
For instance 0.1 base-10 cannot be represented exactly in base-2. In base-10, 0.1 is 1/10, 0.01 is 1/100, etc. In base-2, 0.1 is 1/2, 0.01 is 1/4, 0.001 is 1/8, etc. There is no way--absolutely no way--to represent 1/10 exactly in that notation with a finite number of digits.
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Similar Messages

  • Integration (math) in java?

    is there a mathematical integration method available in java?
    thanx
    chandika

    No in the standard API ... but you can find this in thirdy-part packages ... or implement by yourself.
    If you need numerical integration, simply use the algorithms for this, like Simpson or Newton, but if you need symbolic integration it�s more difficult, try 'java math integration' on google ...

  • Math and Java

    so..a newbie question. How important is Math to being a good programmer?

    i guess the possibilities are endless. If i dont have
    the luxury of school, what can i learn that
    will get me a job?fry-cooking?
    in what way don't you have the luxury of school? presumably going back to school is out of the question. sadly, if you're after a coding job, you'll have a hard time convincing anyone to give you even an interview, based solely on having taught yourself programming. even though it's perfectly possible - and indeed happens - to teach yourself this, and do it well. employers like qualifications, and given the choice between someone with a piece of paper that "proves" (note cynicism) they can do the job, and someone without any such piece of paper, they're always going to take the guy with the paper

  • Binary math in java?

    Dear everyone,
    A silly question here: How do I convert an integer to its binary form and do some operations such as OR, AND on it?
    The only clue I have is Integer.toBinaryString(). Could you please clue me in?
    Thanks a lot!
    George

    Integers are already in binary form. To do boolean arithmetic use &=AND |=OR ^=NOT and ~=XOR:
    int a= 0xff;
    int b;
    int c;
    b=a & 0x01;
    c=a&b|31; etc.
    By the way, I like 0xdeaddeaf. Ive seen several of these, like 0xcafebabe and 0xfeedc0de. Maybe we shouls compile a list!

  • Help plotting points in a java Applet using Bresens Algorithm

    Hi,
    I am trying to compile my code and it doesn't like POINT. I am guesing I am using the wrong thing.
    Point.point(Math.round(x), Math.round(y)); and I tried just Point.
    How do I plot points so that it forms a line. What internal function do I use?
    Here is my code.
    import java.applet.*;
    import java.awt.*;
    import java.lang.Math;
    import java.awt.Point;
    import java.awt.Graphics;
    public class DDASimple extends Applet
         int   dx, dy, steps, k, absolutex, absolutey;
         float xinc, yinc, x, y;
       public void init()
    public void paint(Graphics g)
    DDASMPL(50,50,100,150);
    public void DDASMPL(int x1, int y1, int x2, int y2)
      repaint();
      dx = (x2-x1);
      dy = (y2-y1);
    //absolutex =
      if( Math.abs(dx) > Math.abs(dy))
         steps = Math.abs(dx);
      else
         steps = Math.abs(dy);
         xinc = dx / steps;
         yinc = dy / steps;
         x = x1;
         y = y1;
    Point.point(x1, y1);
          for (k = 1; k < steps; k++)
              x = x+ xinc;
              y = y + yinc;
    Point.point(Math.round(x), Math.round(y));
    //g.drawOval(Math.round(x), Math.round(y));
         }//end else
    }//end function dda
    }//end class ddda applet

    I took out the repaint(). and below is the updated version
    I am not getting anything now, no line
    import java.applet.*;
    import java.awt.*;
    import java.lang.Math;
    import java.awt.Point;
    import java.awt.Graphics;
    public class DDASimple extends Applet
         int   dx, dy, steps, k, absolutex, absolutey;
         float xinc, yinc, x, y;
       public void init()
    public void paint(Graphics g)
    DDASMPL(160, 140, 220, 140, g);
    public void DDASMPL(int x1, int y1, int x2, int y2, Graphics g)
      dx = (x2-x1);
      dy = (y2-y1);
    //absolutex =
      if( Math.abs(dx) > Math.abs(dy))
         steps = Math.abs(dx);
      else
         steps = Math.abs(dy);
         xinc = dx / steps;
         yinc = dy / steps;
         x = x1;
         y = y1;
    //Point xxx = new Point(x1, y1);
    g.fillRect(x1, y1, 1, 1);
          for (k = 1; k < steps; k++)
              x = x+ xinc;
              y = y + yinc;
    //Point.point(Math.round(x), Math.round(y));
    g.fillRect(Math.round(x), Math.round(y),1 ,1);
         }//end else
    }//end function dda
    }//end class ddda applet

  • Java.lang symbols not found when compiling package classes

    I have a set of classes that I have wrapped up in a package. The package name and
    directory structure follow the standard required for each. These classes contain many
    java.lang.Math functions and java.lang.Double calls.
    Am I correct in that the java.lang functions will be imported automatically? When I
    compile a class that is in the package, it looks for the Math.pow (for example)
    function in the package instead of java.lang. I have tried putting the following include
    at the top:
    include java.lang.*;and I still get the "cannot resolve symbol" error. Only when I use
    include java.lang.Math;
    include java.lang.Double;does it compile properly. Is this indicative of a problem with my classpath? It is
    currently set to look in whatever the current directory is, the directory with src.jar,
    and my dev directory that contains the package I am working on.
    Please advise! Thanks in advance!
    Rodman

    Thanks for the quick reply! I looked in the package directory and found the Math.java and
    Double.java files. I'm not sure why they were there. Thanks again!

  • Cannot Import Java Classes

    I am trying to do the sample contact walkthrough in FLEX
    builder. For the Java Adapter.
    http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/js/html/wwhelp.htm?href=00000138 .html
    I cannot get any import statements to work for the java class
    files. I have tried this using the FDS as a J2EE application
    running in tomcat, I have tried with the standalone JRUN version of
    the FDS app.
    I have put the contact files everywhere I can think of, in
    the server classes folder, in the project, in the default web
    folder and nothing I try works. I have even setup the project to
    compile on the server and I get nothing. Everytime, I get errors.
    I did the tutorial from the JDJ magazine:
    http://java.sys-con.com/read/210991.htm
    I cant get that java connection to work either. Please
    someone help me.
    The flex code is below.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.data.DataService;
    import mx.collections.ArrayCollection;
    import samples.contact.Contact;
    public var ds:DataService;
    [Bindable]
    public var contacts:ArrayCollection;
    //public var contact:Contact;
    ]]>
    </mx:Script>
    <mx:DataGrid id="dg" editable="true">
    <mx:columns>
    <mx:DataGridColumn dataField="contactId" headerText="Id"
    editable="false"/>
    <mx:DataGridColumn dataField="firstName"
    headerText="First Name"/>
    <mx:DataGridColumn dataField="lastName" headerText="Last
    Name"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Application>

    Ken, thank you for replying, I have had absolutly nothing but
    problems trying to get this 'simple' thing to work.
    Here is my code.
    In the remote-config.xml file, I have this code:
    <?xml version="1.0" encoding="UTF-8"?>
    <service id="remoting-service"
    class="flex.messaging.services.RemotingService"
    messageTypes="flex.messaging.messages.RemotingMessage">
    <adapters>
    <adapter-definition id="java-object"
    class="flex.messaging.services.remoting.adapters.JavaAdapter"
    default="true"/>
    </adapters>
    <default-channels>
    <channel ref="my-amf"/>
    </default-channels>
    <destination id="SimpleJava">
    <properties>
    <source>javaSamples.SimpleMath</source>
    </properties>
    </destination>
    </service>
    Here is my MXML file: (Called new.MXML)
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    <mx:RemoteObject id="math" destination="SimpleJava">
    <mx:method name="doMath" concurrency="last"
    result="fillTxt(event.result as int)"/>
    </mx:RemoteObject>
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent
    private function fillTxt(b: int):void{
    txtResult.text = (String)
    //comment
    ]]>
    </mx:Script>
    <mx:Panel x="10" y="24" width="250" height="200"
    layout="absolute" title="Simple Math with Java">
    <mx:Label x="10" y="10" text="Input Number to
    Multiply:"/>
    <mx:TextInput x="10" y="36" id="txtNumber"
    maxChars="1"/>
    <mx:Label x="10" y="126" id="txtResult"/>
    <mx:Label x="10" y="100" text="Your Number will appear
    below:"/>
    <mx:Button x="10" y="66" label="Multiply by 2"
    click="math.doMath(txtNumber.text)"/>
    </mx:Panel>
    </mx:Application>
    Here is my SimpleJava.java file:
    package javaSamples;
    //import java.util.*;
    * @author jsanders
    public class SimpleMath {
    public int doMath(String a){
    int new_a = Integer.parseInt(a.trim());
    int b = new_a * 2;
    return b;
    //changesd
    Like I said I have had absolutly nothing but problems with
    this. Yesterday, I was getting send failures, So I did some
    reasearch found some folks who said that they had the same problem,
    and they had to hard code the app name into the services-config.xml
    file. The file used to have {context.root} in it, and that variable
    was set to /flex, now I hardcoded this line into the my-amf channel
    definition to get rid of the send failure error.
    <channel-definition id="my-amf"
    class="mx.messaging.channels.AMFChannel">
    <endpoint uri="
    http://{server.name}:{server.port}/flex/messagebroker/amf"
    class="flex.messaging.endpoints.AMFEndpoint"/>
    <properties>
    <polling-enabled>false</polling-enabled>
    </properties>
    </channel-definition>
    As you can see what should say:
    http://{server.name}:{server.port}/{context.root}
    Now says:
    http://{server.name}:{server.port}/flex.
    This was the only way I could get the send error to go away.
    Now I worry that I might have broken something else. Since I
    removed all references to {context.root} in that file.
    {context.root} is defined in the flex-config.xml file, like
    this:
    <context-root>/flex</context-root>
    I have tried it with or without the '/' in the value of the
    context.root variable.
    I have played with the remoting-config file, and I know that
    I am accessing the destination.
    I have played with the <source> option of the
    destination, and I know that I am finding the class and making a
    good connection.
    I am using the JRUN install of FDS on my box, and yesterday
    at the end of the day after getting the context.root situation
    sorted out, I got a different error something like major.minor
    versioning errors.
    So the Java guys here at work told me that the JRUN version
    packaged with FDS was 1.4, and I used 1.5 to compile my java class.
    So I recompiled this morning with the 1.4 sdk. Now I dont get that
    error about the major minor versioning anymore.
    Now I get nothing. I use firefox, and all the browser tells
    me is 'transferring data from localhost' Nothing else. It just sits
    there and does nothing.
    When I did the debug on it, I got into a loop on the
    UIComponent.as file in the callLaterDispatcher(event:Event)
    function.
    Any clues what might be causing this new hang up. Basically
    the machine just hangs. Is there a problem with the result from the
    Method I am calling in the MXML? Did I do something wrong with the
    Event as Int thing?
    Again any help would be appreciated.

  • Trouble with java security manager

    I have set up a security manager for my webapp running on Tomcat. The application enables the user to write his own scripts using Javascript, that's why I need to set up a security manager.
    Using Rhino as script interpreter, it is possible to use the standard java security mechanisms, e.g. using the security manager to handle the scripts' rights.
    I've added the following lines to my policy file:
    // give server all rights
    grant codeBase "file:webapp/WEB-INF/-" {
         permission java.security.AllPermission;
    //rights granted to scripts
    grant codeBase "file:restrictedClient" {
         permission java.io.FilePermission "webapp/WEB-INF/lib/js.jar", "read";
    I've assigned the scripts to the "restrictedClient" code base. However, the script execution fails as the script does not have the permission to access or define classes of any package (even standard java packages like java.lang or java.math).
    In java.security, I have found the following comment:
    # List of comma-separated packages that start with or equal this string
    # will cause a security exception to be thrown when
    # passed to checkPackageDefinition unless the
    # corresponding RuntimePermission ("defineClassInPackage."+package) has
    # been granted.
    # by default, no packages are restricted for definition, and none of
    # the class loaders supplied with the JDK call checkPackageDefinition.
    #package.definition=
    I now wonder, why the checkPackageDefinition is checked though there's no entry for any package to be checked.
    Extending the policy file like
    grant codeBase "file:restrictedClient" {
         permission java.lang.RuntimePermission "accessClassInPackage.webapp/WEB-INF/classes/org/mozilla/javascript";
         permission java.io.FilePermission "webapp/WEB-INF/lib/js.jar", "read";
         permission java.lang.RuntimePermission "defineClassInPackage.java.io";
         permission java.lang.RuntimePermission "defineClassInPackage.java.util";
         permission java.lang.RuntimePermission "defineClassInPackage.java.net";
         permission java.lang.RuntimePermission "defineClassInPackage.java.sql";
         permission java.lang.RuntimePermission "defineClassInPackage.java.lang";
         permission java.lang.RuntimePermission "defineClassInPackage.java.math";
         permission java.lang.RuntimePermission "de.methodpark.pkit.facade.impl";
    works, but an unpleasant feeling remains :-).
    Rhino creates an own classloader for script execution. Could that be the source of the strange behaviour?
    Any help would be appreciated!
    Regards,
    Matthias

    David,
    I was glad to see your post regarding WLS 9.2 and the troubles with enabling Java Security Manager.
    Were you able to learn any more on things like - why doesn't the admin console work when the security manager is enabled with the default policy file. Also, why is it so difficult to add permissions for your own applications and get them to actually work.
    I'd be curious to see if you were able to get it to work or if you have any insights or resources that can help with this as we are really struggling to get a restrictive policy file that works.
    Thanks,
    D

  • Warnings about merging java classes

    Hey Guys,
    While watching the logs on the sun portal server, I am noticing there are a lot of warnings about merging java.math.BigDecimal, java.math.BigInteger and com.sun.rave.web.ui.Time:
    [#|2007-03-12T09:48:22.948+1000|WARNING|sun-appserver-ee8.1_02|org.apache.commons.digester.Digester|_ThreadID=10;|[ConverterRule]{faces-config/converter} Merge(null,java.math.BigDecimal)|#]
    [#|2007-03-12T09:48:22.912+1000|WARNING|sun-appserver-ee8.1_02|org.apache.commons.digester.Digester|_ThreadID=10;|[ComponentRule]{faces-config/component} Merge(com.sun.rave.web.ui.Time)|#]
    [#|2007-03-12T09:48:27.875+1000|WARNING|sun-appserver-ee8.1_02|org.apache.commons.digester.Digester|_ThreadID=10;|[ConverterRule]{faces-config/converter} Merge(null,java.math.BigInteger)|#]
    What i would like to know is, how do i fix these warnings?
    Thanks in advance.

    You can also use Castor: http://www.castor.org
    It generates classes from XML Schemas and enables data
    binding without writing any line of a fuckin SAX
    parser :-)I evaluated Castor and JAXB and while JAXB isn't perfect, it's got some things over Castor. Castor almost looks abandonded when I go to the site. The documentation just sort of trails off.

  • PLEASE HELP!! with this java problem...

    Ok so I have this assignment regarding Loan calculations: Compute the Monthly Payments given> the APR, #of payments, and amount borrowed. The formula for this is...P= Cr(1+r)^N / (1+r)^N -1 Where P is aount payable each month, r is APR which needs to be converted into months by /12, N is number of payments, and C is total amount owed. I got this:
    import java.lang.Math;
    import java.util.Scanner;
    public class ComputeSomething
    public static void main (String s[])
    //obtain input from the user
    //validate input
    //proceed if input is valid
    //process input
    //repeat the above four steps until "quit"
    Scanner input = new Scanner (System.in);
    double payable_amount; // P
    double amount_owed; //C
    int number_of_payments; //N
    double rate; //r
    double numerator, denominator;
    System.out.print("Enter the value of amount borrowed/owed: ");
    amount_owed = input.nextDouble ();
    System.out.println ();
    System.out.print ("Enter the value of number of payments: ");
    number_of_payments = input.nextInt ();
    System.out.println ();
    System.out.print ("Enter the value of rate as a percentage, e.g., 10 for 10%: ");
    rate = input.nextDouble ();
    System.out.println ();
    rate = rate/(100*12) ;
    numerator = amount_owed * rate * Math.pow ((1+rate),number_of_payments);
    denominator = Math.pow ((1+rate),number_of_payments) - 1;
    payable_amount = numerator/denominator;
    System.out.println("The amount payable per month = " + payable_amount);
    // // implement the second formula
    // numerator = Math.log (payable_amount/amount_owed) - Math.log ((payable_amount/amount_owed) - rate);
    // denominator = Math.log (1+rate);
    // number_of_payments = (int)Math.round (numerator/denominator);
    NOW I have to change it around for the second formula and this is where I am lost cause it has logarithms....This formula goes like this N= ln P/C - ln (P/C-r) / ln(1+r) Where N is the number of monthly payments, C is the sum of actual amount borrowed which is given and r is APR, and P is the monthly payment and ln is the natural logarithm. SO in this formula I have to calculate the NUMBER of payments given the other input.... This project is just a simple command line format so the user just types in the inputs. ALSO there needs to be a command to end the session and the program needs to handle incorrect input too!!
    **I dont know how to do the second formula PLEASE HELP ME.....the formulas in picture format are located at http://www.efunda.com/formulae/finance/loan_calculator.cfm**

    Oh man sorry..what I mean to say is that yes it is a command line type program (no menus) and its going to be in the following format: you type 1 for calculating monthly payments, type 2 for #of payments, and then type 0 to quit. When you type 1 or 2 then the correct formula for each option will then be utilized by asking the input for the fields kinda like this program for a simple fahrenheit to celsius conversion:
    import java.util.Scanner;
    public class TempConverter
    // solution to inclass assignment
    public static void main (String s[])
    double temp_in_celsius;
    double temp_in_fahrenheit;
    Scanner input = new Scanner (System.in); // create a connection 'object' to read data from the k/b
    // create the menu that is displayed to the user
    System.out.println ("Choose 1 to convert temp. from C to F, 2 to convert temp. from F to C and any other value to quit");
    int choice = 0;
    if (input.hasNextInt ())
    System.out.println ("correct data type");
    choice = input.nextInt ();
    else
    System.out.println ("incorrect data entered -- program terminated!");
    System.exit (0);
    // while choice is either one or two, continue; quit otherwise.
    while(choice == 1 || choice == 2)
    if (choice == 1)
    //code for converting temp from C to F
    System.out.println ("Enter the value of temp. in the C scale: " );
    if (input.hasNextDouble ())
    temp_in_celsius = input.nextDouble ();
    temp_in_fahrenheit = ( (9/5.0) * temp_in_celsius ) + 32;
    System.out.println ( temp_in_celsius + " in degrees C is " + temp_in_fahrenheit + " in degrees F");
    else
    System.out.println ("incorrect data entered -- program terminated!");
    System.exit (0);
    else if (choice == 2)
    //code for converting temp from F to C
    System.out.println ("Enter the value of temp. in the F scale: " );
    if (input.hasNextDouble ())
    temp_in_fahrenheit = input.nextDouble ();
    temp_in_celsius = (5/9.0) * (temp_in_fahrenheit-32); //convert the temp to the C scale
    System.out.println (temp_in_fahrenheit + " in degrees F is " temp_in_celsius " in degrees C");
    else
    System.out.println ("incorrect data entered -- program terminated!");
    System.exit (0);
    else
    System.out.println ("Quitting");
    System.out.println ("Choose 1 to convert temp. from C to F, 2 to convert temp. from F to C and any other value to quit");
    if (input.hasNextInt ())
    System.out.println ("correct data type");
    choice = input.nextInt ();
    else
    System.out.println ("incorrect data entered -- program terminated!");
    System.exit (0);
    }

  • Difference between Math and StrictMath?

    What is the difference between these classes? They look the same.

    http://java.sun.com/j2se/1.4.1/docs/guide/lang/enhancements-1.3.html
    Classes java.lang.Math and java.lang.StrictMath
    The Java 2 Platform now contains two clases which provide API for performing general numeric operations.
    java.lang.StrictMath - Class java.lang.StrictMath has the same API as old class java.lang.Math, which was present previous versions of the Java platform. Unlike class Math, however, StrictMath is defined to return bit-for-bit reproducible results in all implementations.
    java.lang.Math - Class java.lang.Math provides the same set of API as does class StrictMath. However, unlike some of the numeric functions of class StrictMath, all implementations of the equivalent functions of class Math are not defined to return the bit-for-bit same results, but can vary within specified constraints. This permits better-performing implementations where strict reproducibility is not required.

  • Jave help MEGA PLEASE

    k so heres the first program
    The game of Nim has two players alternately taking marbles from a pile. In each move the player must take at least one marble, but at most half of the marbles in the pile. The player who takes the last marble loses. Write a program in which the computer plays against a human opponent. Generate a random integer between 10 and 100 (inclusively) to denote the initial size of the pile of marbles. Generate a random integer between 0 and 1 to decide whether or the computer or the human takes the first turn. Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid. In stupid mode, the computer simply takes a random legal value between 1 and n/2 from the pile whenever it has a turn. In smart mode, the computer takes off enough marbles to make the size of the pile a power of 2 - 1 ---that is, 3, 7, 15, 31, or 63. That is always a legal move, except if the size of the pile is one less than a power of 2. In that case the computer makes a random legal move. Note that the computer can not be beaten in smart mode when it has the first move, unless the pile size happens to be 15, 31, or 63.
    heres the class code
    code:--------------------------------------------------------------------------------/*
    * @(#)Nim.java 1.0 03/07/02
    * Name: Alex Ionescu
    * Period: 1
    * Date: 9/18/03
    * Assignment: Nim
    * Purpose: Program Nim game in Java
    package n;
    import javax.swing.JOptionPane;
    import java.util.Random;
    import java.lang.Math;
    import java.lang.String;
    class Nim
         private int pile;
         private int turn;
         private int firstturn;
         private int stupid;
         private int smart;
         private int computer;
         private int user;
         private int first;
         public Nim()
              pile=(int)(Math.random()*90+10);
              smart=(int)(Math.random()*100);
              stupid=(int)(Math.random()*100);
              System.out.println("Pile size is "+pile);
              firstturn=(int)(Math.random()*100 + 1); //heres the 1/100 error
              computer=0;
              user=1;
              if(firstturn>50)
                   firstturn=user;
              else
                   firstturn=computer;
              firstturn=turn;
         public void play()
              if(smart>50)
                   System.out.println("Computer is playing smart");
              else
                   System.out.println("Computer is playing stupid");
              if(firstturn==user)
                   System.out.println("You go first");
              else
                   System.out.println("Computer goes first");
    turn = firstturn;
              while(pile-1>0)
                   if(turn==user)
                        String take = JOptionPane.showInputDialog("How many marbles do you want to take away?");
                        int take2= Integer.parseInt(take);
                        while(take2>(int)(pile/2))
                             JOptionPane.showMessageDialog(null, "Only take away half or less from the pile");
                             take = JOptionPane.showInputDialog("How many marbles do you want to take away?");
                             take2= Integer.parseInt(take);
                        pile= pile-take2;
                        System.out.println("There are "+pile+" marbles left");
                        turn=computer;
                   else
                        if(smart>50)
                             pile -= smartTake();
                        else
                             pile -= stupidTake();
                   turn=user;
         private int smartTake()
              int x = (int)(Math.random())*2-1;
              int sMarbles= (int)Math.pow(2,x);
              while (sMarbles > (.5 * pile) || sMarbles==0)
                   x = (int)(Math.random())*2-1;
                   sMarbles = (int)Math.pow(2,x);
                   System.out.println("The computer took away " + sMarbles +" marbles");
                   return sMarbles;
         private int stupidTake()
              int stMarbles = pile/2;
              while (stMarbles > (.5*pile) || pile==0)
                        stMarbles = pile/2;
              System.out.println("The Computer took away " + stMarbles +" marbles");
              return stMarbles;
    the smartTake method is fucked because i just tried to make some shitty method to turn in so i had a grade
    my errors are here...
    in stupidTake method "In stupid mode, the computer simply takes a random legal value between 1 and n/2 from the pile whenever it has a turn."
    im just plain stumped on this one
    next error is in smart take.. it should take enough marbles away to make the size of the pile a power of 2 -1, which is 3, 7, 15, 31, or 63
    i had something in mind like if pile>63 sMarbles = pile-63; pile=63;
    but i did want to do it without making a bunch of if statements (think i might have to)
    also in my constructor, i have firstturn Math.random() * 100 +1 but the user should only go first once in 100 turns, so this is fucked

    k heeres the second program help
    heres the driver
    *@(#)Decode.java 1.0 03/12/10
    *@author Alex Ionescu
    *@since             Date 03/12/10
    *@period 1
    *@assignment Topic 6 Lab 1
    *@purpose Replicate the postal service's method of translating bar codes and zip codes
    package bar;
    import javax.swing.JOptionPane;
    class BarCodeDriver
         public static void main(String args[])
              String ask = JOptionPane.showInputDialog("Please enter a zipcode or barcode");
              Decode b = new Decode();
              Encode a = new Encode();
              char whatever = ask.charAt(0);
              if(whatever>=48 && whatever <=57)
                   a.Encoding(ask);
              else
                   if(whatever=='|')
                        b.Decoding(ask);
                   else
                        JOptionPane.showMessageDialog(null, "You didn't enter a zipcode or barcode, please try again");
              System.out.println(" ");
              System.exit(0);          
    }and the class
    *@(#)Decode.java 1.0 03/12/10
    *@author Alex Ionescu
    *@since             Date 03/12/10
    *@period 1
    *@assignment Topic 6 Lab 1
    *@purpose Replicate the postal service's method of translating bar codes and zip codes
    package bar;
    import javax.swing.JOptionPane;
    class Decode
         private String Barcode;
         private int Digit;
         private int zipcode;
         private int count;
         private int startstring;
         private int endstring;
         private String digit;
         public Decode()
              count = 0;
              startstring = 1;
              endstring = 6;
              Digit = 0;
              zipcode= 0;
         //pre- expect 27 lines long barcode
         //post- return the barcode translated into a zipcode
         public void bartonum(String digit)
              if(digit.equals("||:::"))
                   Digit=0;     
              else
                   if(digit.equals(":::||"))
                        Digit=1;
                        else
                             if(digit.equals("::|:|"))
                                  Digit=2;
                             else
                                  if(digit.equals("::||:"))
                                       Digit=3;
                                  else
                                       if(digit.equals(":|::|"))
                                            Digit=4;
                                       else
                                            if(digit.equals(":|:|:"))
                                                 Digit=5;
                                            else
                                                 if(digit.equals(":||::"))
                                                      Digit=6;
                                                 else
                                                      if(digit.equals("|:::|"))
                                                           Digit=7;
                                                      else
                                                           if(digit.equals("|::|:"))
                                                                Digit=8;
                                                           else
                                                                if(digit.equals("|:|::"))
                                                                     Digit=9;
              System.out.print(Digit);
              zipcode= Digit + zipcode;
         //pre- expect a barcode with checkdigit,
         //post- return the bar code in zip code form     
         //convert barcode
         public void Decoding(String b)
              //Barcode = JOptionPane.showInputDialog("Please enter a bar code");               
              String digit = b.substring(startstring,endstring);
              for(count=0;count<=4;count++)
                   bartonum((digit));
                   startstring+=5;
                   endstring+=5;
                   digit = b.substring(startstring,endstring);
              //store sum of zipcode and checkdigit
              int woah = zipcode + Digit;
              //check to see if checkdigit is right
              if(woah % 10 == 0)
                   System.out.println("...is the zipcode");
              else
                   System.out.println("...that is not a correct bar code");
    }it prints out this
    11111Exception in thread "main" java.lang.StringIndexOutOfBoundsException: Strin
    g index out of range: 31
    at java.lang.String.substring(String.java:1477)
    at bar.Decode.Decoding(Decode.java:123)
    at bar.BarCodeDriver.main(BarCodeDriver.java:30)
    its suppose to print out the 11111 but not the exception lol;

  • Need help to draw a graph from the output I get with my program please

    Hi all,
    I please need help with this program, I need to display the amount of money over the years (which the user has to enter via the textfields supplied)
    on a graph, I'm not sure what to do further with my program, but I have created a test with a System.out.println() method just to see if I get the correct output and it looks fine.
    My question is, how do I get the input that was entered by the user (the initial deposit amount as well as the number of years) and using these to draw up the graph? (I used a button for the user to click after he/she has entered both the deposit and year values to draw the graph but I don't know how to get this to work?)
    Please help me.
    The output that I got looked liked this: (just for a test!) - basically this kind of output must be shown on the graph...
    The initial deposit made was: 200.0
    After year: 1        Amount is:  210.00
    After year: 2        Amount is:  220.50
    After year: 3        Amount is:  231.53
    After year: 4        Amount is:  243.10
    After year: 5        Amount is:  255.26
    After year: 6        Amount is:  268.02
    After year: 7        Amount is:  281.42
    After year: 8        Amount is:  295.49
    After year: 9        Amount is:  310.27
    After year: 10        Amount is:  325.78
    After year: 11        Amount is:  342.07
    After year: 12        Amount is:  359.17
    After year: 13        Amount is:  377.13
    After year: 14        Amount is:  395.99
    After year: 15        Amount is:  415.79
    After year: 16        Amount is:  436.57
    After year: 17        Amount is:  458.40And here is my code that Iv'e done so far:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.lang.Math;
    import java.text.DecimalFormat;
    public class CompoundInterestProgram extends JFrame implements ActionListener {
        JLabel amountLabel = new JLabel("Please enter the initial deposit amount:");
        JTextField amountText = new JTextField(5);
        JLabel yearsLabel = new JLabel("Please enter the numbers of years:");
        JTextField yearstext = new JTextField(5);
        JButton drawButton = new JButton("Draw Graph");
        public CompoundInterestProgram() {
            super("Compound Interest Program");
            setSize(500, 500);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            amountText.addActionListener(this);
            yearstext.addActionListener(this);
            JPanel panel = new JPanel();
            panel.setBackground(Color.white);
            panel.add(amountLabel);
            amountLabel.setToolTipText("Range of deposit must be 20 - 200!");
            panel.add(amountText);
            panel.add(yearsLabel);
            yearsLabel.setToolTipText("Range of years must be 1 - 25!");
            panel.add(yearstext);
            panel.add(drawButton);
            add(panel);
            setVisible(true);
            public static void main(String[] args) {
                 DecimalFormat dec2 = new DecimalFormat( "0.00" );
                CompoundInterestProgram cip1 = new CompoundInterestProgram();
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.getContentPane().add(new GraphPanel());
                f.setSize(500, 500);
                f.setLocation(200,200);
                f.setVisible(true);
                Account a = new Account(200);
                System.out.println("The initial deposit made was: " + a.getBalance() + "\n");
                for (int year = 1; year <= 17; year++) {
                      System.out.println("After year: " + year + "   \t" + "Amount is:  " + dec2.format(a.getBalance() + a.calcInterest(year)));
              @Override
              public void actionPerformed(ActionEvent arg0) {
                   // TODO Auto-generated method stub
    class Account {
        double balance = 0;
        double interest = 0.05;
        public Account() {
             balance = 0;
             interest = 0.05;
        public Account(int deposit) {
             balance = deposit;
             interest = 0.05;
        public double calcInterest(int year) {
               return  balance * Math.pow((1 + interest), year) - balance;
        public double getBalance() {
              return balance;
    class GraphPanel extends JPanel {
        public GraphPanel() {
        public void paintComponent(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2.setColor(Color.red);
    }Your help would be much appreciated.
    Thanks in advance.

    watertownjordan wrote:
    http://www.jgraph.com/jgraph.html
    The above is also good.Sorry but you need to look a bit more closely at URLs that you cite. What the OP wants is a chart (as in X against Y) not a graph (as in links and nodes) . 'jgraph' deals with links and nodes.
    The best free charting library that I know of is JFreeChart from www.jfree.org.

  • Convert applet to swing

    Hi;
    Could anyone help me to convert my example code from applet to swing,please, thank
    import java.awt.*;
    import java.applet.*;
    import java.lang.Math;
    import java.awt.Font;
    import java.lang.Integer;
    /*** Main class == Applet  ***/
    public class Suffix extends Applet implements Runnable {
       private Thread main;
       public s_tree _tree=null;
       public node nd=null;
       public boolean userPause=false,resumed=false;
       private String str[]={"GOOGOL$","Paused","Resumed","Compacting","Done"};
       public Color bl=Color.blue,rd=Color.red;
       public Font fnt;
       public int mode=3,delay=3000;
       private char alph[]={'$','Q','W','E','R','T','Y','U','I','O',
                        'P','A','S','D','F','G','H','J','K','L',
                        'Z','X','C','V','B','N','M'};
    /*** initialisation function. It is the first Funct to be called ***/
       public void init() {
    // Temp data
          int temp=0,nxx=30;
    // Ini. of fnt , the font size + style used by this applet.
          fnt=new Font("Denis",1,25);
    /*** parsing command parameters ***/
    //      try {
    //DELAY VALUE PARAM
             String param=getParameter("DELAY");
             if (param!=null) {
                temp=Integer.parseInt(param);
                if ((temp>500)&&(temp<6000)) delay=temp;
    //x LEFTMOST coordinate
             param=getParameter("X");
             if (param!=null) {
                temp=Integer.parseInt(param);
                nxx=temp;
    //Base String parameter
             param=getParameter("STRING");
             if ((param!=null)&&(param.length()<15)) {
                str[0]=param;
    //      } catch (ParseException e) { showParseError(e); }
    // Allocating mem for _tree + initialize it .
          _tree=new s_tree(str[0],fnt);
    // Override xx (left_bound) by the caller's or the default value
          _tree.xx=nxx;
    /*** "animation loop is controled here" ***/
       public void run() {
         while(true) {
             try {
    //delay the process for time==delay
                Thread.sleep(delay);
             } catch (InterruptedException e) {}
    //controls animation loop
          repaint();
    /*** override APPLET's paint function ***/
       public void paint (Graphics g) {
    //Output graphics
          update(g);
    /*** Updates the graphics ***/
       public void update (Graphics g) {
    // Set font
          if (g.getFont()!=fnt) g.setFont(fnt);
          if ((userPause==false)&&(resumed==false)) // Is the applet paused ?
             g.clearRect(0,0,1024,768); //clears the screen
             if (_tree==null) {     // if tree is not initialised
                init();
                //_tree.show(g);
             } else {
                if (mode==3) {      // if graphics output mode is 3
                   if (nd!=null) nd._to_rd(false);
                   nd=_tree.step_compact(nd);  //compacts the tree one step further
                   if (nd==null)  // if tree is totally compacted ...
                      mode=4;   //change the ani. mode to 4 (don't call compact)
                   else
                      nd._to_rd(true);  //colors the next node to compact in red
    // Draw the "titleviewport's" comment
             g.setColor(bl);
             g.drawString(str[mode],10,15);
             _tree.show(g);     //show tree
          } else {
             g.clearRect(0,0,200,25);  //clears the "titleviewport to update it"
             g.setColor(rd);
             if (resumed==true){
                resumed=false;
                g.drawString(str[2],10,15);
             else g.drawString(str[1],10,15);
    /*** restart the animation process ***/
       public void start() {
          main=new Thread(this);
          main.start();
    /*** stops the animation ***/
       public void stop() {
          main.stop();
          main=null;
    /*** Handles the user's events (mouse , kbd , ... ***/
       public boolean handleEvent(Event evt) {
          if (evt.id==Event.MOUSE_DOWN) { //if mouse button have been pushed ...
                if (main!=null && main.isAlive()) {
                   if (userPause) {
                      main.start();
                      resumed=true;
                   } else {
                      main.stop();
                   userPause= !userPause;
                } else {
                   main= new Thread(this);
                   main.start();
                   userPause=false;
                   resumed=true;
                repaint();
             return true;
          } else {
             return super.handleEvent(evt);
    /*** Linked List of node(s) ***/
    class nodelist{
       nodelist next=null;
       node ptr=null;
       public void nodelist(){};
    /*** node of a structure tree ***/
    class node {
    // Relatives
       public nodelist children=null;
       public node parent=null;
    // variables
       public int maxchild=12,childnum=0,level=0;
       public int center[]={0,0};
       public int xlen=20,ylen=10,vspace=15,hspace=8;
       public int x[]={0,0};
       public boolean _ishidden=false;
       private Color bk=Color.black,wh=Color.white,rd=Color.red;
    // Node==red toggle variable
       public boolean to_rd=false;
    // node's text
       public String label=null;
    /*** initialisation of the node ***/
       public node(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,String nstr){
          x[0]=nx; x[1]=ny;
          xlen=nxl; ylen=nyl;
          parent=nparent;
          level=nlevel;
          label=new String(nstr);
          children=new nodelist();
    /*** destroys the node ***/
       public void destruct() {
    // NOTE : not like C++ destructors . Do not confuse .
          delete_subtree();
          children=null;
          parent=null;
          bk=wh=rd=null;
          label=null;
    /*** Node to red toggle switch ***/
       public void _to_rd(boolean b) {to_rd=b;};
    /*** Adds a child to this node ***/
       public void add_child(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
                                String nstr) {
          if (childnum<maxchild) {    // if 'legal' space left ...
             if (children==null) {    // if no nodelist attached ...
                children=new nodelist(); //init. children
                children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create node
                childnum++;
             } else {
                nodelist dummy=children;
    // search for the last nodelist
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist(); //adds a nodelist
                dummy=dummy.next;
                dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create child
                childnum++;
    // Tree needs to be realigned
    /*** adds a child and returns its address ***/
       public node add_child_ret(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
                                String nstr) {
          if (childnum<maxchild) {
             if (children==null) {
                children=new nodelist();
                children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
                childnum++;
                return(children.ptr);
             } else {
                nodelist dummy=children;
    // search for the last child
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist();
                dummy=dummy.next;
                dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
                childnum++;
                return(dummy.ptr);
        return(null);
    // Tree needs to be realigned
    /*** adds the node nchild as a new children ***/
       public void add_child(node nchild) {
          nodelist dummy=null;
          dummy=children;
          if (childnum<maxchild) {
             if (children==null) {
                children=new nodelist();
                children.ptr=nchild;
                childnum++;
             } else {
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist();
                dummy=dummy.next;
                dummy.ptr=nchild;
                childnum++;
    //Tree needs to restructured.
    /*** deletes all childrens ***/
       public void delete_subtree() {
          while (childnum>0 && children!=null) { //while child exists , kill it
             if (children.ptr!=null) {
                children.ptr.destruct();
                children.ptr=null;
                children=children.next;
             } else children=null;
             childnum--;
    /*** moves this node and its children horizontally ***/
       public void move_tree(int nx) {
          nodelist dummy=children;
          x[0]+=nx;
          while (childnum>0 && dummy!=null) {
             if (dummy.ptr!=null) {
                dummy.ptr.move_tree(nx);
                dummy=dummy.next;
    /*** removes the node from the tree (do not preserve order of ordered tree ) ***/
       public void remove_node() {
          nodelist dummy=children;
          while(dummy!=null) {
             if (dummy.ptr!=null){
                parent.add_child(dummy.ptr);
             dummy=dummy.next;
          children=null;
    //could call restructure tree here .
    //don't forget to change the node's levels !!!
    /*** show all nodes ***/
       public void show_all(Graphics g) {
          if (_ishidden==false) { //if not hidden
             if (children!=null) {  //if child exist
                nodelist dummy=children; //temp var.
                while(dummy!=null) { //while there is a child...
                   if (dummy.ptr!=null)
                      dummy.ptr.show_all(g);
                   dummy=dummy.next;
             show_node(g);
    /*** show nodes in preorder ***/
       public int preorder_show(Graphics g,int label){
          if (_ishidden==false) {
             show_node(g/*,label++*/);
             if (children!=null) {
                nodelist dummy=children;
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.preorder_show(g,label);
                   dummy=dummy.next;
          return(label);
    /** show nodes in postorder ***/
       public int postorder_show(Graphics g,int label){
          if (_ishidden==false) {
             if (children!=null) {
                nodelist dummy=children;
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.postorder_show(g,label);
                   dummy=dummy.next;
             show_node(g/*,label++*/);
          return(label);
    /*** show nodes in inorder ***/
       public int inorder_show(Graphics g,int label){
          if (_ishidden==false) {
             if (children!=null) {
                nodelist dummy=children;
                if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
                dummy=dummy.next;
                show_node(g/*,label++*/);
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
                   dummy=dummy.next;
             } else show_node(g/*,label++*/);
          return(label);
    /*** Restructure the coordinates of all nodes ***/
       public int align(int min,Font fnt,int lev,Graphics g){
          int i=min; //left bound
          FontMetrics fntm=g.getFontMetrics(fnt); //used to know the text size
          level=lev;
    // node x and y radius are computed here
          xlen=4+(int)(fntm.stringWidth(label)/2);
          ylen=4+(int)(fntm.getHeight()/2);
          if (children!=null) {      //if child present ...
             nodelist dummy=children;
             while(dummy!=null) {
                if (dummy.ptr!=null) i=dummy.ptr.align(i,fnt,lev+1,g); //align them
                   dummy=dummy.next;
          x[0]=min+(int)((i-min)/2); //could be underflow so will be checked
          x[1]=lev*(vspace+(ylen*2))+26;
    // overflow should happen only when the parent node is larger than its children
          if ((x[0]-xlen)<min) { //check uf underflow occurs.
             move_tree(min+xlen-x[0]+1);
             i=x[0]+xlen+5;
          if (childnum==0) x[0]+=2;
        return(i);
    /*** returns the child following nd ***/
    /*** if nd==null -> return 1st child ***/
    /***  if nd==last children -> return null***/
       public node next_child(node nd) {
          nodelist dummy=null;
          if (children==null) return(null);
          if (nd==null) return(children.ptr);
          dummy=children;
          while (dummy.ptr!=nd) {
             if (dummy.next!=null)
                dummy=dummy.next;
             else
                return(null);
          dummy=dummy.next;
          if (dummy!=null) return(dummy.ptr);
             else return(null);
    /*** returns child with first letter==nh ***/
       public node get_childd(char ch) {
          nodelist dummy=null;
          dummy=children;
          while (dummy!=null) {
             if (dummy.ptr!=null) {
                if (dummy.ptr.label.charAt(0)==ch)
                   return(dummy.ptr);
             dummy=dummy.next;
        return(null);
    /*** returns the nodelist containing nd ***/
       public nodelist get_child(node nd) {
          nodelist dummy=children;
          while (dummy!=null) {
             if (dummy.ptr==nd) return(dummy);
             dummy=dummy.next;
        return(null);
    /*** outputs the node to Screen ***/
       public void show_node(Graphics g) {
          if (_ishidden==false) {
             if (level>0) {  //if it is not a root then draw link-line
                g.setColor(bk);
                g.drawLine(x[0],x[1]-ylen,parent.x[0],parent.x[1]+parent.ylen); //from this node to parent node
             if (to_rd==false)
                g.setColor(wh);
             else
                g.setColor(rd);
             g.fillOval(x[0]-xlen,x[1]-ylen,xlen*2,ylen*2); //draws an oval
             g.setColor(bk);
             g.drawString(label,x[0]-xlen+4,x[1]+ylen-12);  //output the text
    /*** class which uses nodes to create a SUFFIX TREE ***/
    class s_tree {
       node root=null;    // root node.
       String str=null;   // 'search' string
       Font fnt=null;     // font type
       int xx=30;         // left limit for graphics
    /*** initialize a SUFFIX TREE with string==nstr and Font==nfnt ***/
       public s_tree(String nstr,Font nfnt) {
          str=new String(nstr);
          fnt=nfnt;
          create();
    /*** uninitialize the structure **/
       public void destruct() {
          root.destruct();
          str=null;
          fnt=null;
    /*** show the tree ***/
       public void show(Graphics g) {
          root.align(xx,fnt,0,g);   // restructure node's coordinates
          root.show_all(g); //show tree
    /*** creates a tree structure from String=str ***/
       public void create() {
          node dummy=null;
          root=new node(0,0,0,0,dummy,0," "); //create root
          root.parent=null; //just to make sure ...
          for (int i=0;i<str.length();i++) {
    // Create subtree of root in the following way :
    //    create subtree ("ASDF$");
    //        "     "    ("aSDF$");
    //       "    "      ("asDF$"); ...
    // where : the UPPERCASE letters is the part of the string sent to insert_string
             insert_string(str.substring(i));
          //root.align(0,fnt,0); //align root now ?
    /*** creates a subtree of ROOT with String=nstr ***/
       public void insert_string(String nstr) {
          node dummy2=null,dummy=null;
          int i=0;
          dummy=root;
          dummy2=root;
    // As long as a children of dummy2 have the letter nstr[i] , dummy==thischildren
    // It is used to make sure that a node does not have two children with the
    // same letter
          while (dummy2!=null) {
             dummy2=dummy2.get_childd(nstr.charAt(i));
             if (dummy2!=null) {
                i++;
                dummy=dummy2;
    //create the nodes for the rest of the string
          for(;i<nstr.length();i++) {
             if (dummy!=null) dummy=dummy.add_child_ret(0,0,0,0,dummy,1,nstr.substring(i,i+1));
    // Compacts the tree node by node and returns the next node to compact
    // if node==null , compacts the first node ...
    //Works in POST-ORDER
       public node step_compact(node nd) {
          node dummy=nd,dummy2=null;
          nodelist ndlst=null;
    // GOES TO THE LOWER LEFT CHILDREN
          if (nd==null) { //first call !
             dummy=root;
             while(dummy.children!=null) {
                if (dummy.children.ptr==null)
                   dummy.children=dummy.children.next;
                else
                   dummy=dummy.children.ptr;
    //*** tries to find a 'compactable' node ***
    //*** It uses the POST-ORDER method      ***
    // if this node is not the last children then try to find next compactable node
    // in the next children.
          if (dummy.parent.childnum!=1) dummy=next_chain(dummy);
          if (dummy==null) return(null); //fully optimized
    //remove parent node.
    /*** THIS IS WHERE COMPACTING TAKES PLACE  **/
          dummy2=dummy.parent.parent;
          ndlst=dummy2.get_child(dummy.parent);
          if (ndlst==null) return(null); //we've got a beeeeg problem if this happens ...
    //*** merges the parent string with this one and delete parent .
          dummy.label=dummy.parent.label.concat(dummy.label);
          ndlst.ptr=dummy;
          //delete parent .
          dummy.parent=null;
          dummy.parent=dummy2;
    //      root.align(0,fnt,0);
        return(dummy);
    /*** finds the next chain in the tree (i.e. the next compactable node) ***/
       public node next_chain(node nd){
          node dummy=null;
          if (nd.parent==null) return(null); //finished ! This is the root
          if (nd.parent.childnum==1) return(nd); //can be optimized
    // finds the nd.parent's child following nd
          dummy=nd.parent.next_child(nd);
          if (dummy==null)  // if OLD_nd==last child
             return(next_chain(nd.parent));      //tries to find a chain upwards
          else {
                 // OLD_nd was not the last child . nd==OLD_nd's next brother
    // GOES TO THE LOWER LEFT most child of nd's subtree.
             while(dummy.children!=null) {
                if (dummy.children.ptr==null)
                   dummy.children=dummy.children.next;
                else
                   dummy=dummy.children.ptr;
             return(next_chain(dummy)); // returns the next compactable node
    };

    First, show me the rupees! Show me the rupees!

  • Re: [iPlanet-JATO] Double Trouble

    Looks like the attachment will not be inlined by egroup's mailer so here is
    the table i was trying to send before:
    Current Type mapping (appologies for lousy formatting)
    ND ColumnDataType DATA_FIELD_TYPE_MAP
    DATA_FIELD_SQL_TYPE_MAP
    NO_TYPE String
    java.sql.Types.VARCHAR
    CHAR_TYPE String
    java.sql.Types.CHAR
    UNSIGNED_CHAR_TYPE String
    java.sql.Types.CHAR
    TINY_TYPE Short
    java.sql.Types.SMALLINT
    UNSIGNED_TINY_TYPE Short
    java.sql.Types.SMALLINT
    SHORT_TYPE Short
    java.sql.Types.SMALLINT
    UNSIGNED_SHORT_TYPE Short
    java.sql.Types.SMALLINT
    INT_TYPE Integer
    java.sql.Types.INTEGER
    UNSIGNED_INT_TYPE Integer
    java.sql.Types.INTEGER
    LONG_TYPE Long
    java.sql.Types.BIGINT
    UNSIGNED_LONG_TYPE Long
    java.sql.Types.BIGINT
    FLOAT_TYPE Float
    java.sql.Types.FLOAT
    DOUBLE_TYPE Double
    java.sql.Types.DOUBLE
    DECIMAL_TYPE java.math.BigDecimal
    java.sql.Types.DECIMAL
    DATE_TYPE java.sql.Date
    java.sql.Types.DATE
    DATETIME_TYPE java.sql.Timestamp
    java.sql.Types.TIMESTAMP
    DURATION_TYPE DONT_KNOW_CLASS_TYPE
    DONT_KNOW_CLASS_TYPE
    STRING_TYPE String
    java.sql.Types.VARCHAR
    BLOB_TYPE Object
    java.sql.Types.BLOB
    UNQUOTED_STRING_TYPE DONT_KNOW_CLASS_TYPE DONT_KNOW_CLASS_TYPE
    BOOLEAN_TYPE Boolean
    java.sql.Types.BINARY
    USER_DEFINED_TYPE DONT_KNOW_CLASS_TYPE
    java.sql.Types.JAVA_OBJECT
    Translation Tool Type Mapping Structures
    The current code generation structures that are responsible for supporting
    these type mappings at translation times are as follows:
    CodeGeneration.DATA_FIELD_TYPE_MAP
    The map is constructed from two arrays:
    CodeGeneration. ND_DATA_FIELD_DATA_TYPES
    CodeGeneration. MIGRATION_MODEL_DATA_TYPES
    CodeGeneration. DATA_FIELD_SQL_TYPE_MAP
    The map is constructed from two arrays:
    CodeGeneration. ND_DATA_FIELD_DATA_TYPES
    CodeGeneration. MIGRATION_MODEL_DATA_TYPES
    JATO Type Values
    The following JATO field values or member types are generated at translation
    time based on the type mappings:
    Model Field typing
    Model.member field type - drawn from CodeGeneration .DATA_FIELD_TYPE_MAP
    Descriptor typing
    QueryFieldDescriptor.fieldClass
    - drawn from CodeGeneration .DATA_FIELD_TYPE_MAP
    StoredProcParameterDescriptor.fieldClass
    - drawn from CodeGeneration .DATA_FIELD_TYPE_MAP
    StoredProcParameterDescriptor.sqlType
    - drawn from CodeGeneration.DATA_FIELD_SQL_TYPE_MAP
    ----- Original Message -----
    From: Mike Frisino <Michael.Frisino@S...>
    Sent: Thursday, January 04, 2001 12:19 PM
    Subject: Re: [iPlanet-JATO] Double Trouble
    Thanks John,
    Can you provide some more information that would help resolve this issue.
    It could be that the mapping rules we use during the translation need tobe
    adjusted.
    Specifically, what were the following ND property values you had for the
    field in question:
    ND Datafield property "ColumnDataType"
    ND Datafield property "ColumnDataTypeText"
    ND Datafield property "NativeType"
    ND Datafield property "NativeTypeText"
    You see, during the translation we had to choose to map from the originalND
    type information to a corresponding java or java.sql type.
    We were not certain whether to favor ND's "ColumnDataType" or ND's
    "NativeType" value.
    We came up with rules based on mapping ND's ColumnDataType. Those rulesare
    detailed in the attachment.
    ----- Original Message -----
    From: <john.teceno@b...>
    Sent: Thursday, January 04, 2001 7:33 AM
    Subject: [iPlanet-JATO] Double Trouble
    Hey Guys,
    I've run across a problem retrieving Doubles back from an Oracle
    Database. The field is defined as a Number. When we converted the
    program from NetD, it was created with return values of Double. What
    is returned is not the correct value. For example, in the table the
    value is 123456, when I do a getInternalID(), it is returning 2.0. I
    am working on a work around, but I thought that I would post this
    anyway.
    John Teceno
    Back Bay Technologies
    [email protected]
    [Non-text portions of this message have been removed]
    [email protected]

    Thank you - Jin and Todd.
    Will try that.
    Atul
    --- In iPlanet-JATO@y..., Byung Jin Chun <bchun@n...> wrote:
    try using kregedit and modify the key for the jvm args, using the -x
    parameters for the 1.2 runtime
    Jin
    -----Original Message-----
    From: Todd Fast [mailto:<a href="/group/SunONE-JATO/post?protectID=101233080150035167169232031248066208071048">Todd.Fast@S...</a>]
    Sent: Tuesday, February 19, 2002 8:40 PM
    Subject: Re: [iPlanet-JATO] Re: OutOfMemoryError
    Atul--
    Out of curiosity - How do you modify the memory parameters for
    the container's VM ?? I know I should try to do some research but
    figured you may already have some insight and willingness to
    share.
    Please consider this as low priority.It differs by container; I don't remember details of any particular one.
    >
    Todd
    For more information about JATO, including download information, please
    visit:
    http://developer.iplanet.com/tech/appserver/framework/index.jsp
    <http://developer.iplanet.com/tech/appserver/framework/index.jsp>
    [Non-text portions of this message have been removed]

Maybe you are looking for

  • Is there a way to split clips in the Event browser? (audio-synch related)

    It seems there is no way to split an event-clip (a clip that appears in the Event browser). You can split Events--but only if they consist of more than one clip. And then you can only split them between two clips. People who have transferred analog v

  • Any way to get rid of the awful white background in grid view?

    The old dark background was infinitely easier on the eyes, and more attractive. When I look at stuff in grid view now it gives me a headache. Any chance of changing this back via terminal or something?

  • Inspection setup maintained while stock in quality inspection

    Dear Consultants, While having stock in quality inspection we were still able to maintain the inspection setup in QM view of that material in that plant. Actually the system should have thrown error "To activate QM, the inspection stock for the mater

  • Run Code Continuously in Event Driven State Machine

    Hi there, I was wondering what is the best way to run code continuously in an event driven state machine. Particularly, I am going off the JKI state machine. At the moment I put the code I want to run continuously (acquire from an instrument) in the

  • Queries about Oracle User Groups

    Hi, I am planning to move to US in few months. I would like to join in any Oracle user group and attend sessions from industry experts. I would like to get some advices on 1) Should i join in IOUG (Independent Oracle Users Group) or 2) Should i prefe