Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.*;
- public class Tenis {
- public static void main(String[] args) throws IOException {
- ArrayList<String> DaneTenis = new ArrayList<>();
- String zrodlo = "C:\\Users\\wader\\Documents\\ATPrank.txt";
- File file = new File(zrodlo);
- List<String> wiek = separacjaWieku(zrodlo);
- List<String> punkty = separacjaPunktow(zrodlo);
- List<String> tenisista = separacjaTenisistow(zrodlo);
- List<String> turnieje = turnieje(zrodlo);
- WczytajListe(DaneTenis, file);
- int pokaz = pozycja(DaneTenis, "Rafael Nadal");
- int pokaz2 = liczbaN(DaneTenis, "POL");
- double pokaz3 = srednia(wiek, 10);
- int pokaz4 = roznicaPkt(tenisista, punkty, "Novak Djokovic", "Rafael Nadal");
- zagraneTurnieje(turnieje);
- }
- public static List<String> separacjaWieku(String zrodlo) throws IOException {
- ArrayList<String> wiek = new ArrayList<>();
- FileReader fr = new FileReader(zrodlo);
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- String[] element = line.split("\t");
- wiek.add(element[3]);
- }
- return wiek;
- }
- public static List<String> separacjaPunktow(String zrodlo) throws IOException {
- ArrayList<String> wiek = new ArrayList<>();
- FileReader fr = new FileReader(zrodlo);
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- String[] element = line.split("\t");
- wiek.add(element[4]);
- }
- return wiek;
- }
- public static List<String> separacjaTenisistow(String zrodlo) throws IOException {
- ArrayList<String> wiek = new ArrayList<>();
- FileReader fr = new FileReader(zrodlo);
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- String[] element = line.split("\t");
- wiek.add(element[2]);
- }
- return wiek;
- }
- public static List<String> turnieje(String zrodlo) throws IOException {
- ArrayList<String> turnieje = new ArrayList<>();
- FileReader fr = new FileReader(zrodlo);
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- String[] element = line.split("\t");
- turnieje.add(element[5]);
- }
- return turnieje;
- }
- public static void WczytajListe(List<String> lista, File plik) throws FileNotFoundException {
- Scanner scanner = new Scanner(plik);
- while (scanner.hasNext()) {
- String linia = scanner.nextLine();
- lista.add(linia);
- }
- }
- //A
- public static int pozycja(List<String> zawodnik, String imie) {
- int i = 0;
- int pozycja = 0;
- for (i = 0; i < zawodnik.size(); i++) {
- if (zawodnik.get(i).contains(imie)) {
- pozycja = i + 1;
- }
- }
- System.out.println("Pozycja gracza o imieniu " + imie + " to " + pozycja);
- return pozycja;
- }
- //B
- public static int liczbaN(List<String> zawodnik, String narody) {
- int i = 0;
- int licznik = 0;
- for (i = 0; i < zawodnik.size(); i++) {
- if (zawodnik.get(i).contains(narody)) {
- licznik++;
- }
- }
- System.out.println("Z narodu " + narody + " w TOP 50 jest: " + licznik + " gracz(y)");
- return licznik;
- }
- //C
- public static double srednia(List<String> lista, int iloscGraczy) throws IOException {
- double suma = 0;
- double srednia = 0;
- double Roznica = 0; // pomocnicza zmienna licząca sume roznic wieku.(do odchylenia)
- double N = 0.1;
- double od = 0;
- for (int i = 0; i < 10; i++) {
- suma += Integer.parseInt(lista.get(i));
- }
- srednia = suma / iloscGraczy;
- System.out.println("Srednia wieku " + iloscGraczy + " zawodników wynosi: " + srednia);
- for (int j = 0; j < 10; j++) {
- Roznica += Math.pow(Integer.parseInt(lista.get(j)) - (srednia), 2);
- od = Math.sqrt(N * Roznica); // N=10, wiec 1/N=0.1
- }
- System.out.println("Odchylenie standardowe: " + od);
- return srednia;
- }
- //D
- public static int roznicaPkt(List<String> lista, List<String> lista2, String imie1, String imie2) {
- int a = pozycja(lista, imie1) - 1;
- int b = pozycja(lista, imie2) - 1;
- int punktya = Integer.parseInt(lista2.get(a));
- int punktyb = Integer.parseInt(lista2.get(b));
- int c = punktya - punktyb;
- int d = punktyb - punktya;
- System.out.println("Roznica punktów pomiedzy Novakiem Djokoviciem a Rafealem Nadalem, a: " + c);
- if (punktya > punktyb) {
- return c;
- } else {
- return d;
- }
- }
- public static void zagraneTurnieje(List<String> lista) {
- String zapis = "turnieje.txt"; // zapisze plik o podanej nazwie
- try {
- File turnieje = new File(zapis);
- FileWriter tekst1 = new FileWriter(turnieje, false);
- BufferedWriter tekst2 = new BufferedWriter(tekst1);
- for (int i = 0; i < lista.size(); i++) {
- String linia = lista.get(i);
- tekst2.write(linia);
- tekst2.newLine();
- }
- tekst2.close();
- tekst1.close();
- }
- catch (IOException e) {
- System.out.println("Blad");
- }
- }
- }
- *****************************************************************************************************
- package com.company;
- import java.io.*;
- import java.util.Random;
- public class zapisDNA {
- public int dlugosc;
- public String sekwencja;
- zapisDNA(int dlugosc) {
- if (dlugosc > 40 || dlugosc < 0) {
- System.out.println("Nieprawidłowa długość łańcucha");
- return;
- }
- this.dlugosc = dlugosc;
- }
- public String zrobDNA() { //tworzymy losowa nic
- StringBuilder buduj = new StringBuilder();
- Random losuj = new Random();
- int n = 4;
- String kod = null;
- char[] zasadyAzotowe = {'A', 'G', 'C', 'T'};
- for (int i = 0; i < dlugosc; i++) {
- buduj.append(zasadyAzotowe[losuj.nextInt(n)]);
- kod = buduj.toString();
- }
- this.sekwencja = kod;
- return kod;
- }
- public void zapiszDNA() { //zapis sekwencji DNA do pliku txt
- String plik = "utworzoneDNA.txt";
- File dna = new File(plik);
- FileWriter a = null;
- try {
- a = new FileWriter(dna, false);
- BufferedWriter b = new BufferedWriter(a);
- String linia = this.sekwencja;
- a.write(linia);
- a.close();
- b.close();
- } catch (IOException e) {
- e.printStackTrace();
- System.out.println("Błąd");
- }
- }
- }
- ************************************************
- package com.company;
- import java.io.BufferedReader;
- import java.io.FileReader;
- public class odczytDNA {
- public String kod;
- public String kodKomplementarny;
- odczytDNA(String zrodlo) {
- load(zrodlo); //bezposrednie zaladowanie pliku txt
- }
- public void load(String zrodlo) { //wczytywanie kodu ze zrodla
- try {
- FileReader fr = new FileReader(zrodlo);
- BufferedReader br = new BufferedReader(fr);
- String line;
- while ((line = br.readLine()) != null) {
- kod = line;
- }
- } //try
- catch (Exception e) {
- System.out.println("Blad");
- }//catch
- }
- public String generujKomplementarny() { //tworzenie nici komplementarnej i przyporzadkowanie polu klasy
- // "kodKomplementarny"
- StringBuilder buduj = new StringBuilder();
- char polimerazaDNA;
- String kodKomplementarny = null;
- for (int i = 0; i < this.kod.length(); i++) {
- polimerazaDNA = this.kod.charAt(i);
- if (polimerazaDNA == 'C') buduj.append('G');
- else if (polimerazaDNA == 'A') buduj.append('T');
- else if (polimerazaDNA == 'G') buduj.append('C');
- else if (polimerazaDNA == 'T') buduj.append('A');
- kodKomplementarny = buduj.toString();
- this.kodKomplementarny = kodKomplementarny;
- }
- return kodKomplementarny;
- }
- }
- ***********************************************
- package com.company;
- import java.io.IOException;
- public class TestDNA {
- public static void main(String[] Args) throws IOException {
- zapisDNA DNA = new zapisDNA(40);
- DNA.zrobDNA();
- System.out.println("Otrzymana sekwencja : " + DNA.sekwencja);
- DNA.zapiszDNA();
- odczytDNA odczytaj = new odczytDNA("utworzoneDNA.txt");
- odczytaj.generujKomplementarny();
- System.out.println("Utworzon nić komplementarna DNA : " + odczytaj.kodKomplementarny);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement