Results 1 to 12 of 12
  1. #1
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default Need help quick!

    I dont understand what´s wrong with my code. Some parts are in swedish, but maybe it doesnt matter anyway. The program must be able to count, in this case the year tax.


    import javax.swing.*;
    public class Inkomstskatt {
    public static void main (String[] arg){
    Toolkit.getDefaultToolkit().beep();
    int knappNr = 0;
    while (knappNr = 0) {
    String s = JOptionPane.showInputDialog ("Ange årsinkomst")
    double inkomstskatt = 0;
    int x1 = Integer.parseInt(s);//x1 = inkomst//
    if(x1<= 8900)
    inkomstskatt = 0;
    else if (x1 > 8900 && <=198700)
    inkomstskatt = 100;
    else if (x1 > 198700)
    inkomstskatt = 100 + (x1 - 198700) * 0.20;
    JOptionPane.showMessageDialog(null, "Årlig skatt:"+inkomstskatt+"Kr");
    knappNr = JOptionPane.showConfirmDialog(null,
    "Skall ytterliggare beräknar utföras?,
    "Fråga", JOptionPane.YES_NO_OPTION);
    }
    System.exit(0);
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Make sure that:
    • All of your Strings have beginning quotes and end quotes
    • All statements that need to end with semicolon do in fact end in semicolons
    • That you don't use assignment operater "=" in if blocks:
      Java Code:
      if (x = y) {  // *** not this
      where you want to use the equality operator, "==":
      Java Code:
      if (x == y) { // this is OK
    • If you use compound boolean statements joined with the && operator, that both statements can stand on their own. In other words it's not:
      Java Code:
      if (a >= b && < c) {  // *** not this
      but instead is
      Java Code:
      if (a >= b && a < c) {  // this is OK
    • Never add good code to bad code. That is add code in small amounts to your program and make sure that this code compiles before attempting to add any more code. Else you'll end up with a mess of errors like you have now.


    good luck!

  3. #3
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    Is this better?

    import javax.swing.*;
    public class Inkomstskatt {
    public static void main (String[] arg){
    int knappNr = 0;
    while (knappNr == 0) {
    String s = JOptionPane.showInputDialog ("Ange inkomst");
    double skatt = 0;
    int x1 = Integer.parseInt(s);//x1 = inkomst//
    if (x1 <= 8900)
    skatt = 0;
    else if (x1 > 8900 && x1 <= 198700)
    skatt = 100;
    else if (x1 > 198700)
    skatt = 100 + (x1 - 198700) * 0.20;
    JOptionPane.showMessageDialog(null,"Skatt per år:"+skatt+"Kr");
    knappNr = JOptionPane.showConfirmDialog
    (null,"Skall ytterliggare beräkningar utföras?","Fråga", JOptionPane.YES_NO_OPTION);
    }
    System.exit(0);
    }
    }

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Does it work?

    Does it work? Do you get any errors?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    It worked, but I found some code on the internet and Im afraid the teacher will suspect that I cheated and didnt understand. I understand this program. Thats why I choosed it.

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    If you think that your teacher will suspect something, then he will. For example, have you seen the JOptionPane class in your studies? If not, then you better have a good excuse why you used it and understand how it works.
    It's not a good idea to take code from the web when you're learning Java... there's no learning process involved. That is why I never post complete solutions in this forum. I give links, hints and pseudo code so the OPS can learn instead just doing a cut & paste.

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    I didnt copy much, but yes there are som similarities. I have problems to read my book, because I have ADHD. So maybe you know a homepage where I can find the codes without a lot of text. I need it more direct! If not I just get more confused.

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  9. #9
    skatefreak is offline Member
    Join Date
    Jan 2009
    Posts
    18
    Rep Power
    0

    Default

    Hey,
    I'm in the process of learning java myself but i wouldnt be so quick to pin your learning style on ADHD there.

    I have to admit that I would prefure to work through and learn how the code operates from the ground up but I find I have far more sucess if I can get hold of a working part of code and play around with it a little, get to know the expressions and such and then retrospectilvly read about it :)

    I guess its partly because I can get a basic understanding for how to implement/write the code and go back and through further reading, learn the correct implimentations etc :)

    -Jvr

  10. #10
    Manikyr is offline Member
    Join Date
    Jan 2009
    Posts
    17
    Rep Power
    0

    Default

    Normally I learn very fast and mathematics/physics is my biggest passions, but when theres to much bla bla I have a hard time getting focused. Thank you for your help!

  11. #11
    VinceGuad is offline Member
    Join Date
    Jan 2008
    Posts
    36
    Rep Power
    0

    Default

    Try to format your code so its easier on the eyes and also take advantage of the *
    Java Code:
    **
    *

  12. #12
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default This is going to be interesting...

    ... also take advantage of the *
    uh.... question: what is it advantage of the *?

    CJSL

    EDIT: it just dawned on me... you're trying to make to the 20 posts (with useless information). Don't go there... let the 20 posts come naturally ... you'll just anger people... like me.
    Last edited by CJSLMAN; 01-28-2009 at 05:19 AM. Reason: updating my question with a comment
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Quick Question
    By Graeme in forum New To Java
    Replies: 4
    Last Post: 01-08-2009, 09:01 PM
  2. Quick Question
    By Spenc in forum New To Java
    Replies: 3
    Last Post: 09-22-2008, 03:26 PM
  3. quick easy question
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-19-2008, 04:28 PM
  4. Quick Help Please! Can't Run Code!!
    By VinceGuad in forum Eclipse
    Replies: 4
    Last Post: 01-16-2008, 04:54 AM

Posting Permissions

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