TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Prime b
NA
810
346k
Yet another circle problem
Mar 14 2012 5:53 PM
Ok, remember the last thread I made about the Circle problem http://www.c-sharpcorner.com/Forums/Thread/164425/circle-class.aspx
Well this is continuation, this time I have do this "Using the Cirlce class for the last assignment, implement the constructors and give the Circle a point"
So, I got the Point class
============Point class==============================
/**
* This class represents a single 2D x,y coordinate on a
* x/y mapping system.
*
* @author
*/
public class Point
{
private int x;
private int y;
/**
* Assigns 0 to a constructor
*/
public Point()
{
this.x = 0;
this.y = 0;
}
/**
* The method Point returning values for x and y
* @param x returns x
* @param y returns y
*/
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
/**
* @return the x
*/
public int getX()
{
return x;
}
/**
* @param x the x to set
*/
public void setX(int x)
{
this.x = x;
}
/**
* @return the y
*/
public int getY()
{
return y;
}
/**
* @param y the y to set
*/
public void setY(int y)
{
this.y = y;
}
/**
*
* @param x
* @param y
*/
public void move(int x, int y)
{
this.x = x;
this.y = y;
}
/**
*
* @param otherLocation
*/
public void move(Point otherLocation)
{
this.x = otherLocation.getX();
this.y = otherLocation.getY();
}
/**
*
* @param deltaX
* @param deltaY
*/
public void shift(int deltaX, int deltaY)
{
this.x = this.x + deltaX;
this.y = this.y + deltaY;
}
===============Circle class==================
/**
* This class represents a single 2D x,y coordinate on a
* x/y mapping system.
*
* @author
*/
public class Point
{
private int x;
private int y;
/**
* Assigns 0 to a constructor
*/
public Point()
{
this.x = 0;
this.y = 0;
}
/**
* The method Point returning values for x and y
* @param x returns x
* @param y returns y
*/
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
/**
* @return the x
*/
public int getX()
{
return x;
}
/**
* @param x the x to set
*/
public void setX(int x)
{
this.x = x;
}
/**
* @return the y
*/
public int getY()
{
return y;
}
/**
* @param y the y to set
*/
public void setY(int y)
{
this.y = y;
}
/**
*
* @param x
* @param y
*/
public void move(int x, int y)
{
this.x = x;
this.y = y;
}
/**
*
* @param otherLocation
*/
public void move(Point otherLocation)
{
this.x = otherLocation.getX();
this.y = otherLocation.getY();
}
/**
*
* @param deltaX
* @param deltaY
*/
public void shift(int deltaX, int deltaY)
{
this.x = this.x + deltaX;
this.y = this.y + deltaY;
}
==============Main Class================
/**
*
* @author Alexander Trowell
*/
public class CircleDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double radius; // To hold a radius
int pointX;
int pointY;
// Create a Scanner object for keyboard input
Scanner scan = new Scanner(System.in);
// Get the number for the radius
System.out.println("Please enter the circle's radius");
radius = scan.nextDouble();
scan.nextLine();
System.out.println("Please enter the circle's X point");
pointX = scan.nextInt();
scan.nextLine();
System.out.println("Please enter the circle's Y point");
pointY = scan.nextInt();
// Create an instance of the Circle class,
// passing the data that was entered as arguments
// to the constructor.
Circle circle1 = new Circle(radius);
Point point = new Point(pointX,pointY);
// Output
System.out.println("The area of the circle with radius of " + radius + " is " + circle1.getArea()
+ " with diameter of " + circle1.getDiameter() + " and with circumference of " + circle1.getCircumference()+" and circle located in the "+point);
}
The problem is when you run it , this is what you get ("
The area of the circle with radius of 25.0 is 1963.4937499999999 with diameter of 50.0 and with circumference of 157.0795 and circle located in the Point@1b67f74")
Point@1b67f74 supposed to the points the user gave, but for some reason it gives this gibberish.
Reply
Answers (
3
)
What is the major difference between Filter and servlet.
Object collision