Results 1 to 3 of 3
  1. #1
    nischalinn is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default error passing value of a variable from one class to main method of another class

    I've 3 classes.
    1. Circle
    2. GetInputFromUser
    3. testCircle

    Cirlce CLASS:
    package ABC;

    public class Circle {
    private double radius;

    public double getRadius() {
    return radius;
    }
    public double getArea()
    {
    return radius*radius*Math.PI;
    }
    }
    GetInputFromUser CLASS
    package ABC;
    import java.util.Scanner;


    public class GetInputFromUser
    {
    float rad;
    Scanner in = new Scanner(System.in);

    public float GetInput(float radius)
    {
    System.out.println("Enter the radius of the circle");
    rad = in.nextFloat();
    return rad;

    }
    }
    testCircle CLASS
    package ABC;

    public class testCircle{

    public static void main(String[] args)
    {

    GetInputFromUser ui1 = new GetInputFromUser();
    float getRadius;
    getRadius = ui1.GetInput();

    System.out.println(" radius "+ getRadius);
    System.out.println(" radius ");

    }
    }
    In the testCircle class, in the line:
    getRadius = ui1.GetInput();
    it's showing the error:
    The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()

    and when I do:
    getRadius = ui1.GetInput(rad);
    it's showing the error:
    rad cannot be resolved

    I can not figure out why I am getting this error, where is my code going wrong.
    Please can any one help me.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: error passing value of a variable from one class to main method of another class

    Java Code:
    public float GetInput(float radius)
    expects you to pass a float. This does not make sense as it is never used.
    Java Code:
    getRadius = ui1.GetInput(rad);
    -> rad is not defined in testCircle

    As per the coding conventions class names start with a capital letter.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,539
    Rep Power
    5

    Default Re: error passing value of a variable from one class to main method of another class

    And please use the code tags and not quote tags for encapsulating code. Got to the advanced editor. Highlight your pasted code, and then click the octothorpe (#).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 8
    Last Post: 11-22-2012, 07:16 AM
  2. main method not found error in class . wat s the error?
    By kirankumaragnihotram in forum New To Java
    Replies: 10
    Last Post: 06-29-2012, 11:26 AM
  3. Replies: 1
    Last Post: 06-27-2012, 02:55 PM
  4. Replies: 7
    Last Post: 06-18-2012, 09:31 PM
  5. Replies: 0
    Last Post: 10-23-2011, 10:49 PM

Tags for this Thread

Posting Permissions

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