Results 1 to 7 of 7
  1. #1
    Phobos0001 is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Default need help with my 1st multi-method program

    Greetings everyone,

    i'm currently studying java as one of my subjects at TAFE, we are starting on learning to use 2 or more methods in a single program

    i have started working on an extremely simple one and i got it all working as a single method, but when i split it up and put a method call, i got a compile error "'class' or 'interface' expected" im guessing ive put my braces in the wrong spot or something and im hoping someone can help me figure out where i went wrong
    Java Code:
    import javax.swing.*;
    public class q5
    {
    	public static void main (String[] args)
    	{
    		String enter;
    		double number =0;
    		
    		enter = JOptionPane.showInputDialog("Enter a number:");
    		number = Double.parseDouble(enter);
    		
    		findAbs (number);
    		
    		System.exit(0);
    		
    	}
    	}
    		
    	{
    		public static void findAbs (double number)
    		{
    		if ( number <0 )
    		number = -number;
    				
    		JOptionPane.showMessageDialog(null,
    		"the absoloute value is:" + number, "Exerscise 6.1",
    		JOptionPane.INFORMATION_MESSAGE);
    		}
    	
    }
    any help will be greatly apriciated. once i can get one program working it will be quite easy to modify it and study where the braces are to be placed in more complex code with 3 or more methods. thanks again for any help

  2. #2
    $_ACE_$ is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Default

    remove the closing and opening braces before the "public static void findAbs" method. should work fine..

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  4. #4
    Phobos0001 is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Default

    awsome, cheers for that, ill take a look tommmorow morning and try again. thanks for your help everyone, ill let you all know how i go

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Phobos0001 is offline Member
    Join Date
    Nov 2007
    Posts
    20
    Rep Power
    0

    Default all solved

    Eranga, the reason why i had to leave it untill the next day is i have an early class that i had to wake up for, CISCO 3, and i cannot afford to fall behind in that class either

    i have weeded out the program and solved it, again thanks for the assistance, i apriciate it, its good to have a stable base program to modify for future use

    Java Code:
    import javax.swing.*;
    public class q5
    {
    	public static void main (String[] args)
    	{
    		String enter;
    		double number =0;
    		
    		enter = JOptionPane.showInputDialog("Enter a number:");
    		number = Double.parseDouble(enter);
    		
    		findAbs (number);
    		
    		System.exit(0);
    		
    	}
    	
    		
    	
    		public static void findAbs (double number)
    		{
    		if ( number <0 )
    		number = -number;
    				
    		JOptionPane.showMessageDialog(null,
    		"the absoloute value is:" + number, "Exerscise 6.1",
    		JOptionPane.INFORMATION_MESSAGE);
    		}
    		
    	
    }

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Nice to here that you have solved the question. :)

    Yes, as you said, it is better to develop any code/program by depend on the future developments. It's make sense really in the future, if not always make wired :o

Similar Threads

  1. Replies: 2
    Last Post: 01-07-2008, 08:45 PM
  2. How come multi thread don't look like it?
    By jkhoa in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-22-2007, 05:25 AM
  3. Replies: 1
    Last Post: 08-07-2007, 07:16 AM
  4. Axiomatic Multi-Platform C 1.6.4 (Mac OS X)
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 06-22-2007, 06:59 PM
  5. Axiomatic Multi-Platform C 1.6.4
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 06-22-2007, 12:49 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
  •