Results 1 to 7 of 7
  1. #1
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default [SOLVED] Can't pinpoint reason for this error..

    Here is my code..I haven't been able to get it to build correctly, am using Netbeans 5.5, and yes it is a school lab so far as converting from fahrenheit to celsius, the rest is for extra credit, which I figure can't hurt.
    The error I'm getting is "class or Interface expected" on line 33 - where you see public void Main()...
    Also a " ; expected" on the last french brace...

    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    
    public class Main 
    {
        private
                double F;
                double C;
                double K;
                 
     public void SetFahrenheit() 
        {
            
            String Fahrenheit = JOptionPane.showInputDialog(null, "Please enter the temperature in Fahrenheit" );
            JOptionPane.showMessageDialog(null, "You entered the temp " + Fahrenheit);
            F = Double.parseDouble(Fahrenheit);
            
        }
        
        public void GetCelsius()
        {
            
            double Celsius = (5.0 / 9.0) * (F - 32);
            JOptionPane.showMessageDialog(null, "The temperature in Celsius is " + Celsius);
        }
    };
       
       /* public void Main() 
        {
          
    }*/
    
    
        public void Main()
         
    
            public void SetChoices()
    
    {
            String choice = JOptionPane(null, "Choose temperature input type: /n 1 for Fahrenheit /n 2 for Celsius /n 3 for Kelvin");
                int iChoice = Integer.parseInt(choice);
    
    {
            switch (iChoice) 
            {
                case 1: if (iChoice = 1)
                {
                    oTemp.SetFahrenheit();
                     break;
                }
                case 2: if (iChoice = 2)
                {
                    oTemp.GetCelsius();
                    break;
                }
                case 3: if (iChoice = 3)
                {
                    oTemp.GetKelvin();
                    break;
                }    
                default :
                {
                  oTemp.SetChoices();
                }
            }
    public static void main (void)
            {
            Main oTemp = new Main();
            oTemp.SetChoices();
    };
    }
    thanks
    Last edited by Reiyn; 03-29-2009 at 08:46 PM.

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

    Default

    You need to figure out where your class begins and where it should end, and then make sure all the curly braces match up.... yours don't. You also have some unnecessary semicolons sprinkled in there. It looks as if you're trying to cobble two classes you've found into one. I suggest re-writing the class from scratch.

  3. #3
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    Ok, I'll look at the structure..I do have issues with that part of this I'll say lol

  4. #4
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    Now I get No main class, but all else is fixed, what have I done?

    here's the new code:
    Java Code:
    import javax.swing.*;
    import javax.swing.JOptionPane;
    
    public class Main
    {
        private
                double F;
                double C;
                double K;
           
        public void SetFahrenheit() 
            {
                String Fahrenheit = JOptionPane.showInputDialog(null, "Please enter the temperature in Fahrenheit" );
                JOptionPane.showMessageDialog(null, "You entered the temp " + Fahrenheit);
                F = Double.parseDouble(Fahrenheit);       
            }
        public void SetCelsius()
            {   
                String celsius = JOptionPane.showInputDialog(null, "Please enter the temperature in Celsius" );
                JOptionPane.showMessageDialog(null, "You entered the temp " + celsius);
                C = Double.parseDouble(celsius);   
            }
        public void SetKelvin()
            {   
                String kelvin = JOptionPane.showInputDialog(null, "Please enter the temperature in Kelvin" );
                JOptionPane.showMessageDialog(null, "You entered the temp " + kelvin);
                K = Double.parseDouble(kelvin);   
            }
        public void GetCelsius()
            {   
                double Celsius = (5.0 / 9.0) * (F - 32);
                JOptionPane.showMessageDialog(null, "The temperature in Celsius is " + Celsius);
            }
        public void GetFahrenheit()
            {   
                double Fahrenheit = (9/5) *C + 32;
                JOptionPane.showMessageDialog(null, "The temperature in fahrenheit is " + Fahrenheit);
            }
        public void GetKelvin()
            {   
                double Kelvin = (5.0 / 9.0) * (F - 32);
                JOptionPane.showMessageDialog(null, "The temperature in Kelvin is " + Kelvin);
            }
        public void SetChoices()
            {
                String choice = JOptionPane.showInputDialog(null, "Choose temperature input type: /n 1 for Fahrenheit /n 2 for Celsius /n 3 for Kelvin");
                int iChoice = Integer.parseInt(choice);
            
        switch (iChoice) 
            {
                case 1: if (iChoice == 1)
                {
                     SetFahrenheit();
                     break;
                }
                case 2: if (iChoice == 2)
                {
                    SetCelsius();
                    break;
                }
                case 3: if (iChoice == 3)
                {
                    SetKelvin();
                    break;
                }    
                default:
                {
                    SetChoices();
                    break;
                }
            }
        }
        public static void main ()
            {
                Main oTemp = new Main();
                oTemp.SetChoices();
            }
        };
    thanks

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

    Default

    Your main method needs to have the args listed, even though you don't use them:
    Java Code:
    public static void main(String [] args)
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    Reiyn is offline Member
    Join Date
    Sep 2008
    Posts
    29
    Rep Power
    0

    Default

    yup! Another student caught that...thanks though, I just got it converting each way and turned it in 10 min ago, thought I'd thank the forum for the help :)

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

    Default No problem...

    You're welcome...

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

Similar Threads

  1. Replies: 3
    Last Post: 01-23-2009, 08:53 AM
  2. Getting errors for some reason
    By Swarvy in forum New To Java
    Replies: 7
    Last Post: 09-30-2008, 02:45 PM
  3. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 04:28 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
  •