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 5 of 5

Thread: Cannot get to compile

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cannot get to compile

    import javax.swing.*;
    public class Circle {
     
        public double showRadius;
        public Circle (double showRadius){
                input=showRadius;
        }
        public void main(String[] args) {
            double myRadius = Double.parseDouble(JOptionPane.showInputDialog("Enter first integer"));
            double myDiameter;
            double myArea;
            calcRadius(1);
            calcRadius(myRadius);
            calcArea(1);
            calcArea(myRadius);
            calcDiameter(1);
            calcDiameter(myRadius);
     
     
        }
        public void calcRadius (double myRadius){
            double newRadius;
            newRadius = Double.parseDouble(JOptionPane.showInputDialog("Enter Radius"));
     
        }
        public void calcDiameter (double myRadius){
            double newDiameter;
            newDiameter = showRadius * 2;
     
        }
        public void calcArea (double myRadius){
            double newArea;
            newArea = 2 * myRadius * 3.14;
        }
    The error that I am receiving is:

    C:\Users\Michael\Documents\NetBeansProjects\Circle \src\circle\Circle.java:6: cannot find symbol
    symbol : variable input
    location: class Circle
    input=showRadius;

    I am new to this whole thing, and I have no clue how to fix that.

    PS: Yes, I know I'm bad at coding Java.
    Last edited by copeg; April 19th, 2011 at 12:09 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Cannot get to compile

    For future reference, please use the code tags. The error refers to the constructor of Circle - where is the variable input defined?

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cannot get to compile

    A) My apologies, good sir. Thank you for your help.

    I re-watched this tutorial and... alright, I re-worked it a little.

    import javax.swing.*;
    public class Circle {
     
        public double showRadius;
        public Circle (double showRadius){
                showRadius=input;
        }
        public void main(String[] args) {
            double input = Double.parseDouble(JOptionPane.showInputDialog("Enter Radius"));
            double myDiameter;
            double myArea;  
            calcRadius(1);
            calcRadius(input);
            calcArea(1);
            calcArea(input);
            calcDiameter(1);
            calcDiameter(input);
     
     
        }
        public void calcRadius (double input){
            double newRadius;
            newRadius = Double.parseDouble(JOptionPane.showInputDialog("Enter Radius"));
     
        }
        public void calcDiameter (double input){
            double newDiameter;
            newDiameter = showRadius * 2;
     
        }
        public void calcArea (double input){
            double newArea;
            newArea = 2 * input * 3.14;
        }
    }

    Isn't the variable input now defined within the method?

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Cannot get to compile

    Isn't the variable input now defined within the method?
    No. Every has what is called a scope. For example, variables declared outside a method cannot by seen by the method (with a few exceptions such as the case where the variable is passed to the method or they are class instance variables). In the case of the constructor
    public double showRadius;
        public Circle (double showRadius){
                showRadius=input;//what is input?
        }
    Input is nowhere to be found...however
    public double showRadius;
        public Circle (double input){
                showRadius=input;//now input has been passed, is within scope and can be used
        }
    input is passed to the method, and is now within scope. Think about if from the computer's standpoint - look at a single method knowing nothing about the other methods - what can that method see with regards to variables?

  5. #5
    Junior Member
    Join Date
    Apr 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cannot get to compile

    - I have change that, and now it says there are no classes.
    - I'm guessing it can just see input? I'm not exactly sure. I'm a... noob.

Similar Threads

  1. Cannot get to compile
    By theoneyouenvy in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 19th, 2011, 10:17 PM
  2. [SOLVED] I CANT COMPILE
    By savvas in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 31st, 2011, 11:34 AM
  3. *why won't this compile?*
    By dcshoecousa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 2nd, 2010, 07:18 PM
  4. [SOLVED] help in java i cant compile this
    By timeline in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 15th, 2010, 02:11 PM
  5. need help to compile
    By hardwarewizard in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 10:03 AM