SHOW:
|
|
- or go back to the newest paste.
| 1 | package com.company; | |
| 2 | import java.util.*; | |
| 3 | public class Solution {
| |
| 4 | ||
| 5 | public static void main(String[] args) {
| |
| 6 | Scanner in = new Scanner(System.in); | |
| 7 | XSSFWorkbook workbook = new XSSFWorkbook(); | |
| 8 | XSSFSheet sheet = workbook.createSheet("Отчет");
| |
| 9 | ||
| 10 | Row header = sheet.createRow(0); | |
| 11 | header.createCell(0).setCellValue("Номер");
| |
| 12 | header.createCell(1).setCellValue("Имя");
| |
| 13 | header.createCell(2).setCellValue("Возраст");
| |
| 14 | header.createCell(3).setCellValue("Тип родственных отношений");
| |
| 15 | header.createCell(4).setCellValue("Заработная плата");
| |
| 16 | header.createCell(5).setCellValue("Максимальная зарплата");
| |
| 17 | header.createCell(6).setCellValue("Минимальная зарплата");
| |
| 18 | header.createCell(7).setCellValue("Средняя зарплата");
| |
| 19 | header.createCell(7).setCellValue("Суммарная зарплата");
| |
| 20 | ArrayList<Integer> money = new ArrayList<Integer>(); | |
| 21 | ||
| 22 | for(int i = 1; i < 5; i++){
| |
| 23 | Row dataRow = sheet.createRow(i); | |
| 24 | System.out.println("Введите номер: ");
| |
| 25 | int num = in.nextInt(); | |
| 26 | dataRow.createCell(0).setCellValue(num); | |
| 27 | System.out.println("Введите имя: ");
| |
| 28 | String name = in.next(); | |
| 29 | dataRow.createCell(1).setCellValue(name); | |
| 30 | System.out.println("Введите возраст: ");
| |
| 31 | int age = in.nextInt(); | |
| 32 | dataRow.createCell(2).setCellValue(age); | |
| 33 | System.out.println("Введите тип родственных отношений: ");
| |
| 34 | String fam = in.next(); | |
| 35 | dataRow.createCell(3).setCellValue(fam); | |
| 36 | System.out.println("Введите зарплату: ");
| |
| 37 | int salary = in.nextInt(); | |
| 38 | money.add(salary); | |
| 39 | dataRow.createCell(4).setCellValue(salary); | |
| 40 | } | |
| 41 | Row row1 = sheet.getRow(1); | |
| 42 | int a = Collections.max(money); | |
| 43 | int b = Collections.min(money); | |
| 44 | ||
| 45 | row1.createCell(5).setCellValue(a); | |
| 46 | row1.createCell(6).setCellValue(b); | |
| 47 | int sum = 0; | |
| 48 | for(int i : money){
| |
| 49 | sum += i; | |
| 50 | } | |
| 51 | ||
| 52 | int total = sum / money.size(); | |
| 53 | row1.createCell(7).setCellValue(total); | |
| 54 | row1.createCell(8).setCellValue(sum); | |
| 55 | ||
| 56 | ||
| 57 | ||
| 58 | ||
| 59 | for(Row row:sheet) | |
| 60 | {
| |
| 61 | System.out.println(); | |
| 62 | for (Cell cell:row) | |
| 63 | {
| |
| 64 | System.out.print(cell+" "); | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | try {
| |
| 69 | FileOutputStream out = new FileOutputStream(new File("Family.xlsx"));
| |
| 70 | workbook.write(out); | |
| 71 | out.close(); | |
| 72 | ||
| 73 | } catch (FileNotFoundException e) {
| |
| 74 | e.printStackTrace(); | |
| 75 | } catch (IOException e) {
| |
| 76 | e.printStackTrace(); | |
| 77 | } | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 |