第十二次作業
Posted 高杨翔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十二次作業相关的知识,希望对你有一定的参考价值。
public class Point {
int x;
int y;
public Point(int x0, int y0) {
super();
this.x = x0;
this.y = y0;
}
public Point() {
super();
}
public void movePoint(int dx, int dy) {
this.x += dx;
this.y += dy;
}
public static void main(String[] args) {
Point p1 = new Point(3, 7);
p1.movePoint(5, 8);
System.out.println("p1的X坐标为:" + p1.x + "p1的Y坐标为:"+p1.y);
Point p2 = new Point(4, 9);
p2.movePoint(3, 8);
System.out.println("p2的X坐标为:" + p2.x + "p2的Y坐标为:"+p2.y);
}
}
public class Rectangle {
int length;
int width;
public Rectangle(int length, int width) {
this.length = length;
this.width = width;
}
public int getArea() {
return length * width;
}
public int getPer() {
return (length + width) * 2;
}
public void showAll() {
System.out.println("长为:" + length);
System.out.println("宽为:" + width);
System.out.println("面积为:" + getArea());
System.out.println("周长为:" + getPer());
}
public static void main(String[] args) {
Rectangle s1 = new Rectangle(9, 2);
s1.showAll();
}
}
public class bjb {
char color;
int cpu;
public bjb() {
super();
}
public bjb(char color, int cpu) {
super();
this.color = color;
this.cpu = cpu;
}
public void show() {
System.out.println("笔记本颜色是:" + color + ",cpu型号是:" + cpu);
}
}
public class TExtbjb {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
bjb b1 = new bjb(\'黑\', 9);
bjb b2 = new bjb(\'白\', 10);
b1.show();
b2.show();
}
}
以上是关于第十二次作業的主要内容,如果未能解决你的问题,请参考以下文章