用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

漫步云端    -  云代码空间

——

学生信息统计

2013-02-13|2027阅||

摘要:package count; public class College { private String name; private int maleCount; private int femaleCount; public College(String name){ this

package count;


public class College {

private String name;

private int maleCount;

private int femaleCount;

public College(String name){
this.name=name;
}


public String getName() {
return name;
}


public int getMaleCount() {
return maleCount;
}


public int getFemaleCount() {
return femaleCount;
}

public void maleadd(){
this.maleCount++;
}

public void femaleadd(){
this.femaleCount++;
}

public double bili(){
double bili=0;
if(femaleCount==0){
bili=Double.MAX_VALUE;
}else{
bili=(double)maleCount/(double)femaleCount;
}
return bili;
}


}





package count;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class Count {


public static void main(String[] args) {


String filepath = System.getProperty("user.dir") + File.separator
+ "file" + File.separator + "student.txt";


Message messages[] = new Message[20000];
int index = 0;
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader(
new File(filepath)));
String s = "";
while ((s = bufferedReader.readLine()) != null) {
String[] infos = s.split(",");
Message message = new Message();
message.setClassID(infos[0]);
message.setId(infos[1]);
message.setName(infos[2]);
message.setSex(infos[3]);
message.setSubject(infos[4]);
message.setCollege(infos[5]);
messages[index] = message;
index++;
}
/*******************************************/
College[] colleges=new College[30];
int collegeindex=0;
for(int i=0;i<index;i++){
Message message=messages[i];
String collegesName=message.getCollege();
boolean flag=false;
for(int j=0;j<collegeindex;j++){
if(colleges[j].getName().equals(collegesName)){
if(message.getSex().equals("男")){
colleges[j].maleadd();
}else{
colleges[j].femaleadd();
}
flag=true;
break;
}
}
if(!flag){
College college=new College(collegesName);
colleges[collegeindex]=college;
collegeindex++;
if(message.getSex().equals("男")){
college.maleadd();
}else{
college.femaleadd();
}
}
}

for(int i=0;i<collegeindex;i++){

System.out.println("name "+colleges[i].getName()
+" 男生:"+ colleges[i].getMaleCount()
+" 女生:"+ colleges[i].getFemaleCount()
+" 比值:"+ colleges[i].bili());
}
// int maleCount = 0;
// for(int i=0;i<index;i++){
// System.out.println(messages[i]);//syso+alt+? 快捷打
// if(messages[i].getSex().equals("男")){
// maleCount++;
// }
// }
// int femaleCount = index+1 - maleCount;//数组下标加1为总人数
// System.out.println("total:" + index +1 +"男生:"+maleCount+"女生:"+femaleCount+"男女比例:"+((double)maleCount/(double)femaleCount));
//

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
}






package count;


public class Message {

private String classID;//班级

private String id;//学号

private String name;//姓名

private String sex;//性别

private String subject;//专业

private String college;//学院

public String getClassID() {
return classID;
}


public void setClassID(String classID) {
this.classID = classID;
}


public String getId() {
return id;
}


public void setId(String id) {
this.id = id;
}


public String getName() {
return name;
}


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


public String getSex() {
return sex;
}


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


public String getSubject() {
return subject;
}


public void setSubject(String subject) {
this.subject = subject;
}


public String getCollege() {
return college;
}


public void setCollege(String college) {
this.college = college;
}


@Override
public String toString() {
return "Message [classID=" + classID + ", id=" + id + ", name=" + name个人中心
+ ", sex=" + sex + ", subject=" + subject + ", college="
+ college + "]";
}




}
/*
链接的本地txt信息自备
*/
顶 10踩 10收藏
文章评论
  • 初级程序员

    漫步云端删除|举报|踩(1)|顶(1)|回复(3)|2013-02-13 22:14:10
    发现好像版式不对。。。不好看、、、
    • 小蜜锋: 2013-02-14 12:57:17|举报

      用编辑器左上角的插入代码功能就好看多了。

    • 小蜜锋: 2013-02-14 12:58:02|举报

      其实这属于代码片段啊,应该放到代码库里 http://yuncode.net/code/add

    • 漫步云端: 2013-11-09 23:40:10|举报

      後來我發現了

共1 条评论 1/1页
发表评论

个人资料

  • 昵称: 漫步云端
  • 等级: 初级程序员
  • 积分: 0
  • 代码: 0 个
  • 文章: 1 篇
  • 随想: 8 条
  • 访问: 7 次
  • 关注

人气文章

人气代码

    标签

    站长推荐