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

Thread: Help with plotting x-y coordinates.

  1. #1
    Junior Member mixmagz's Avatar
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with plotting x-y coordinates.

    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 :
    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.
    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 & coding of 1 and 2.. here is my code for #1
    This is for Point.java
    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;
        }
    }

    This is for the Circle.java which extends Point.java

    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;
        }
    }

    And Ive created a class to test my Code which i named Tester.java

    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 > 0; i--)
                {
                    System.out.println(i);
                }
                for(int i = 1; i <= 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 > 0; i--)
                {
                    System.out.println(i);
                }
                for(int i = 1; i <= 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 > 0; i--)
                {
                    System.out.println(i);
                }
                for(int i = 1; i <= 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());
            }
        }
    }

    Any help i appreciated about this.. thank you..
    And can you re-check my code if it is correct?..



  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with plotting x-y coordinates.

    ...I'm not really sure what your actual question is?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member mixmagz's Avatar
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with plotting x-y coordinates.

    Quote Originally Posted by KevinWorkman View Post
    ...I'm not really sure what your actual question is?
    About this sir.
    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.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with plotting x-y coordinates.

    I still don't see an actual question. Simply listing your requirements does not give us any indication of your actual question, or what you've tried, where you're stuck. You've posted your requirements and some code without telling us what that code does, what you want it to do, or how those two are related.

    If you want help, I suggest you ask a specific question and post an SSCCE (not your whole program) that demonstrates exactly what you're stuck on.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member mixmagz's Avatar
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with plotting x-y coordinates.

    Quote Originally Posted by KevinWorkman View Post
    I still don't see an actual question. Simply listing your requirements does not give us any indication of your actual question, or what you've tried, where you're stuck. You've posted your requirements and some code without telling us what that code does, what you want it to do, or how those two are related.

    If you want help, I suggest you ask a specific question and post an SSCCE (not your whole program) that demonstrates exactly what you're stuck on.
    Ok sir Im sorry.. okay here;s is the whole question which im trying to get solve..:

    1. A point in the x-y plane represented by its x-coordinate and y-coordinate. Design the class POINT that can store and process a point in the x-y plane. You should then perform operations on a point, such as showing the point, setting the coordinates of the point , printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate. Also write a test program to test various operations on a point.

    2. Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane. The center of the circle is point in the x-y plane. Design the class CIRCLE that can store the radius and center of the circle. Because the center is the x-y plane and you designed the class to capture the properties of a point (No 1), you must derive the class CIRCLE from the class POINT. You should be able to perform the usual operations on a circle, such as setting the radius, printing the radius, calculating and printing the area and circumference, and carrying on the usual operations on the center.

    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.

    Every circle has a center and a radius. Given the radius, we can determine the circle’s area and circumference. Given the center, we can determine its position in the x-y plane.
    Ive done the 1 & 2 But i want it to be rechecked..
    My teacher wants us to have a graph drawn (it can be text based) and when the user enters coordinates it should correctly place an '*' at that point. So, my program completely works except for the part of it putting an '*' at the coordinates entered.
    I have chosen to ask the user to enter values between 1-10 and I then display 10-1 vertically and 1-10 horizontal and the I want to place an '*' at the entered coordinate. And I think it'd be best to use arrays, but I just don't know where to begin.

    So the output should look something like this:
    10
    9
    8
    7
    6 * (If the user entered 1 and 6 it would put an asterisk here)
    5
    4
    3
    2
    1
    1 2 3 4 5 6 7 8 9 10
    The '1' is actually spaced in the program, just looks like that because I am using

    I have a problem also in #3.. its all about polymorphism. and i can't do the coding because i dont understand it fully..

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Help with plotting x-y coordinates.

    Well, what about those things have you tried? For the graph, break your problem down into small pieces. Do you have a method that draws a single row of your graph? Do you have a method that uses that method to draw every row in your graph? Do you have any logic about placing the * where it belongs?

    And as for question 3, what about it don't you understand? What did the basic tutorials and google tell you about polymorphism? What about your textbook, or the notes you must have borrowed from a classmate who did show up for class?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. ArrayList Plotting Points
    By basketball8533 in forum Collections and Generics
    Replies: 1
    Last Post: October 18th, 2011, 03:59 PM
  2. Plotting updated graph continuously
    By sudhan in forum Java Theory & Questions
    Replies: 0
    Last Post: October 17th, 2011, 09:28 PM
  3. I like plotting points :) HI!
    By fractalorbit in forum Member Introductions
    Replies: 1
    Last Post: September 5th, 2011, 10:49 AM
  4. Mapping real coordinates into GUI
    By gloor in forum AWT / Java Swing
    Replies: 2
    Last Post: May 26th, 2011, 08:35 AM
  5. Plotting w/JFreeCharts
    By Javajava in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 12th, 2010, 10:02 AM

Tags for this Thread