编写一个学生类,提供name,age,gender,phone,address,email成员变量
答案:1 悬赏:0 手机版
解决时间 2021-02-16 09:00
- 提问者网友:我是女神我骄傲
- 2021-02-15 13:22
编写一个学生类,提供name,age,gender,phone,address,email成员变量
最佳答案
- 五星知识达人网友:青尢
- 2021-02-15 14:31
public class Student{
private static Stu[] stus = new Stu[10];
public static void main(String[] args){
initStu();
Stu s = find("stu3","address3","email3");
if(s != null){
System.out.println(s.getName()+","+s.getGender());
}else
System.out.println("不存在该学员!");
}
//初始化
public static void initStu(){
for(short i = 0 ; i < stus.length; i++){
String gender = (i%2) == 0 ? "男" : "女";
Stu stu = new Stu("stu"+i,i,gender,"110","address"+i,"email"+i);
stus[i] = stu;
}
}
//模拟查找
public static Stu find(String name,String address,String email){
for(Stu s : stus){
if(s.getName().equals(name) && s.getAddress().equals(address) && s.getEmail().equals(email)){
return s;
}
}
return null;
}
}
class Stu{
private String name;
private short age;
private String gender;
private String phone;
private String address;
private String email;
public Stu(){}
public Stu(String name,short age,String gender,String phone,String address,String email){
this.name = name;
this.age = age;
this.gender = gender;
this.phone = phone;
this.address = address;
this.email = email;
}
public String getName(){
return name;
}
public String getGender(){
return gender;
}
public String getAddress(){
return address;
}
public String getEmail(){
return email;
}
}
太乱了,还是给个附件吧。
private static Stu[] stus = new Stu[10];
public static void main(String[] args){
initStu();
Stu s = find("stu3","address3","email3");
if(s != null){
System.out.println(s.getName()+","+s.getGender());
}else
System.out.println("不存在该学员!");
}
//初始化
public static void initStu(){
for(short i = 0 ; i < stus.length; i++){
String gender = (i%2) == 0 ? "男" : "女";
Stu stu = new Stu("stu"+i,i,gender,"110","address"+i,"email"+i);
stus[i] = stu;
}
}
//模拟查找
public static Stu find(String name,String address,String email){
for(Stu s : stus){
if(s.getName().equals(name) && s.getAddress().equals(address) && s.getEmail().equals(email)){
return s;
}
}
return null;
}
}
class Stu{
private String name;
private short age;
private String gender;
private String phone;
private String address;
private String email;
public Stu(){}
public Stu(String name,short age,String gender,String phone,String address,String email){
this.name = name;
this.age = age;
this.gender = gender;
this.phone = phone;
this.address = address;
this.email = email;
}
public String getName(){
return name;
}
public String getGender(){
return gender;
}
public String getAddress(){
return address;
}
public String getEmail(){
return email;
}
}
太乱了,还是给个附件吧。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯