Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I don't get this

    I am pretty new to java and learning it from a book, I made an excercice and got something weard...
    A number between 100 and 300 shows a price with a lot of zeros...
    When i tried it again (without the '//' ) it worked, but what was the problem at the beginning?

    The task was: create an applet that calculates the price for pens

    under 10 pens 2.00€ each
    between 10 and 50 1.50€ each
    between 50 and 100 1.25€ each
    over 100 1.10€ each

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;

    public class NewServlet extends Applet
    {
    double vakTekst,b,c,d,e,f,g,temp,xtra;
    boolean onder10,tss10En50,tss50En100,groterDan100,v,w,x
    // ,u
    ;
    TextField vak=new TextField(20);
    Button knop=new Button("Klik Hier");

    public void init()
    {
    knop.addActionListener(new KnopHandler());
    vak.addActionListener(new KnopHandler());

    x=false;
    add(vak);
    add(knop);
    }

    public void paint(Graphics g)
    {
    if(x)
    {
    if(onder10)
    {
    temp=vakTekst*2;
    g.drawString("De prijs bedraagt "+temp+" euro.",50,50);
    }
    else if(tss10En50)
    {
    temp=vakTekst*1.5;
    g.drawString("De prijs bedraagt "+temp+" euro.",50,50);
    }
    else if(tss50En100)
    {
    temp=vakTekst*1.25;
    g.drawString("De prijs bedraagt "+temp+" euro.",50,50);
    }
    else if(groterDan100)
    {
    /* if(u)
    {
    temp=vakTekst*1.1;
    xtra=vakTekst*0.1;
    temp=vakTekst+xtra;
    g.drawString("De prijs bedraagt "+temp+" euro.",50,50);
    }
    else
    {
    */ temp=vakTekst*1.1;
    g.drawString("De prijs bedraagt "+temp+" euro.",50,50);
    // }
    }
    else
    {
    g.drawString("Ongeldig bedrag...",50,50);
    }
    }
    }

    class KnopHandler implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    vakTekst=Double.parseDouble(vak.getText());
    onder10=vakTekst<10;
    tss10En50=vakTekst>=10 && vakTekst<50;
    tss50En100=vakTekst>=50 && vakTekst<100;
    groterDan100=vakTekst>=100;
    // u=vakTekst>=100 && vakTekst<300;
    x=true;

    repaint();
    }
    }
    }

  • #2
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    Your description here seems fairly vague. You have more than one case of // in your code, which one are you referring to? What compiler error did you get?

    For the record, your code as you posted it compiles fine for me.

  • #3
    New to the CF scene
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when I delete all the '//' ,the problem solved
    when I enter a number between 100 and 300
    like 111 i get "De prijs bedraagt 122.10000000000001 euro"
    but 111 *1.1 is supposed to be 122.1

    i didn't get an error, its just weard...

    I use NetBeans
    Last edited by nelttjen; 01-06-2008 at 10:34 AM.

  • #4
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts
    this is from java script forum, but mybe it wil help to explain things:

    absolutelly bizare substract loop

  • #5
    New to the CF scene
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found something with the words floating and binarys from the javascript thread
    Aperiantly there is a problem with converting a Decimal into a binary...
    and i ll be different at every other converter i gues...


  •  

    Posting Permissions

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