java题:设计point类用来定义平面上的一个点,用构造函数传递坐标位置编写测试类在该类中实现point类的对
再加一道:设计长方形类,成员变量包括长方形的长和宽。类中由计算面积和周长的方法,并有相应的set和get方法设置,获得得长方形的长和宽。编写测试类是否达到预定功能要求使用...
再加一道:设计长方形类,成员变量包括长方形的长和宽。类中由计算面积和周长的方法,并有相应的set和get方法设置,获得得长方形的长和宽。编写测试类是否达到预定功能要求使用自定义的包。
展开
4个回答
展开全部
1.
class Point{
public int x,y;
public Point(int x,int y){
this.x=x;
this.y=y;
}
}
class test{
Point point=new Point(1,2);
System.out.println(point.x);
System.out.println(point.y);
}
2.
package test.rect;
class RECT{
int width=0,height=0;
public void setWidth(int w){
width=w;
}
public void setHeight(int h){
height=h;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public int s(){
return width*height;
}
public int l(){
if(width != 0 && height != 0)
return 2*(width+height);
else
return 0;
}
}
class test(){
RECT rect=new RECT();
rect.setWidth(5);
rect.setHeight(6);
System.out.println(rect.s());
System.out.println(rect.l());
}
class Point{
public int x,y;
public Point(int x,int y){
this.x=x;
this.y=y;
}
}
class test{
Point point=new Point(1,2);
System.out.println(point.x);
System.out.println(point.y);
}
2.
package test.rect;
class RECT{
int width=0,height=0;
public void setWidth(int w){
width=w;
}
public void setHeight(int h){
height=h;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public int s(){
return width*height;
}
public int l(){
if(width != 0 && height != 0)
return 2*(width+height);
else
return 0;
}
}
class test(){
RECT rect=new RECT();
rect.setWidth(5);
rect.setHeight(6);
System.out.println(rect.s());
System.out.println(rect.l());
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第一题:
/* MyPoint.java */
// class MyPoint
public class MyPoint {
public MyPoint(int x,int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
private int x;
private int y;
}
/* Test.java */
// class Test
public class Test{
public static void main(String[] args) {
MyPoint point = new MyPoint(3, 4);
System.out.println(point.getX());
System.out.println(point.getY());
}
}
第二题:
/* MyRect.java */
package myShapes;
// class MyRect
public class myRect {
public MyRect() {};
public MyRect(int h, int w) {
width = w;
height = h;
}
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int area() {
return width * height;
}
public int perimeter() {
return 2 * (width + height);
}
private int width;
private int height;
}
/* Test.java */
package myShapes;
// class Test
public class Test() {
public static void main(String[] args) {
MyRect rect = new MyRect(8, 9);
System.out.println(rect.getWidth());
System.out.println(rect.getHeight());
System.out.println(rect.area());
System.out.println(rect.perimeter());
MyRect rect=new MyRect();
rect.setWidth(7);
rect.setHeight(8);
System.out.println(rect.getWidth());
System.out.println(rect.getHeight());
System.out.println(rect.area());
System.out.println(rect.perimeter());
}
}
第二题的程序文件要存在myShapes的文件夹中。
/* MyPoint.java */
// class MyPoint
public class MyPoint {
public MyPoint(int x,int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
private int x;
private int y;
}
/* Test.java */
// class Test
public class Test{
public static void main(String[] args) {
MyPoint point = new MyPoint(3, 4);
System.out.println(point.getX());
System.out.println(point.getY());
}
}
第二题:
/* MyRect.java */
package myShapes;
// class MyRect
public class myRect {
public MyRect() {};
public MyRect(int h, int w) {
width = w;
height = h;
}
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int area() {
return width * height;
}
public int perimeter() {
return 2 * (width + height);
}
private int width;
private int height;
}
/* Test.java */
package myShapes;
// class Test
public class Test() {
public static void main(String[] args) {
MyRect rect = new MyRect(8, 9);
System.out.println(rect.getWidth());
System.out.println(rect.getHeight());
System.out.println(rect.area());
System.out.println(rect.perimeter());
MyRect rect=new MyRect();
rect.setWidth(7);
rect.setHeight(8);
System.out.println(rect.getWidth());
System.out.println(rect.getHeight());
System.out.println(rect.area());
System.out.println(rect.perimeter());
}
}
第二题的程序文件要存在myShapes的文件夹中。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
java题:设计point类用来定义平面上的一个点,用构造函数传递坐标位置编写测试类在该类中实现point类的对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
编写平面坐标类Point并测试
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询