<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Help me plotting x-y coordinates- Inheritance &amp; Polymorphism' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Help me plotting x-y coordinates- Inheritance &amp; Polymorphism' posted on the 'Java' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 17:23:55 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 17:23:55 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Help me plotting x-y coordinates- Inheritance &amp; Polymorphism</title>
      <link>http://www.programmersheaven.com/mb/java/426938/426938/help-me-plotting-x-y-coordinates--inheritance--polymorphism/</link>
      <description>&lt;strong&gt;HELLO Im New Here! ..and having problems about this ..I am doing #2 which requires #1. And im done with my code. and i have this little confuse about the Cylinder class here's the question :&lt;/strong&gt;&lt;br /&gt;
[QUOTE][I]3.	Every cylinder has a base and height, where the base is a circle. Design the class CYLINDER that can capture the properties of a cylinder and perform the usual operations on a cylinder. Derive this from the class CIRCLE designed in No.2. Some operations that can be performed by the cylinder are as follows: calculate and print the volume, calculate and print the surface area, set the height, set the radius of the base, and set the center of the base. [/i][/quote]&lt;br /&gt;
&lt;strong&gt;Im confuse about this because of Polymorphism.. I miss the lecture because im late..but im doing a self study but about this problem i cant understand and do the coding.. but i have already done in inheritance the questions &amp;amp; coding of 1 and 2..  here is my code for #1&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;[I]This is for Point.java[/i]&lt;/strong&gt;&lt;br /&gt;
&lt;pre class="sourcecode"&gt;class Point
{
    // Declare variables
    private double x;
    private double y;

    // Empty constructor
    public Point()
    {
    }

    // Constructor with variables
    public Point(double x, double y)
    {
        this.x = x;
        this.y = y;
    }

    // Used to set the new x-coordinate
    public void setX(double x)
    {
        this.x = x;
    }

    // Used to set the new y-coordinate
    public void setY(double y)
    {
        this.y = y;
    }

    // Used to display the x-coordinate
    public double getX()
    {
        return x;
    }

    // Used to display the y-coordinate
    public double getY()
    {
        return y;
    }
}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;[I]This is for the Circle.java which extends Point.java[/i]&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;import java.lang.*;
 
public class Circle extends Point
{
    // Declare variables
    private double r;
     
    // Empty constructor
    public Circle()
    {
    }
     
    // Constructor with variables
    public Circle(double x, double y, double r)
    {
        super(x, y);
        this.r = r;
    }
     
    // Used to set the radius
    public void setR(double r)
    {
        this.r = r;
    }
     
    // Used to return the radius
    public double getR()
    {
        return r;
    }
     
    // Calculates the area
    public double area()
    {
        return Math.PI*r*r;
    }
     
    // Calculates the circumference
    public double circumference()
    {
        return 2*Math.PI*r;
    }
}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;[I]And Ive created a class to test my Code which i named Tester.java[/i]&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;import java.util.*;

public class Tester
{
    static Scanner console = new Scanner(System.in);
    public static void main(String[] args)
    {
        // Declare variables
        int loopDecision, xC, yC, rC;

        // Loop statement
        System.out.println("Enter 1 to insert your own values. " +
                                    "Enter 2 to use preset values.");
        loopDecision = console.nextInt();

        /* If 1 is chosen then it goes into the if loop.
         * In the if loop the user will be able to set their
         * own coordinates and radius. They will then get the
         * area of the circle and the circumference. */
        if(loopDecision == 1)
        {
            // Ask user to input values
            System.out.println("Enter a number 1-10 for the X coordinate.");
            xC = console.nextInt();
            System.out.println("Enter a number 1-10 for the Y coordinate.");
            yC = console.nextInt();
            System.out.println("Enter the radius.");
            rC = console.nextInt();
            System.out.println();

            // Set the Circle class.
            Circle p = new Circle(xC, yC, rC);

            // Display their entered values
            System.out.println("X coordinate = " + p.getX());
            System.out.println("Y coordinate = " + p.getY());
            System.out.println();

            // These two for loops display the values on the side and bottom

            for(int i = 10; i &amp;gt; 0; i--)
            {
                System.out.println(i);
            }
            for(int i = 1; i &amp;lt;= 10; i++)
            {
                System.out.print(" " + i);
            }

            System.out.println();
            System.out.println("Radius = " + p.getR());
            // Display the area and circle
            System.out.println("Area of the circle = " + p.area());
            System.out.println("Circumference of the circle = " + p.circumference());
        }

        /* In the else loop the user will be able to see
         * the varius functions of the program. Using preset
         * values assigned by me. */
        else
        {
            // Set the values
            Circle p = new Circle(10, 3, 5);
            System.out.println();

            // Display the starting values
            System.out.println("Initial x-coordinate = " + p.getX());
            System.out.println("Initial y-coordinate = " + p.getY());
            System.out.println();

            // These two for loops display the values on the side and bottom
            for(int i = 10; i &amp;gt; 0; i--)
            {
                System.out.println(i);
            }
            for(int i = 1; i &amp;lt;= 10; i++)
            {
                System.out.print(" " + i);
            }

            System.out.println();
            System.out.println("Initial radius = " + p.getR());

            System.out.println();
            System.out.println("Now changing the values.");
            System.out.println();

            // Set new values
            p.setX(5);
            p.setY(10);
            p.setR(4);

            // Display the new values
            System.out.println("X coordinate = " + p.getX());
            System.out.println("Y coordinate = " + p.getY());
            System.out.println();

            // These two for loops display the values on the side and bottom
            for(int i = 10; i &amp;gt; 0; i--)
            {
                System.out.println(i);
            }
            for(int i = 1; i &amp;lt;= 10; i++)
            {
                System.out.print(" " + i);
            }

            System.out.println();
            System.out.println();
            System.out.println("Radius = " + p.getR());
            // Show area and circumference with the new values
            System.out.println("Area of the circle = " + p.area());
            System.out.println("Circumference of the circle = " + p.circumference());
        }
    }
}&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;[I]Any help i appreciated about this.. thank you..[/i]&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;[I]And can you re-check my code if it is correct?..[-O&amp;lt;[/i]&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/java/426938/426938/help-me-plotting-x-y-coordinates--inheritance--polymorphism/</guid>
      <pubDate>Mon, 23 Jan 2012 05:46:08 -0700</pubDate>
      <category>Java</category>
    </item>
  </channel>
</rss>