Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Problems With Method Calls and Variables

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problems With Method Calls and Variables

    Here is the deal; I've been doing this program in school and my teacher feels as though he has spent too much time helping me, and he said he has gotten the program to run, but I cannot figure it out, and he won't help me anymore. Everything seems to be in order but I have 9 errors.

    Here are the program guidelines:
    Task:
    Write a program that calculates the volume of a rectangular solid with a length, width and height defined by the user. The user should be allowed to find the volume of multiple rectangular solids.

    Conditions:

     Use JOptionPane dialog boxes.
     A control loop(do while, while) should be used within main() to allow the user to run the program multiple times.
     main() should call a introduction method, a get values method and an end program method.
     The get values method should call a three parameter calculate method.
     Allow the user to enter lengths that contain decimals.
     Format the volume to two decimals.
     Do not forget System.exit(0);

    Here is my code:

    import javax.swing.JOptionPane;
    import java.text.DecimalFormat;
    import cs1.Keyboard;
     
    public class C6R7 {
     
        public static void main(String[] args) {
     
     		//loop it fool
     		do{
     			//method call
     			introduction();
     			getvalues();
     			endprogram();
     
     			//char choice
     			String word1, word2;
     			word2 = "yes";
     			boolean value;
     
     			//do it again
     			word1 = JOptionPane.showInputDialog(null,
     				"Enter yes to continue: ",
     			"Continue?", JOptionPane.QUESTION_MESSAGE);	
     
     			//equals
     			value = word1.equalsIgnoreCase(word2);
     
     		}while(value == true);
        }
     
        //-------------introduction---------------------
        static void introduction(){
        	//intro
        	JOptionPane.showMessageDialog(null,
        		"Welcome to the amazing volume calculator...",
        	"Welcome", JOptionPane.INFORMATION_MESSAGE);
        }
     
        //--------------getvalues----------------------
        static void getvalues(){
        	//variables
        	String length, width, height;
        	double lengthp = 0, widhtp = 0, heightp = 0, voulume = 0;
     
        	//decimal format
        	DecimalFormat fmt = new DecimalFormat("#####.##");
     
        	//get values
        	//input length
        	length = JOptionPane.showInputDialog(null,
        		"Enter the length of the figure: ",
        	"Length", JOptionPane.QUESTION_MESSAGE);
     
        	//input width
        	width = JOptionPane.showInputDialog(null,
        		"Enter the width of the figure: ",
        	"Width", JOptionPane.QUESTION_MESSAGE);
     
        	//input height
        	height = JOptionPane.showInputDialog(null,
        		"Enter the height of the figure: ",
        	"Height", JOptionPane.QUESTION_MESSAGE);
     
        	//parse it
        	heightp = Double.parse(height);
        	lengthp = Double.parse(length);
        	widthp = Double.parse(width);
     
        	//volume
        	volume = (lengthp * widthp) * heightp;
     
        	//output
        	JOptionPane.showMessageDialog(null,
        		"The volume of the figure is " + volume,
        	"The Volume", JOptionPane.INFORMATION_MESSAGE);
     
        }
     
        //------------------end program--------------------------------
        static void endprogram(){
        	//byebye
        	JOptionPane.showMessageDialog(null,
        		"Thank you for using the Java Volume Calculator",
        	"Have a nice day!", JOptionPane.INFORMATION_MESSAGE);
     
        	//end it
        	System.exit(0);
        }
    }

    Here are my errors:

    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:32 : cannot find symbol
    symbol : variable value
    location: class C6R7
    }while(value == true);
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:69 : cannot find symbol
    symbol : method parse(java.lang.String)
    location: class java.lang.Double
    heightp = Double.parse(height);
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:70 : cannot find symbol
    symbol : method parse(java.lang.String)
    location: class java.lang.Double
    lengthp = Double.parse(length);
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:71 : cannot find symbol
    symbol : variable widthp
    location: class C6R7
    widthp = Double.parse(width);
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:71 : cannot find symbol
    symbol : method parse(java.lang.String)
    location: class java.lang.Double
    widthp = Double.parse(width);
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:74 : cannot find symbol
    symbol : variable volume
    location: class C6R7
    volume = (lengthp * widthp) * heightp;
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:74 : cannot find symbol
    symbol : variable widthp
    location: class C6R7
    volume = (lengthp * widthp) * heightp;
    ^
    \\Hsstusvr\2012\hartgrc\Java\C6R7\src\C6R7.java:78 : cannot find symbol
    symbol : variable volume
    location: class C6R7
    "The volume of the figure is " + volume,
    ^
    8 errors

    Process completed.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Problems With Method Calls and Variables

    "cannot find symbol" means the compiler can not find a definition for that symbol that is in scope where the code is trying to use it. In scope means within the same {} pair. If you define a variable inside of a {} pair, it is not known outside of those {}s.

    Look at where the error occurs. Is there a definition for the variable within the same {}s?

    If there is not, you need to make a definition for the variable that is in the same {}s
      String var0 = "eee";  // define a varable that will be known in the following {}s
      {
         String var1 = "DDD";  // define var1 and give it value (local to these{}s)
         var1 = var0;  // Ok because var0 is in scope /known here
      } // end of scope for var1
     
      { // begin new scope
         String var2 = var1; //  here var1 is not defined (it is out of scope)
         var2 = var0;          // Ok because var0 is in scope here
      }
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Problems With Method Calls and Variables

    You must know that before using any variable, you must declare/initialize it.
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

Similar Threads

  1. Why I can't return two variables in one method?
    By netlync in forum Java Theory & Questions
    Replies: 3
    Last Post: January 13th, 2012, 02:39 AM
  2. Timer expiry calls a method
    By jack_nutt in forum Java Theory & Questions
    Replies: 1
    Last Post: July 11th, 2011, 07:46 PM
  3. Case statements to Method calls???
    By Java Neil in forum Java Theory & Questions
    Replies: 1
    Last Post: February 24th, 2011, 06:17 AM
  4. Need help understanding method calls and such
    By hackman2007 in forum Java Theory & Questions
    Replies: 8
    Last Post: July 14th, 2010, 08:18 AM
  5. Any way to map method calls?
    By Swiftslide in forum Collections and Generics
    Replies: 1
    Last Post: September 21st, 2009, 04:37 AM

Tags for this Thread