zoukankan      html  css  js  c++  java
  • 0926-----homework(4,5,6)

      1 /**
      2   *homework0926
      3   *@author:kai li
      4   */
      5 package com.kai.li.homework0926;
      6 import java.util.List;
      7 import java.util.ArrayList;
      8 import java.util.Arrays;
      9 import java.util.Collections;
     10 import java.util.Random;
     11 import java.util.Map;
     12 import java.util.HashMap;
     13 import static java.util.stream.Collectors.toMap;
     14 /**
     15   *following class is client 
     16   */
     17 public class HomeWork0926{
     18     public static void main(String[] args)throws Exception{
     19         
     20         /**
     21           *question four
     22           */
     23     
     24     List<String> strList=new ArrayList<String>();
     25     strList.add("hello");
     26     strList.add("world");
     27     strList.add("learn");
     28     Collections.reverse(strList);
     29     System.out.println(strList);  
     30 
     31     /**
     32         *question five
     33       */   
     34     
     35     /*create data source*/
     36     List<Account> accounts=Arrays.asList(new Account(10.00,"1234"),new Account(15.00,"5678"),new Account(0.00,"1010"));
     37     Map<Long,Account> accountMap=new HashMap<>();
     38     accountMap=accounts.stream().collect(toMap(i->i.getId(),i->i));
     39     System.out.println(accountMap);
     40 
     41     /**
     42       *question six
     43       */
     44     
     45     /*creat data source*/
     46 
     47     List<Worker> workerList=new ArrayList<>();
     48     workerList.add(new Worker("zhang3",18,3000));
     49     workerList.add(new Worker("li4",25,3500));
     50     workerList.add(new Worker("wang5",22,3200));
     51 
     52     /*operate*/
     53     
     54     workerList.add(1,new Worker("zhao6",24,3300));
     55     workerList.remove(3);
     56     
     57     //iterator
     58     workerList.stream().forEach(System.out::println);
     59     workerList.stream().forEach(Worker::work);
     60     }
     61 }
     62 
     63 /**
     64   *class for question five
     65   */
     66 class Account{
     67     private long id;
     68     private double balance;
     69     private String password;
     70     Account(double balance,String password){
     71         Random random=new Random();
     72         this.id=random.nextInt(100000)+100000;
     73         this.balance=balance;
     74         this.password=password;
     75     }
     76     public long getId(){
     77         return id;
     78     }
     79     public double getBalance(){
     80         return balance;
     81     }
     82     public String getPassword(){
     83         return password;
     84     }
     85     @Override
     86     public String toString(){
     87         return "id:"+id+",balance:"+balance+"
    
    ";
     88     }
     89 }
     90 
     91 /**
     92   *class for question six
     93   */
     94 class Worker{
     95     private int age;
     96     private String name;
     97     private double salary;
     98     public Worker(){}
     99     public Worker(String name,int age,double salary){
    100         this.name=name;
    101         this.age=age;
    102         this.salary=salary;
    103     }
    104     public int getAge(){
    105         return age;
    106     }
    107     public String getName(){
    108         return name;
    109     }
    110     public double getSalary(){
    111         return salary;
    112     }
    113     @Override
    114     public String toString(){
    115         return "name:"+name+",age:"+age+",salary:"+salary;
    116     }
    117     public void work(){
    118         System.out.println(name+" work ");
    119     }
    120 }
  • 相关阅读:
    5个经典的javascript面试问题
    去年的一些面试题
    各种奇妙的hack
    jQuery工作原理解析以及源代码示例
    JavaScript Window
    原生JavaScript技巧大收集(1~10)
    蜘蛛爬虫类程序抓取有防盗链的网站处理 php和wget命令简单破解防盗链网站的功能
    Git SSH Key 生成步骤
    linux下ssh使用rsa认证教程
    linux FTP服务器 VSFTP配置手册
  • 原文地址:https://www.cnblogs.com/kaililikai/p/5915963.html
Copyright © 2011-2022 走看看