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

Thread: Java cirkel

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java cirkel

    Create a class called Cirkel. The class shall have a constructor, which takes a parameter (radien). The radius shall be an instance variable. There shall also be to instance methods, one which returns the area and one which returns the circumference. There shall also be a class method for calculating the area of the circle (radius as parameter). After that create a testclass where a circle is created and the circumference is returned and written out. After that shall the area be returned and be written out with help of what is in the class, without creating an object (though invoking the class method).

    Hi! I have a problem with this assignment above. Anyone who can help?

    package cirkel;
     
    public class Cirkel {
          private double radien;
     
          public Cirkel(double r) {
            radien = r;
        }
          public double Diametern() {
            return 2*radien;
        }
          public double Omkretsen() {
            return Math.PI*radien*2;
        }
          public double Arean() {
            return Math.PI*radien*radien;
        }
    }

    package cirkel;
     
    public class circle {
        public static void main(String[] args){
            Cirkel CirkelObject = new Cirkel(4);
            CirkelObject.radien();
     
        }
    }

    This is how far i have reached.

    Thanks for help in advance


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

    Default Re: Java cirkel

    No one will just post an answer for you..so providing as much information about where you are stuck, any errors you receive, and any behavior that is different than you want will help you as much as it will everyone else.

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java cirkel

    Quote Originally Posted by copeg View Post
    No one will just post an answer for you..so providing as much information about where you are stuck, any errors you receive, and any behavior that is different than you want will help you as much as it will everyone else.
    Good to know since I am totally new in this...

    Then I would like to add that my biggest problem is to find connection between the classes and
    PHP Code:
    CirkelObject.radien(); 
    does not seem to work. Is "radien" wrong?


    Create a class called Cirkel. The class shall have a constructor, which takes a parameter (radien). The radius shall be an instance variable. There shall also be to instance methods, one which returns the area and one which returns the circumference. There shall also be a class method for calculating the area of the circle (radius as parameter). After that create a testclass where a circle is created and the circumference is returned and written out. After that shall the area be returned and be written out with help of what is in the class, without creating an object (though invoking the class method).

    Hi! I have a problem with this assignment above. Anyone who can help?

    package cirkel;
     
    public class Cirkel {
          private double radien;
     
          public Cirkel(double r) {
            radien = r;
        }
          public double Diametern() {
            return 2*radien;
        }
          public double Omkretsen() {
            return Math.PI*radien*2;
        }
          public double Arean() {
            return Math.PI*radien*radien;
        }
    }

    package cirkel;
     
    public class circle {
        public static void main(String[] args){
            Cirkel CirkelObject = new Cirkel(4);
            CirkelObject.radien();
     
        }
    }

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

    Default Re: Java cirkel

    See the following for a description of Instance versus Class methods, which seems to be the issue here: Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)