0926-----homework(4,5,6)

Posted 风林山火

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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+"\\n\\r";
 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 }

 

以上是关于0926-----homework(4,5,6)的主要内容,如果未能解决你的问题,请参考以下文章

0926-----homework

掘金Al智能机器人全自动收益系统开发

Python读取cvs文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 6(代

H5新增元素跟文档结构新的文档结构 1. article 文章块 2. section 区块 3. nav 导航条 4. aside 辅助栏 5. main 主要区域 6. header 标(代

2021-08-27:正常的里程表会依次显示自然数表示里程,吉祥的里程表会忽略含有4的数字而跳到下一个完全不含有4的数。正常:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15(代

IPEX-1代/3代/4代/5代,PCB天线底座,公头,样式及封装尺寸图