Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Scanner;
- public class Main {
- static ArrayList<Debt> debtList;
- public static void main(String[] args) {
- debtList = new ArrayList<>();
- Scanner scanner = new Scanner(System.in);
- loading();
- while(true) { // opcje
- System.out.println("opcje");
- System.out.println("wyswietl");
- int choice=1;
- choice=scanner.nextInt();
- if (choice== 0) {
- scanner.close();
- return;
- } else {
- sort();
- }
- }
- }
- public static void display() { //funkcja wyswietlania
- for( int i = 0; i < debtList.size(); i++) {
- System.out.println(debtList.get(i).getCountry()+debtList.get(i).getPer_capita());
- }
- }
- public static void sort() { //sortowanie
- Collections.sort(debtList, new Comparator<Debt>()
- {
- @Override
- public int compare(Debt d1, Debt d2)
- {
- if (d1.getPopulation() > d2.getPopulation()) {
- return 1;
- } if (d2.getPopulation() < d1.getPopulation()) {
- return -1;
- } else {
- return 0;
- }
- //porownanie
- }
- });
- }
- public static void loading() { //funkcja pobierania
- try{
- File file = new File("debt.txt"); //pobieranie - rżnąć
- FileReader fileReader = new FileReader(file);
- BufferedReader bufferedReader = new BufferedReader(fileReader);
- String textLine;
- //Debt_List debt_list = new Debt_list("Debt1");
- while ((textLine = bufferedReader.readLine()) !=null) { //tak samo
- String [] dataTable = textLine.split(";"); //tak samo
- String country = dataTable [0]; //tyle stringow ile zmiennych
- String amountString = dataTable [1];
- String populationString = dataTable[2];
- int amount = Integer.parseInt(amountString); //zamiana na liczbe
- int population = Integer.parseInt(populationString);
- Debt debt = new Debt(country, amount, population); //tworzenie obiektu
- debtList.add(debt);
- }
- bufferedReader.close();
- } catch (Exception e) {
- System.out.println("Exception enocuntered while importing data from the source file ("+e+")"); // co jak jebnie
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement