java:急求两java简单编程题
我刚刚开始学,还不懂什么,可是老师要交作业!!1.构造一个类来描述点,该类的构成包括x和y两个坐标,以及一些对点进行的操作,包括:取得点的坐标值,对点的坐标赋值,改变坐标...
我刚刚开始学,还不懂什么,可是老师要交作业!!
1. 构造一个类来描述点,该类的构成包括x和y两个坐标,以及一些对点进行的操作,包括:取得点的坐标值,对点的坐标赋值,改变坐标值等操作,编写应用程序生成该类的对象并对其进行操作。
2. 编写一个程序,包含以下内容:
(1)创建一个学生类 student ,其中包括属性(学号s_No,姓名s_Name,性别s_Sex,年龄s_Age)和方法(构造方法,获得学号,姓名,性别,年龄的方法;修改学号,姓名,性别,年龄的方法)。
(2)主类包含主方法main,在其中创建一个学生对象s,并初始化,然后分别显示该学生的学号,姓名,性别,年龄,再修改年龄并显示修改结果。 展开
1. 构造一个类来描述点,该类的构成包括x和y两个坐标,以及一些对点进行的操作,包括:取得点的坐标值,对点的坐标赋值,改变坐标值等操作,编写应用程序生成该类的对象并对其进行操作。
2. 编写一个程序,包含以下内容:
(1)创建一个学生类 student ,其中包括属性(学号s_No,姓名s_Name,性别s_Sex,年龄s_Age)和方法(构造方法,获得学号,姓名,性别,年龄的方法;修改学号,姓名,性别,年龄的方法)。
(2)主类包含主方法main,在其中创建一个学生对象s,并初始化,然后分别显示该学生的学号,姓名,性别,年龄,再修改年龄并显示修改结果。 展开
5个回答
展开全部
class Point
{
public double x;
public double y;
public getPointLoactin()//取得坐标植并输出
{
System.out.println("The Point's Location is("+x+","+y+")");
}
public setPointLocation(double x,double y)//对点的坐标赋值
{
this.x=x;
this.y=y;
}
public changePointLocation()//改变坐标值
{
x=2.30;
y=5.40;
}
}
public class DoPoint
{
public static void main(String args[])
{
Point p = new Point();
p.setPointLocation(8.30,9.20);
p.getPointLocation();
p.changePointLocation();
p.getPointLocation();
}
}
直接写了一个 应该没有什么问题,大致就是这样的吧,自己看看
{
public double x;
public double y;
public getPointLoactin()//取得坐标植并输出
{
System.out.println("The Point's Location is("+x+","+y+")");
}
public setPointLocation(double x,double y)//对点的坐标赋值
{
this.x=x;
this.y=y;
}
public changePointLocation()//改变坐标值
{
x=2.30;
y=5.40;
}
}
public class DoPoint
{
public static void main(String args[])
{
Point p = new Point();
p.setPointLocation(8.30,9.20);
p.getPointLocation();
p.changePointLocation();
p.getPointLocation();
}
}
直接写了一个 应该没有什么问题,大致就是这样的吧,自己看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
老师让你交作业,你自己都不试一下,就直接来拿代码,建议你自己试着写一个,出错了可以贴出来,大家帮你改,这样你才有自己的收获!这样不劳而获……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Point
{
private:
double x;
double y;
public:
Point(){x=0;y=0}
Point( double _x, double _y ){ x = _x; y = _y; }
double getX(){return x;}
double getY(){return y;}
void setX(double _x ){x=_x;}
void setY(double _y ){y=_y;}
}
{
private:
double x;
double y;
public:
Point(){x=0;y=0}
Point( double _x, double _y ){ x = _x; y = _y; }
double getX(){return x;}
double getY(){return y;}
void setX(double _x ){x=_x;}
void setY(double _y ){y=_y;}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先占一个位
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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());
}
}
_____________________________________________________
2.
package test;
public class Student {
private int s_No;
private String s_Name;
private int s_Age;
private boolean s_Sex;
Student(int no, String name, int age, boolean sex) {
this.s_No = no;
this.s_Name = name;
this.s_Age = age;
this.s_Sex = sex;
}
public int getS_No() {
return s_No;
}
public void setS_No(int no) {
s_No = no;
}
public String getS_Name() {
return s_Name;
}
public void setS_Name(String name) {
s_Name = name;
}
public int getS_Age() {
return s_Age;
}
public void setS_Age(int age) {
s_Age = age;
}
public boolean getS_Sex() {
return s_Sex;// true:male, false:female
}
public void setS_Sex(boolean sex) {
s_Sex = sex;
}
public static void print(String suggest, int value) {
System.out.println(suggest + value);
}
public static void print(String suggest, String value) {
System.out.println(suggest + value);
}
public static void main(String[] args) {
Student student = new Student(1, "小明", 17, true);
System.out.println("s_No is :" + student.getS_No());
System.out.println("s_Name is :" + student.getS_Name());
System.out.println("s_Age is :" + student.getS_Age());
if(student.getS_Sex())
System.out.println("s_Sex is : male");
else
System.out.println("s_Sex is : female");
}
}
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());
}
}
_____________________________________________________
2.
package test;
public class Student {
private int s_No;
private String s_Name;
private int s_Age;
private boolean s_Sex;
Student(int no, String name, int age, boolean sex) {
this.s_No = no;
this.s_Name = name;
this.s_Age = age;
this.s_Sex = sex;
}
public int getS_No() {
return s_No;
}
public void setS_No(int no) {
s_No = no;
}
public String getS_Name() {
return s_Name;
}
public void setS_Name(String name) {
s_Name = name;
}
public int getS_Age() {
return s_Age;
}
public void setS_Age(int age) {
s_Age = age;
}
public boolean getS_Sex() {
return s_Sex;// true:male, false:female
}
public void setS_Sex(boolean sex) {
s_Sex = sex;
}
public static void print(String suggest, int value) {
System.out.println(suggest + value);
}
public static void print(String suggest, String value) {
System.out.println(suggest + value);
}
public static void main(String[] args) {
Student student = new Student(1, "小明", 17, true);
System.out.println("s_No is :" + student.getS_No());
System.out.println("s_Name is :" + student.getS_Name());
System.out.println("s_Age is :" + student.getS_Age());
if(student.getS_Sex())
System.out.println("s_Sex is : male");
else
System.out.println("s_Sex is : female");
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询