java:急求两java简单编程题

来源:百度知道 编辑:UC知道 时间:2024/06/15 12:03:12
我刚刚开始学,还不懂什么,可是老师要交作业!!

1. 构造一个类来描述点,该类的构成包括x和y两个坐标,以及一些对点进行的操作,包括:取得点的坐标值,对点的坐标赋值,改变坐标值等操作,编写应用程序生成该类的对象并对其进行操作。

2. 编写一个程序,包含以下内容:
(1)创建一个学生类 student ,其中包括属性(学号s_No,姓名s_Name,性别s_Sex,年龄s_Age)和方法(构造方法,获得学号,姓名,性别,年龄的方法;修改学号,姓名,性别,年龄的方法)。
(2)主类包含主方法main,在其中创建一个学生对象s,并初始化,然后分别显示该学生的学号,姓名,性别,年龄,再修改年龄并显示修改结果。

1.

public class Point {

private int x;
private int y;

Point(int x,int y)
{
this.x = x;
this.y = y;
}

public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}

public static void print(String suggest, int value)
{
System.out.println(suggest + value);
}

public static void main(String[] args) {
Point p = new Point(0,0);
System.out.println("init x=0,y=0");
print("x is: ", p.getX());
print("y is: ", p.getY());
System.out.println("change x=2,y=3");
p.setX(2);
p.setY(3);
print("x is: ", p.getX());
print("y is: ", p.getY());
}

}
________________________________