1个回答
2018-06-21 · 国内最优秀java资源共享平台
关注
展开全部
public class Student {
private String code;
private String name;
private int height;
private char sex;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String code, String name, int height, char sex) {
super();
this.code = code;
this.name = name;
this.height = height;
this.sex = sex;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String show(){
return "Student [code=" + code + ", name=" + name + ", height=" + height + ", sex=" + sex + "]";
}
public int show(Student s){
return s.getHeight();
}
public void show(Student s,int sv){
if(s.getHeight()>=sv){
if(s.getSex()=='f'){
System.out.println(s.show());
}
}
}
}
public class Test {
public static void main(String[] args) {
Student student1 = new Student("A001", "zs1", 171, 'm');
Student student2 = new Student("A002", "zs2", 172, 'f');
Student student3 = new Student("A003", "zs3", 173, 'm');
Student student4 = new Student("A004", "zs4", 174, 'f');
Student student5 = new Student("A005", "zs5", 175, 'f');
System.out.println(student1.show());
System.out.println(student2.show());
System.out.println(student3.show());
System.out.println(student4.show());
System.out.println(student5.show());
//平均身高
int sv=(student1.show(student1)+student2.show(student2)+student3.show(student3)+
student4.show(student4)+student5.show(student5))/5;
System.out.println("超过平均年龄的女生详情:");
//超过平均年龄的女生
student1.show(student1, sv);
student2.show(student2, sv);
student3.show(student3, sv);
student4.show(student4, sv);
student5.show(student5, sv);
}
}
private String code;
private String name;
private int height;
private char sex;
public Student() {
super();
// TODO Auto-generated constructor stub
}
public Student(String code, String name, int height, char sex) {
super();
this.code = code;
this.name = name;
this.height = height;
this.sex = sex;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String show(){
return "Student [code=" + code + ", name=" + name + ", height=" + height + ", sex=" + sex + "]";
}
public int show(Student s){
return s.getHeight();
}
public void show(Student s,int sv){
if(s.getHeight()>=sv){
if(s.getSex()=='f'){
System.out.println(s.show());
}
}
}
}
public class Test {
public static void main(String[] args) {
Student student1 = new Student("A001", "zs1", 171, 'm');
Student student2 = new Student("A002", "zs2", 172, 'f');
Student student3 = new Student("A003", "zs3", 173, 'm');
Student student4 = new Student("A004", "zs4", 174, 'f');
Student student5 = new Student("A005", "zs5", 175, 'f');
System.out.println(student1.show());
System.out.println(student2.show());
System.out.println(student3.show());
System.out.println(student4.show());
System.out.println(student5.show());
//平均身高
int sv=(student1.show(student1)+student2.show(student2)+student3.show(student3)+
student4.show(student4)+student5.show(student5))/5;
System.out.println("超过平均年龄的女生详情:");
//超过平均年龄的女生
student1.show(student1, sv);
student2.show(student2, sv);
student3.show(student3, sv);
student4.show(student4, sv);
student5.show(student5, sv);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询