Results 1 to 4 of 4
  1. #1
    Fidelcashflow is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default Help with plotting x-y coordinates

    My Assignment:
    1. A point in the x-y plane is 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 operation 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 operation 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 a circle is a point in the x-y plane. Design the class Circle that can store the radius and center of the circle. Because the center is a point in the x-y plane and you designed the class to derive the class Circle from the class Point. You should be able to perform the usual operation on a circle, such as setting the radius, printing the radius, calculating and printing the area and circumference, and carrying out the usual operation on the center.
    I am doing #2 which requires you to do #1.

    My Problem: 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 any help would really be appreciated.

    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 [quote].

    Java Code:
    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());
    		}
    	}
    }
    Java Code:
    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;
    	}
    }
    Java Code:
    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;
    	}
    }

  2. #2
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    Dont you need some kind of is statement when you print?

    Java Code:
     if (i==6)
    Last edited by ocean; 12-02-2009 at 12:07 PM.

  3. #3
    Fidelcashflow is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by ocean View Post
    Dont you need some kind of is statement when you print?

    Java Code:
     if (i=6)
    Well, I don't think an if statement would work for this kind of thing. The reason that I mentioned using arrays was because my teacher said it'd be a good way to go. But we can do it anyway we wanted. Thank you for the reply though :).

  4. #4
    ocean is offline Senior Member
    Join Date
    Sep 2009
    Location
    Sweden/Borås
    Posts
    107
    Rep Power
    0

    Default

    You need an array to store the numbers? then mabey something like.

    Java Code:
     int[] n = {1,2,3,4,5,6,7,8,9,10};
              
                for (int i = 0; i < n.length; i++ ){
                    if (i == 1){
                        System.out.print("*");
                    }
                   System.out.print(n [i]);
        }
    Or mabey i dont understand what you want =)

Similar Threads

  1. Help in plotting graph
    By javafanatic in forum New To Java
    Replies: 20
    Last Post: 12-07-2009, 01:55 PM
  2. Help regarding 3D graph plotting...
    By Megatron in forum New To Java
    Replies: 1
    Last Post: 05-21-2009, 05:26 PM
  3. Help! Plotting a function
    By cvubando in forum New To Java
    Replies: 14
    Last Post: 02-20-2009, 08:34 AM
  4. graph plotting
    By sirine in forum New To Java
    Replies: 5
    Last Post: 01-25-2009, 04:34 PM
  5. line plotting math
    By Ace_Of_John in forum Java 2D
    Replies: 1
    Last Post: 01-19-2008, 11:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •