ptrvlck icon

priklad

ptrvlck | PRO | 04/29/21 04:41:39 PM UTC | 0 ⭐ | 738 👁️ | Never ⏰ | []
Java |

2.93 KB

|

None

|

0 👍

/

0 👎

package com.company;
import java.util.*;
public class Solution {
 
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Отчет");
 
        Row header = sheet.createRow(0);
        header.createCell(0).setCellValue("Номер");
        header.createCell(1).setCellValue("Имя");
        header.createCell(2).setCellValue("Возраст");
        header.createCell(3).setCellValue("Тип родственных отношений");
        header.createCell(4).setCellValue("Заработная плата");
        header.createCell(5).setCellValue("Максимальная зарплата");
        header.createCell(6).setCellValue("Минимальная зарплата");
        header.createCell(7).setCellValue("Средняя зарплата");
        header.createCell(7).setCellValue("Суммарная зарплата");
        ArrayList<Integer> money = new ArrayList<Integer>();
 
        for(int i = 1; i < 5; i++){
            Row dataRow = sheet.createRow(i);
            System.out.println("Введите номер: ");
            int num = in.nextInt();
            dataRow.createCell(0).setCellValue(num);
            System.out.println("Введите имя: ");
            String name = in.next();
            dataRow.createCell(1).setCellValue(name);
            System.out.println("Введите возраст: ");
            int age = in.nextInt();
            dataRow.createCell(2).setCellValue(age);
            System.out.println("Введите тип родственных отношений: ");
            String fam = in.next();
            dataRow.createCell(3).setCellValue(fam);
            System.out.println("Введите зарплату: ");
            int salary = in.nextInt();
            money.add(salary);
            dataRow.createCell(4).setCellValue(salary);
        }
        Row row1 = sheet.getRow(1);
        int a = Collections.max(money);
        int b = Collections.min(money);
 
        row1.createCell(5).setCellValue(a);
        row1.createCell(6).setCellValue(b);
        int sum = 0;
        for(int i : money){
            sum += i;
        }
 
        int total = sum / money.size();
        row1.createCell(7).setCellValue(total);
        row1.createCell(8).setCellValue(sum);
 
 
 
 
        for(Row row:sheet)
        {
            System.out.println();
            for (Cell cell:row)
            {
                System.out.print(cell+" ");
            }
        }
 
        try {
            FileOutputStream out =  new FileOutputStream(new File("Family.xlsx"));
            workbook.write(out);
            out.close();
 
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
 

Comments