package com.risk.test; //包

import java.util.ArrayList;
import java.util.HashMap;//引入的类
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class TestString {
	
	
/**	题目一：一个字符串为"hello world"，用循环拆解出一个一个字母输出。
	
//	题目二：创建一个List，在List 中增加个学生，
//	基本信息如下： 姓名 班级 年龄 分数 
//	zhangsan c1 18 65 
//	lisi c2 17 78 
//	wangwu c1 12 89  
//	tom c3 18 33 
//	jerry c3  17 95 
//	jack c1 12 34  
//	steve c3  18 87 
//	kevin c2 17 63 
//	john c3 12 56  
//	1.计算所有学生的平均年龄
//	2.计算各个班级的平均分
//	3.计算学生评分，60以下为不及格，60-80分为中等，80分以上为优秀
	
//	题目三：给定list包含1-100中的95个数字，如何找出5个剩下的？？
	
//
//	题目四：一个文件名称"***.xls"，如果文件名称的长度大于15（不包括文件类型），则将多余的部分用...来代替
//	题目五：字符串"##图片#http://www.bcxin#23412##"，用#切分，去除空字符串
	 
**/
	public static void main(String[] args) {
		TestString ts = new TestString();
//		ts.demo1();
//		ts.demo2();
//		ts.demo3();
		ts.demo4();
	}
	
	///题目一
	public void demo1(){
		String str = "hello world";
		String str2 = new String("hello world");
//		for (Character c : str.toCharArray()) {
//			System.out.println(c);
//		}
		String[] strs = new String[str.length()];
		for (int i = 0; i < str.length(); i++) {
			String substr = str.substring(i,i+1);
			strs[i] = substr;
			//这里print也行
		}
		
		for (String string : strs) {
			System.out.println(string);
		}
	}
	
	
	//题目二
	public void demo2(){
		List<Student> list = new ArrayList<Student>();
		Student a1 = new Student();
		a1.setName("zhangsan");
		a1.setClasses("c1");
		a1.setAge(18);
		a1.setGrade(65);
		
		Student a2 = new Student();
		a2.setName("lisi");
		a2.setClasses("c2");
		a2.setAge(17);
		a2.setGrade(78);
		
		Student a3 = new Student();
		a3.setName("wangwu ddd ".trim());
		a3.setClasses("c1");
		a3.setAge(12);
		a3.setGrade(89);
		
		list.add(a1);
		list.add(a2);
		list.add(a3);
		
		int totalAge = 0;
		
		for (Student student : list) {
			totalAge = totalAge + student.getAge();
		}
		if ( list.size() > 0 ) {
			System.out.println(totalAge/list.size()); //1.计算所有学生的平均年龄
		}
		
		Map<String,List<Student>> map = new HashMap<String,List<Student>>();
		for (Student student : list) {
			Object students = map.get(student.getClasses());
			List<Student> stus = new ArrayList<Student>();
			if ( students != null ) {
				stus = (List<Student>)students;
			}
			stus.add(student);
			map.put(student.getClasses(),stus);
		}
		
		for (Map.Entry<String,List<Student>> entry : map.entrySet()) {  
//            System.out.println("key = " + entry.getKey() + " and value = " + entry.getValue()); 
            //continue  2.计算各个班级的平均分
            int totalGrade = 0;
            List<Student> stus = entry.getValue();
            for (Student student : stus) {
            	totalGrade = totalGrade + student.getGrade();
			}
            System.out.println("班级："+entry.getKey()+"平均分："+totalGrade/stus.size());
        }
		
		
		for (Student student : list) {
			if ( student.getGrade()<60 ) {
				System.out.println(student.getName()+":"+"不及格");
				continue;//跳出本次循环，执行下一个循环
//				break;//跳出循环
			} else if ( student.getGrade() < 80 && student.getGrade() > 60) {
				// || or   && and
				System.out.println(student.getName()+":"+"中等");
			} else if ( student.getGrade()>80 ) {
				System.out.println(student.getName()+":"+"优秀");
			}
		}
		
		//jdk8
		list.forEach(student->{
			
		});
	}
		
	
	public void demo3(){
		Random random = new Random();
		
		List<Integer> list = new ArrayList<Integer>();
		while(list.size()<5){ //循环一个集合，不能在循环内对集合进行加减操作
			int temp = random.nextInt(10);
			if ( !list.contains(temp) ) {
				list.add(temp);
			}
		}
		for (int i : list) {
			System.out.println(i);
		}
		//continue
		//thinking in java 这本书也很好
	}
	
	private void demo4(){
		System.out.println("liu xiang ".trim());
	}
}
