第九周上机
package hhhhkj;
import java.util.Scanner;
public class kjklkjkj {
public static void main(String[] args) {
Point p1=new Point();
p1.movepoint(1, 2);
Point p2=new Point();
p2.movepoint(3, 4);
}
}
package hhhhkj;
public class Point {
int x,y;
public void movepoint(int dx,int dy){
x+=dx+15;
y+=dy+20;
System.out.println("横坐标为"+x+"纵坐标为"+y);
}
}

第二题
package hhhhkj;
import java.util.Scanner;
public class kjklkjkj {
public static void main(String[] args) {
Rectangle r=new Rectangle();
r.showAll();
}
}
package hhhhkj;
public class Rectangle {
double length=3;
double width=4;
public Rectangle(){
System.out.println("构造方法");
}
public void getArea() {
double area=length*width;
System.out.println("面积为"+area);
}
public void getPer() {
double per= 2*(length+width);
System.out.println("周长为"+per);
}
public void showAll() {
System.out.println("长为"+length);
System.out.println("宽为"+width);
System.out.println("面积为"+length*width);
System.out.println("周长为"+(length+width));
}
}

第三题
package hhhhkj;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
test1 r=new test1();
r.cpumodel=2;
r.colourname='红';
r.colour();
r.cpu();
}
}
package hhhhkj;
public class test1 {
char colourname;
int cpumodel;
public void colour(){
System.out.println("颜色是"+colourname);
}
public void cpu(){
System.out.println("型号是"+cpumodel);
}
public test1(){
System.out.println("无参构造");
}
}

第四题
package hhhhkj;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
test1 r1=new test1();
test1 r2=new test1();
r1.height=1.73;
r1.name="zhangsan";
r1.weight=56.3;
r2.name="lishi";
r2.height=1.74;
r2.weight=78.4;
r1.sayhellow();
r1.hhhhh();
r2.sayhellow();
r2.hhhhh();
}
}
package hhhhkj;
public class test1 {
String name;
double height;
double weight;
public void sayhellow(){
System.out.println("hellow,my name is"+name);
}
public void hhhhh(){
System.out.println("名字是"+name);
System.out.println("升高是"+height);
System.out.println("体重是"+weight);
}
public test1(){
System.out.println("****88888");
}
}


浙公网安备 33010602011771号