Results 1 to 4 of 4
  1. #1
    rjthomp is offline Member
    Join Date
    Jul 2015
    Posts
    2
    Rep Power
    0

    Question Error with my code

    I am doing an assignment for my class, and I keep "fixing" the errors I get when I attempt to compile the code, but I get to 1 error, and then i'm back up 100. I have tried setting the bands and colors, etc, as int, double, float, boolean, and I've tried multiple combinations of those. Can someone please evaluate my code and let me know what I am doing wrong.



    import javax.swing.JOptionPane;

    public class Resistor
    {
    public static void main(String[] args)
    {

    String input;

    boolean Black = 0,
    Brown = 1,
    Red = 2,
    Orange = 3,
    Yellow = 4,
    Green = 5,
    Blue = 6,
    Violet = 7,
    Gray = 8,
    White = 9,
    Gold = 0.05,
    Silver = 0.1,
    None = 0.2,
    Band1,
    Band2,
    Band3,
    Tolerance,
    Bands;

    input = JOptionPane.showInputDialog("What color is the first band? " +
    "\n Black, Brown, Red, Orange, Yellow, " +
    "\n Green, Blue, Violet, Gray, or White.");
    Band1 = Double.parseDouble(input);

    if(Black)
    {
    Band1 = 0;
    }
    else if(Brown)
    {
    Band1 = 10;
    }
    else if(Red)
    {
    Band1 = 20;
    }
    else if(Orange)
    {
    Band1 = 30;
    }
    else if(Yellow)
    {
    Band1 = 40;
    }
    else if(Green)
    {
    Band1 = 50;
    }
    else if(Blue)
    {
    Band1 = 60;
    }
    else if(Violet)
    {
    Band1 = 70;
    }
    else if(Gray)
    {
    Band1 = 80;
    }
    else if(White)
    {
    Band1 = 90;
    }
    else
    {
    JOptionPane.showMessageDialog(null, "Error! Invalid Input!!!");
    }

    input = JOptionPane.showInputDialog("What color is the second band? " +
    "\n Black, Brown, Red, Orange, Yellow, " +
    "\n Green, Blue, Violet, Gray, or White.");
    Band2 = Double.parseDouble(input);

    if(Black)
    {Band2 = 0;}
    else if(Brown)
    {Band2 = 1;}
    else if(Red)
    {Band2 = 2;}
    else if(Orange)
    {Band2 = 3;}
    else if(Yellow)
    {Band2 = 4;}
    else if(Green)
    {Band2 = 5;}
    else if(Blue)
    {Band2 = 6;}
    else if(Violet)
    {Band2 = 7;}
    else if(Gray)
    {Band2 = 8;}
    else if(White)
    {Band2 = 9;}
    else
    {
    JOptionPane.showMessageDialog(null, "Error! Invalid Input!!!");
    }

    input = JOptionPane.showInputDialog("What color is the third band? " +
    "\n Black, Brown, Red, Orange, Yellow, " +
    "\n Green, Blue, Violet, Gray, or White.");
    Band3 = Double.parseDouble(input);

    if(Black)
    {Band3 = 1;}
    else if(Brown)
    {Band3 = 10;}
    else if(Red)
    {Band3 = 100;}
    else if(Orange)
    {Band3 = 1000;}
    else if(Yellow)
    {Band3 = 10000;}
    else if(Green)
    {Band3 = 100000;}
    else if(Blue)
    {Band3 = 1000000;}
    else if(Violet)
    {Band3 = 10000000;}
    else if(Gray)
    {Band3 = 100000000;}
    else if(White)
    {Band3 = 1000000000;}
    else
    {
    JOptionPane.showMessageDialog(null, "Error! Invalid Input!!!");
    }

    input = JOptionPane.showInputDialog("What color is the " +
    "tolerance band?" + "\n Gold, Silver " +
    "or None.");
    Tolerance = Double.parseDouble(input);

    if(Gold)
    {Tolerance = 0.05;}
    else if(Silver)
    {Tolerance = 0.1;}
    else if(None)
    {Tolerance = 0.2;}
    else
    {
    JOptionPane.showMessageDialog(null, "Error! Invalid Input!!!");
    }

    Bands = (Band1 + Band2);

    JOptionPane.showMessageDialog(null, "Your resistor has a value " +
    "of " + Bands * Band3 +
    "plus or minus " + Tolerance);
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Error with my code

    I can see you didn't read my response in your earlier thread a couple of weeks ago: http://www.java-forums.org/new-java/...r-my-code.html

    Why should anyone take the trouble to respond here?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Error with my code

    Please edit your post and wrap the code in code tags.

    but I get to 1 error, and then i'm back up 100.
    Copy the full text of any error messages and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Xen
    Xen is offline Member
    Join Date
    Jan 2015
    Posts
    86
    Rep Power
    0

    Default Re: Error with my code

    What they're saying is that your code is unreadable like this. It makes it really hard for a common bystander to help another common bystander if the code is so hard to read that it will take a lot of energy just to see what's there.

    Asking for solutions to your problems like that is a big ask in any case, you are basically asking someone to do your homework. Then at least make it easy on the person doing the helping.

Similar Threads

  1. code error
    By jovin555 in forum New To Java
    Replies: 8
    Last Post: 01-31-2013, 08:32 AM
  2. Error in my code
    By MikeJ39 in forum New To Java
    Replies: 2
    Last Post: 10-19-2011, 09:58 PM
  3. error code help please..
    By andnlou2678 in forum New To Java
    Replies: 7
    Last Post: 10-07-2011, 12:11 AM
  4. error in code
    By Akap in forum New To Java
    Replies: 4
    Last Post: 01-31-2011, 06:37 AM
  5. Pls help with a code error.
    By saytri in forum New To Java
    Replies: 8
    Last Post: 12-24-2007, 08:10 PM

Posting Permissions

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