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

Thread: Help with a homework problem

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with a homework problem

    I am doing an assignment that is asking for the user to put in the radius of a circle and the program figures out the area, diameter and circumference. It is using 2 different java programs to accomplish this. One with the info on how to get area, diameter and circumference and one is the demo that runs the program. I keep getting errors on my demo.
    //  Circle Class
     
    public class Circle
    {
      private double rad;
      private double Pie;
      private double area;
      private double diameter;
      private double circumference;  
     
     
      public Circle(double Radius, double PI, double Area, double Diameter, double Circumference)
      {
        Radius = rad;
        PI = Pie;
        Pie =3.14159;
        Area = area;
        Diameter = diameter;
        Circumference = circumference;
     
      }
    That is the first part and the second is:

    import java.util.Scanner;
     
    //  Circle Demo
     
    public class CircleDemo
    {
      public static void main(String [] args)
      {
     
      System.out.println("Rich Simmerman  3/4/2014/n/n");
     
      double circleRadius;
     
     
     
        Scanner keyboard = new Scanner(System.in);
     
     
      System.out.println("Enter the radius of the circle: ");
      circleRadius = keyboard.nextDouble();
     
    [I] Circle data = new Circle(circleRadius);[/I]
     
      System.out.println("The circle's area is " + data.getArea());
     
      System.out.println("The circle's diameter is " + data.getDiameter());
     
      System.out.println("The circle's circumference is " + data.getCircumference());
     
     
      }
    }

    I am really just starting out and not sure what I'm doing.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,252
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Help with a homework problem

    I keep getting errors
    Please copy the full text of the error message and paste it here. It has important info about the errors.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a homework problem

    Quote Originally Posted by Norm View Post
    Please copy the full text of the error message and paste it here. It has important info about the errors.
    1 error found:
    File: C:\Users\rich\Desktop\CircleDemo.java [line: 22]
    Error: constructor Circle in class Circle cannot be applied to given types;
    required: double,double,double,double,double
    found: double
    reason: actual and formal argument lists differ in length

    --- Update ---

    Sorry I didn't copy the whole first part of the program

    //  Circle Class
     
    public class Circle
    {
      private double rad;
      private double Pie;
      private double area;
      private double diameter;
      private double circumference;  
     
     
      public Circle(double Radius, double PI, double Area, double Diameter, double Circumference)
      {
        Radius = rad;
        PI = Pie;
        Pie =3.14159;
        Area = area;
        Diameter = diameter;
        Circumference = circumference;
     
      }
     
     
     
     
      public void setRad(double Radius)
      {
        rad = Radius;
      }
     
     
     
      public double getRad()
      {
        return rad;
      }
     
      public double getArea()
      {
        return Pie * rad * rad;
      }
     
      public double getDiameter()
      {
        return rad * 2;
      }
     
      public double getCircumference()
      {
        return 2 * Pie * rad;
      }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,252
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: Help with a homework problem

    The compiler found a call to a constructor that did NOT have the correct args.
    The compiler found: a call to a constructor that used a double
    but the constructor required: double,double,double,double,double

    Look at the constructor for the Circle class, make a note of the args it takes and then code the new statement that calls the constructor to use the required args.

    A question: Why are these values passed to the constructor:
    PI, Area, Diameter, Circumference

    PI I assume is the constant. No need to pass it
    The other 3 are supposed to be computed by the class
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a homework problem

    That's why I'm asking, I 'm still new to this and just starting out. Most still doesn't make sense to me yet. This is only my 3rd assignment, most of the others have been pretty simple.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,252
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with a homework problem

    Ok, thanks!

Similar Threads

  1. BeginnerJOptionPane( input/output) homework problem. PLEASE HELP!
    By brobertson300 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: March 7th, 2014, 01:26 AM
  2. What do I have wrong? And no, this is not a homework problem.
    By blobman23 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 29th, 2013, 06:11 AM
  3. Help with homework
    By gta1 in forum Object Oriented Programming
    Replies: 1
    Last Post: March 11th, 2013, 09:58 PM
  4. Question about homework problem.
    By Rain_Maker in forum Java Theory & Questions
    Replies: 13
    Last Post: February 7th, 2013, 08:11 PM
  5. Homework problem (scanner problems)
    By TommyFiz in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 20th, 2009, 07:10 PM