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

Thread: Help with this problem

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Help with this problem

    I need to make this:
    Design a Cylinder class that has radius and height attributes, a constructor with which the values of both attributes can be set, and the getRadio (), getHeight (), setRadio () and setHeight () methods. The class will also have the toString () method that will return a String that indicates the values of its attributes. Create two objects of class Cylinder (cylinderA and cylinderB). Display the content of the attributes of both objects. Then assign one object to the other and display the contents of both on the screen. Finally, modify the content of the attributes of one of the objects and display the content of the other. Explain in detail what happens throughout the program so that what happens with the pointers is clearly visible.

    And I fully understand all until toString() method. After that I dont know how to code it. I will appreciate any help. I will paste the code I have below.

     
    class Cilindro{
     
    double radio;
    double altura;
     
     
    Cilindro() 
    {
      radio = 10;
      altura = 20;
    }
     
    public double getRadio() {
        return radio;
        }
     
     
    public double getAltura() {
        return altura;
      }
     
    public void setRadio(double radio) {
        this.radio = radio;
       }
     
       public void setAltura(double altura) {
        this.altura = altura;
        }
     
         public String toString()                 
           {                                        
                   return ("Radio = " + radio +          
                           "\nAltura = " + altura);      
     
           }
    }
    Last edited by LforHelp; December 6th, 2020 at 03:15 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with this problem

    toString() method. After that I dont know how to code it.
    A class's toString method should return a String that shows values from the class that would be useful for anyone using the class to see when printed.
    Your toString method looks like it does that.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Catch block problem. Please fix my problem.
    By damnitsme in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 3rd, 2014, 01:49 AM
  2. Problem with Project Euler problem 18
    By sara_magdy in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 19th, 2013, 12:46 PM
  3. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  4. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM
  5. Java program for 2-D Array Maze
    By Peetah05 in forum Collections and Generics
    Replies: 11
    Last Post: May 8th, 2009, 04:30 AM