java:急求两java简单编程题
发布网友
发布时间:2023-11-10 04:27
我来回答
共5个回答
热心网友
时间:2024-12-04 07:34
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();
}
}
直接写了一个 应该没有什么问题,大致就是这样的吧,自己看看
热心网友
时间:2024-12-04 07:34
老师让你交作业,你自己都不试一下,就直接来拿代码,建议你自己试着写一个,出错了可以贴出来,大家帮你改,这样你才有自己的收获!这样不劳而获……
热心网友
时间:2024-12-04 07:35
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;}
}
热心网友
时间:2024-12-04 07:36
先占一个位
热心网友
时间:2024-12-04 07:36
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");
}
}