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: who can help me write this program?

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default who can help me write this program?

    The UML diagram of the Rectangle class of type.lib contains the following two entries in the method compartment:
    getCircumference() : int
    hashCode() : int

    write the app that starts by prompting for and reading the width and height of a rectangle, both of type int. the app then creates a rectangle object using the Rectangle class of type.lib. finally the app invokes the above two methods and outputs their returns. Here is a samlple run:
    Enter the width: 3
    Enter the height: 4
    The return of getCircumference is: 14
    The return of hashcode is: 95


  2. #2
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: who can help me write this program?

    What have you got so far?

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: who can help me write this program?

    public class Rectangle
    {
    private int width;
    private int height;
    public Rectangle(int width, int height)
    {
    Rectanlge x = new Rctangle(int width, int height);
    int x = getCircumference();

    }

    }

  4. #4
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: who can help me write this program?

    These are weird specifications. Why would a Rectangle class have a "getCircumference" method? Rectangles have perimeters, not circumference. Your Rectangle class is off to a good start. It looks like you defined the constructor (that public Rectangle(in width, int height) method, but the body of that method isn't correct. A constructor is a special function that is automatically invoked when you create an object. I think the code you've written will just create an endless loop (if you fix those misspellings of Rectangle).

    The code inside there should be written outside the class, inside your main function. You also need to use dot notation to access a class's method or variable. Such as x.getCircumference();

Similar Threads

  1. write a java program
    By mohd faizan shekh in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 9th, 2013, 05:31 PM
  2. how to write a program
    By Akash in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 26th, 2013, 05:32 AM
  3. Help me write this program.
    By HuKjr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 6th, 2011, 11:05 AM
  4. How would I write this program?
    By mjballa in forum Java Theory & Questions
    Replies: 2
    Last Post: November 14th, 2011, 11:49 PM
  5. how can i write this program
    By lavudyagopi27 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 17th, 2010, 08:11 AM