Home > Back-end >  Please can you help me, thank you
Please can you help me, thank you

Time:10-05

1: the design of a Rectangle is a Rectangle class, including the top left corner coordinates (x1, y1), length (w) and high (h) four data members, write a Rectangle class the following methods:
1, write the appropriate constructor initializes a rectangle;
2, the calculation method of rectangular area getArea ();
3, write whether the rectangle Contains point method to calculate the Contains (int x, int y).
Enter

At the upper left of the input a rectangular coordinates, long and high;
Input a coordinates x, y;
O

The area of the rectangle
Decision point (x, y) within the rectangle, if within the rectangle, such as the sample, please format output within the rectangle, if not, please as the sample format output outside the rectangle,
System. Out. Println (" (" + I + ", "+ j +") "+" in the rectangle (" + a + ", "a + b +"), "+" w="+ x +", "+" h="+ (int) y +" inside ");
Or
System. Out. Println (" (" + I + ", "+ j +") "+" in the rectangle (" + a + ", "a + b +"), "+" w="+ x +", "+" h="+ (int) y +" outside ");
}
Difficulty

Introduction to
The input sample

1
45 3
2 2
Sample output

Area=15.0
(2, 2) in a rectangle (1, 4), w=5, h=3


Class 2: to design a circle, containing the center and radius of the two data members, 1, write the appropriate constructor initializes a circle; 2, the method of calculation area getArea (), 3, calculation, whether they contain the contains of Point (Point), the contains (int x, int y).
Enter

Enter a circle's center and radius;
Enter a point P;
Input a coordinates x, y;
O

Determine whether the point P and coordinate within the circle,
The output format is as follows:
System. The out. Println (" (" + p2. GetX () + ", "+ p2. GetY () +") in the circle (" + p1. GetX () + ", "+ p1. GetY () +"), r="+ p1. GetR () +" ");
System. The out. Println (" (" + p2. GetX () + ", "+ p2. GetY () +") is not in the circle (" + p1. GetX () + ", "+ p1. GetY () +"), r="+ p1. GetR () +" ");
System. The out. Println (" (" + x3 + ", "+ y3 +") in the circle (" + p1. GetX () + ", "+ p1. GetY () +"), r="+ p1. GetR () +" ");
System. The out. Println (" (" + x3 + ", "+ y3 +") is not in the circle (" + p1. GetX () + ", "+ p1. GetY () +"), r="+ p1. GetR () +" ");
Difficulty

General
The input sample

3 5 2
5 5
3, 4,
Sample output

(5, 5) is not in the circle (3, 5), r=2.0 within
(3, 4) in (3, 5), r=2.0

CodePudding user response:

2. Import Java. Util. Scanner;
Public class lop {
Public static void main (String [] args) {
//TODO Auto - generated method stub
Int x1, x2, x4, x5, x6, x7;
Double x3;
Scanner sc=new Scanner (System. In);
X1=sc. NextInt ();
X2=sc. NextInt ();
The x3=sc. NextDouble ();
X4=sc. NextInt ();
X5=sc. NextInt ();
X6=sc. NextInt ();
X7=sc. NextInt ();
Circle p1=new circle (x1, x2, x3);
Point k=new point (x4, x5);
P1. Containspoint (x4, x5);
P1. Containspoint (x6, x7);

}

}

The class circle
{
Int x, y;
Double r;
Public circle (int x, int y, double r)
{this.=x x; This. Y=y; This. R=r; }

Public int getX () {
Return the x;
}



Public void your setX (int x) {
This.=x x;
}
Public int getY () {
The return of y;
}
Public void setY (int y) {
This. Y=y;
}
Public double getR () {
Return r;
}
Public void setR (double r) {
This. R=r;
}
Public double getarea () {
Double p=3.14 * this. R * this. R;
Return the p;
}

Public Boolean Containspoint (int a, int b) {
Boolean I=false;

Double d=Math. Abs (a - x);
Double e=Math. Abs (b - y);
If (d + e d * * e & lt; R * r) {
System. The out. Println (" (" + a + ", "a + b +") in the circle (" + x + ", "+ y +"), r="+ r +" ");
return true;
} else {
System. The out. Println (" (" + a + ", "a + b +") is not in the circle (" + x + ", "+ y +"), r="+ r +" ");
return false;
}
}

}

The class point {
Int x, y;
Public point (int a, int b) {
X=a; Y=b;
}
Public int getX () {
Return the x;
}
Public void your setX (int x) {
This.=x x;
}
Public int getY () {
The return of y;
}
Public void setY (int y) {
This. Y=y;
}


}






  • Related