Students find objects based on students English

Student category

 

com.twod1z Package Penalty for;
/ **
* @program: com.twod1z
* @description: Students find objects (student category) according to participants English
* @author: Mr.Lin
* @Create: 2019 Nian 7 Yue 27 Ri
** /
class Student {public
Private String name;
Private Sex char;

public Student () {}

public Student(String name, char sex) {
this.name = name;
this.sex = sex;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public char getSex() {
return sex;
}

public void setSex(char sex) {
this.sex = sex;
}


}

   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Test category

package com.twod1z;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* @program: com.twod1z
* @description:根据学员英文名找到学员对象(测试类)
* @author: Mr.Lin
* @create: 2019年7月27日
**/
public class Text {
public static void main(String[] args) {
Student s1 = new Student("张明",'男');
Student s2 = new Student("李欣",'女');
Student s3 = new Student("王武",'男');

Map<String,Student>m = new HashMap<String,Student>();

m.put("Jack", s1);
m.put("Mary", s2);
m.put("Michael", s3);

Set<String>s = m.keySet();

for (String str : s) {
Student stu = m.get(str);
System.out.println(str+"对应的学员姓名是:"+stu.getName()+";性别是:"+stu.getSex());
}
}

}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

   

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/lpbk/p/11257064.html