Math and Integer classes gone???

Hello,
I'm using the J2ME Wireless Toolkit to build my applications. For some reason it is having problems when I try using these two classes. I get a "cannot resolve symbol" error when I try using Math.round(float) and new Integer(String). Anyone know why this is happening?
Thanks,
JD

Maybe I misunderstood the original question, I thought he was asking for a function that rounded the division of a number to the closest integer. For example: 2.95 -> 3, 2.5 -> 3, 2.48 -> 2....
I have never used fixed point math so I wanted to try out that little function of yours and I put it into my app and tested it. It seems to actually be doing integer division plus a tiny bit. Then purely on a random guess I tried replacing the 1 with a y and it was now rounding the numbers in the standard way. Here is my code and test cases:
System.out.println(roundedRatio(180,39)+"-"+roundedRatio(180,40)+"-"+roundedRatio(180,41));
          System.out.println(roundedRatio(180,71)+"-"+roundedRatio(180,72)+"-"+roundedRatio(180,73));
          System.out.println(roundedRatio(180,119)+"-"+roundedRatio(180,120)+"-"+roundedRatio(180,121));
          System.out.println(roundedRatio1(180,39)+"-"+roundedRatio1(180,40)+"-"+roundedRatio1(180,41));
          System.out.println(roundedRatio1(180,71)+"-"+roundedRatio1(180,72)+"-"+roundedRatio1(180,73));
          System.out.println(roundedRatio1(180,119)+"-"+roundedRatio1(180,120)+"-"+roundedRatio1(180,121));
     int roundedRatio(int x, int y) {
       int fpX = x << 8; // 8 is just an arbitrary number used as fixed point precision
       int fpHalf = 1 << 7; // shift one space less and you get 0.5 with that fixed point precision
       return ((fpX + fpHalf) / y) >> 8;
      int roundedRatio1(int x, int y) {
       int fpX = x << 8; // 8 is just an arbitrary number used as fixed point precision
       int fpHalf = y << 7; // shift one space less and you get 0.5 with that fixed point precision
       return ((fpX + fpHalf) / y) >> 8;
      }float values: 180/40 = 4.5, 180/120 = 2.5 etc.
output is:
4-4-4
2-2-2
1-1-1
5-5-4
3-3-2
2-2-1

Similar Messages

  • Final method and final class

    What is final method and final class in abap objects.

    ejp wrote:
    Since that doesn't work--or would overyy complex to implement... would be impossible to implement. Once the method-local copy goes out of existence, ipso facto it can never be changed. This is the whole point.I consider it impossible too, but I'm not a language/compiler/runtime expert, so I allowed for the possibility that there could be some way to do it--e.g. local variables that are references in inner classes live on the heap instead of the stack, or something. My point isn't that it's possible, just that if it were somehow to be done, it would by ugly, so we may as well consider it impossible--it just ain't gonna happen.
    we go with the logic, "Okay, we need to copies, but keeping them in sync is a nightmareNo, it is +meaningless.+No, it's not meaningless. If we have the two copies, and they're not final, then after the inner object is created, the method can continue running, and either the method or the inner object could modify its copy. As far as our code knows, it's the same variable, so there'd have to be some way to keep them in sync. That's either impossible or undesirably complex--like the above, it doesn't matter which--so it's final in order to get past the issue of keeping the copies in sync.

  • Enums and generic classes

    Hi all,
    consider the following class:
    public class Box<T> {
      // omitted
    }Suppose I create an Enum like so:
    public enum BoxEnum {
        FIRST_BOX("Box1", String.class), SECOND_BOX("Box2", Integer.class);
        private final String name;
        private final Class<?> classType;
        // The starting point of the problem
        private static Map<String, Box<?>> map;
        static {
            map = new Hashtable<String, Box<?>>();
            for (BoxEnum i : BoxEnum.values()) {
                map.put(i.getName(), new Box<Same Type as classType>());
                // note the error in the upper line
        BoxEnum(String name, Class<?> classType) {
            this.name = name;
            this.classType = classType;
        public String getName() {
            return name;
        @SuppressWarnings("unchecked")
        public <T> T getClassType() {
            return (T) classType;
    }Note where the problem occurs; what I am trying to achieve is to populate a Map. Moreover, I should be able to create a new Box holding the exact same data that is specified in the Enum constant. To be more precise, consider the following example:
    FIRST_BOX("Box1", String.class)the program should populate a Map so that the key would be "Box1" and the value would be "new Box<String>()".
    Is there a way to achieve this?
    Thank you.

    Hi, thank you for a quick response.
    I'm not really sure if I understand your reply correctly, or maybe I was not clear enough describing my question. I did try a few different approaches with your suggestion but none of them worked, so I'll try to show one more example, to make this clearer (or so I hope)
    // This is where it goes down:
    private static Map<String, Box<?>> map;
        static {
            map = new Hashtable<String, Box<?>>();
            for (BoxEnum i : BoxEnum.values()) {
                // This is the fundamental part; this is where the new Box
                // should be created, having the same data type as its
                // enum constant, thus if i == 0, then:
                String name = i.getName();  // "Box1"
                Class<?> cls = i.getClassType() // this method was corrected, please note below
                map.put(name, new Box<cls>());  // please note the cls variable; here's the error
      // the corrected method
    public <T> T getClassType() {
            return (T) classType.newInstance();
    }

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

  • Int and Integer

    whats the difference between these two anyway..?

    int is a primitive type and Integer is a class. You would generally use primitive types wherever possible because they are much more efficient. You would use classes, for instance, if you have to put your values into a collection such as an ArrayList.

  • I am confused..what is Boolean and Integer?

    What is the difference between Boolean and bolean and Integer and int?

    you can think of it this way
    // this is an Object
    public class Boolean {
    public Boolean{
    boolean status = false;
    and
    // this is a primitive
    boolean status = false;
    Both of these code would create a variable called status which would be initialized to false. The difference would be that one is an Object, the other a primitive.
    With primitives, specifically boolean, you can only do a few things to it. e.g. change the variable status to true or false.
    But with an Object of class Boolean you can do the simple conversion from false to true plus more, depending on what you want it to do (using method to act upon the object).
    For the int and Integer,
    Integer numberObject = new Integer(3);
    this would create an Object of class Integer with a parameter 3 in it.
    int numberPrimitive = 3;
    would be the primitive equivalent.
    numberObject.intValue();
    would convert the Integer object to a primtive that returns 3 for its value.
    for numberPrimitive you can probably change it to say 4, 5, 3490, 45 +546, 245/ 34543 ......whatever...
    hope this helps... =P

  • Using Timer and TimerTask classes in EJB's(J2EE)

    Does J2EE allow us to use Timer and TimerTask classes from java.util package in SessionBean EJB's ( Statless or Statefull )?.
    If J2EE does allow, I am not sure how things work in practical, Lets take simple example where a stateless SessionBean creates a Timer class
    and schedules a task to be executed after 5 hours and returns. Assuming
    GC kicks in many times in 5 hours, I wonder if the Timer object created by survives the GC run's so that it can execute the scheduled tasks.
    My gut feeling says that the Timer Object will not survive.. Just
    want to confirm that.
    I will be interested to know If there are any techiniques that can make
    the usage of Timer and TimeTask classes in EJB's possible as well as reliable with minmum impact on over all performance.

    Have a look at J2EE 1.4. I think they add a timer service for EJBs there...
    Kai

  • I recently downloaded a  bunch of songs an ringtones from Itunes on my phone. I synced up the phone to my computer to back up the files and to charge it and afterward all the new music and ringtones are gone?! Checked iTunes and they're not there either!

    I recently downloaded a bunch of songs and ringtones to my iPhone 4 and when I synced my phone to my computer to back up the files and to charge the phones the ringtones and songs were gone. They disappeared from my phone and from my iTunes as well. I checked my my iTunes for downloadable items and there was nothing there. I went onto iTunes and tried to download the same things that I had previously and when I did it said I had already downloaded them? iTunes only gave me the option to purchase the music and ringtones again.  Does this happen often or is there something wrong with the software on my iPhone?

    Hi,
    Did you have the music in your iTunes library on your computer when you signed up for match? How did you transfer the music from you iPhone to your computer? Do you have a back up.
    Jim

  • I updated my ipod 4 to ios5 and now my plus sign on the contacts and calendar are gone and i cant add events or new people what do i do??

    i updated my ipod4 to ios5 and now my plus sign on the contacts and calendar are gone!!
    and now i cant add events or new people directly to my ipod..
    how can i fix this??

    Try looking at the similar posts on the right side of this page under the heading "More Like This". The ones with the green checkmark were solved.

  • Since latest ios update, my iphone 6 loses my ringtones. I download new and that's gone the next day too

    Since latest ios update, my iphone 6 loses my ringtones. I download new and that's gone the next day too. How can I get my phone to keep my ringtones?

    Most USB port do not supply enough current to charge the iPad.

  • I just rebuilt my mail inbox, 1 iCloud account and 2 other imap accounts, and everything is gone. Nothing on the remote servers either and on all my iCloud sync mobiles. How can i recover all my emails? Thanks

    I just rebuilt my mail inbox, 1 iCloud account and 2 other imap accounts, and everything is gone. Nothing on the remote servers either and on all my iCloud sync mobiles. How can i recover all my emails? Thanks it's all my work!!!!!!!

    we do what your doing... we use the same ID for "Icloud".
    We do NOT use the same ID for:  Face time and Imessage

  • Whats the difference between an INTERFACE and a CLASS?

    Whats the difference between an INTERFACE and a CLASS?
    Please help.
    Thanx.

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A31&qt=Difference+between+interface+and+class

  • I'm new to Mac. I have an iPhone and a Mac Mini.  My original iTunes was on a Windows computer that crashed.  So, all of my iTunes Music and Movies are gone.  How do I get the movies and music from my iPhone to the new Mac Mini?

    I'm new to Mac. I have an iPhone and a Mac Mini.  My original iTunes was on a Windows computer that crashed.  So, all of my iTunes Music and Movies are gone.  How do I get the movies and music from my iPhone to the new Mac Mini?

    If you still have the crashed Win computer, you may be able to recover your music and movies from the hard drive. If you have a friend with a hard drive USB connection kit and a PC, they should be able to help.  Otherwise, check locally for computer services that might do that for you (I think Best Buy Geek Squad may be able to help). If the drive itself is in good shape, it shouldn't be too expensive. 

  • HT203175 I plugged my iPod into the computer and it says that my iPod is synced with another iTunes library, but it's not. So all my music and apps are gone. What can I do to remind the computer its the right iTunes library and get all my stuff back?

    I plugged my iPod into the computer and it says that my iPod is synced with another iTunes library, but it's not. So all my music and apps are gone. What can I do to remind the computer its the right iTunes library and get all my stuff back?

    Same as you would if you bought a pc; copy everything from your old computer to your new one.  Then you can just sync everything from the new computer, as you did with the old one.

  • I moved iTunes folder location, now all my personal song ratings and playlists are gone.  How can I get them back?  All the iTunes files are intact, just in a new location.  Running iTunes 11.1.5.5

    I moved iTunes folder location, now all my personal song ratings and playlists are gone.  How can I get them back?  All the iTunes files are intact, just in a new location.  Running iTunes 11.1.5.5 on Windows 7

    Put everything back the way it was.
    Them move the folder correctly.
    http://support.apple.com/kb/ht1364

Maybe you are looking for