第12周作业
1.
package School.Day11;
public class Point {
int x;
int y;
public Point(){
}
public Point(int x,int y){
this.x = x;
this.y = y;
}
public void movePoint(int x,int y){
this.x = x;
this.y = y;
}
}
package School.Day11;
public class PointTest {
public static void main(String[] args){
Point p1 = new Point(5,5);
Point p2 = new Point(10,10);
p1.movePoint(10,10);
p2.movePoint(5,5);
System.out.println("p1的坐标是: (" + p1.x + "," + p1.y + ")");
System.out.println("p2的坐标是: (" + p2.x + "," + p2.y + ")");
}
}

2.
package School.Day11;
public class Rectangle {
int length;
int width;
public Rectangle(){
}
public Rectangle(int length,int width){
this.length = length;
this.width = width;
}
public void showAll(){
System.out.println("长是: " + this.length);
System.out.println("宽是: " + this.width);
System.out.println("面积是: " + this.length * this.width);
System.out.println("周长是: " + (this.length + this.width) * 2);
}
}
package School.Day11;
public class RectangleTest {
public static void main(String[] args) {
Rectangle r = new Rectangle(10,5);
r.showAll();
}
}

3.
package School.Day11;
public class Computer {
char color;
int cpu;
public Computer() {
}
public Computer(char color, int cpu) {
this.color = color;
this.cpu = cpu;
}
public void showAll(){
System.out.println("颜色: " + this.color);
System.out.println("型号: " + this.cpu);
}
}
package School.Day11;
public class ComputerTest {
public static void main(String[] args) {
Computer c = new Computer('黑',9700);
c.showAll();
}
}

浙公网安备 33010602011771号