JAVA代码编写!求帮忙!求教
答案:2 悬赏:0 手机版
解决时间 2021-01-25 08:30
- 提问者网友:雪舞兮
- 2021-01-24 10:49
JAVA代码编写!求帮忙!求教
最佳答案
- 五星知识达人网友:轮獄道
- 2021-01-24 12:12
第一题:
Car.java
public class Car {
public String num;
public float price;
public Car(String num,float price){
this.num = num;
this.price=price;
System.out.println("车牌号为:"+num+",价格为:"+price);
}
} 测试类:
public class CarTest {
public static void main(String[] args) {
Car car = new Car("京P34E68", 100000.23f);
}
} 输出为:车牌号为:京P34E68,价格为:100000.23
第二题:
Student.java
public class Student {
private String num;
private String name;
private int age;
private String sex;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String tell() {
return "Student [num=" + num + ", name=" + name + ", age=" + age+ ", sex=" + sex + "]";
}
public static void main(String[] args) {
Student student = new Student();
student.setAge(18);
student.setNum("001");
student.setName("COLD");
student.setSex("男");
System.out.println(student.tell());
}
}
输出:Student [num=001, name=COLD, age=18, sex=男]
希望能帮到你,望采纳
Car.java
public class Car {
public String num;
public float price;
public Car(String num,float price){
this.num = num;
this.price=price;
System.out.println("车牌号为:"+num+",价格为:"+price);
}
} 测试类:
public class CarTest {
public static void main(String[] args) {
Car car = new Car("京P34E68", 100000.23f);
}
} 输出为:车牌号为:京P34E68,价格为:100000.23
第二题:
Student.java
public class Student {
private String num;
private String name;
private int age;
private String sex;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String tell() {
return "Student [num=" + num + ", name=" + name + ", age=" + age+ ", sex=" + sex + "]";
}
public static void main(String[] args) {
Student student = new Student();
student.setAge(18);
student.setNum("001");
student.setName("COLD");
student.setSex("男");
System.out.println(student.tell());
}
}
输出:Student [num=001, name=COLD, age=18, sex=男]
希望能帮到你,望采纳
全部回答
- 1楼网友:轮獄道
- 2021-01-24 12:18
可以写 see my name, find me
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯