Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.25 KB | None | 0 0
  1. package com.company;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class Tenis {
  6. public static void main(String[] args) throws IOException {
  7. ArrayList<String> DaneTenis = new ArrayList<>();
  8. String zrodlo = "C:\\Users\\wader\\Documents\\ATPrank.txt";
  9. File file = new File(zrodlo);
  10. List<String> wiek = separacjaWieku(zrodlo);
  11. List<String> punkty = separacjaPunktow(zrodlo);
  12. List<String> tenisista = separacjaTenisistow(zrodlo);
  13. List<String> turnieje = turnieje(zrodlo);
  14.  
  15.  
  16. WczytajListe(DaneTenis, file);
  17. int pokaz = pozycja(DaneTenis, "Rafael Nadal");
  18. int pokaz2 = liczbaN(DaneTenis, "POL");
  19. double pokaz3 = srednia(wiek, 10);
  20. int pokaz4 = roznicaPkt(tenisista, punkty, "Novak Djokovic", "Rafael Nadal");
  21. zagraneTurnieje(turnieje);
  22.  
  23. }
  24.  
  25. public static List<String> separacjaWieku(String zrodlo) throws IOException {
  26. ArrayList<String> wiek = new ArrayList<>();
  27.  
  28. FileReader fr = new FileReader(zrodlo);
  29. BufferedReader br = new BufferedReader(fr);
  30. String line;
  31. while ((line = br.readLine()) != null) {
  32. String[] element = line.split("\t");
  33. wiek.add(element[3]);
  34. }
  35. return wiek;
  36. }
  37.  
  38. public static List<String> separacjaPunktow(String zrodlo) throws IOException {
  39. ArrayList<String> wiek = new ArrayList<>();
  40.  
  41. FileReader fr = new FileReader(zrodlo);
  42. BufferedReader br = new BufferedReader(fr);
  43. String line;
  44. while ((line = br.readLine()) != null) {
  45. String[] element = line.split("\t");
  46. wiek.add(element[4]);
  47. }
  48. return wiek;
  49. }
  50.  
  51. public static List<String> separacjaTenisistow(String zrodlo) throws IOException {
  52. ArrayList<String> wiek = new ArrayList<>();
  53.  
  54. FileReader fr = new FileReader(zrodlo);
  55. BufferedReader br = new BufferedReader(fr);
  56. String line;
  57. while ((line = br.readLine()) != null) {
  58. String[] element = line.split("\t");
  59. wiek.add(element[2]);
  60. }
  61. return wiek;
  62. }
  63.  
  64. public static List<String> turnieje(String zrodlo) throws IOException {
  65. ArrayList<String> turnieje = new ArrayList<>();
  66.  
  67. FileReader fr = new FileReader(zrodlo);
  68. BufferedReader br = new BufferedReader(fr);
  69. String line;
  70. while ((line = br.readLine()) != null) {
  71. String[] element = line.split("\t");
  72. turnieje.add(element[5]);
  73. }
  74. return turnieje;
  75. }
  76.  
  77.  
  78. public static void WczytajListe(List<String> lista, File plik) throws FileNotFoundException {
  79. Scanner scanner = new Scanner(plik);
  80. while (scanner.hasNext()) {
  81. String linia = scanner.nextLine();
  82. lista.add(linia);
  83. }
  84.  
  85. }
  86.  
  87. //A
  88. public static int pozycja(List<String> zawodnik, String imie) {
  89. int i = 0;
  90. int pozycja = 0;
  91. for (i = 0; i < zawodnik.size(); i++) {
  92. if (zawodnik.get(i).contains(imie)) {
  93. pozycja = i + 1;
  94. }
  95. }
  96. System.out.println("Pozycja gracza o imieniu " + imie + " to " + pozycja);
  97. return pozycja;
  98. }
  99.  
  100. //B
  101. public static int liczbaN(List<String> zawodnik, String narody) {
  102. int i = 0;
  103. int licznik = 0;
  104. for (i = 0; i < zawodnik.size(); i++) {
  105. if (zawodnik.get(i).contains(narody)) {
  106. licznik++;
  107. }
  108. }
  109. System.out.println("Z narodu " + narody + " w TOP 50 jest: " + licznik + " gracz(y)");
  110. return licznik;
  111. }
  112.  
  113. //C
  114. public static double srednia(List<String> lista, int iloscGraczy) throws IOException {
  115.  
  116. double suma = 0;
  117. double srednia = 0;
  118. double Roznica = 0; // pomocnicza zmienna licząca sume roznic wieku.(do odchylenia)
  119. double N = 0.1;
  120. double od = 0;
  121. for (int i = 0; i < 10; i++) {
  122. suma += Integer.parseInt(lista.get(i));
  123. }
  124. srednia = suma / iloscGraczy;
  125. System.out.println("Srednia wieku " + iloscGraczy + " zawodników wynosi: " + srednia);
  126.  
  127.  
  128. for (int j = 0; j < 10; j++) {
  129. Roznica += Math.pow(Integer.parseInt(lista.get(j)) - (srednia), 2);
  130. od = Math.sqrt(N * Roznica); // N=10, wiec 1/N=0.1
  131.  
  132. }
  133. System.out.println("Odchylenie standardowe: " + od);
  134. return srednia;
  135. }
  136.  
  137. //D
  138. public static int roznicaPkt(List<String> lista, List<String> lista2, String imie1, String imie2) {
  139.  
  140. int a = pozycja(lista, imie1) - 1;
  141. int b = pozycja(lista, imie2) - 1;
  142.  
  143. int punktya = Integer.parseInt(lista2.get(a));
  144. int punktyb = Integer.parseInt(lista2.get(b));
  145.  
  146. int c = punktya - punktyb;
  147. int d = punktyb - punktya;
  148. System.out.println("Roznica punktów pomiedzy Novakiem Djokoviciem a Rafealem Nadalem, a: " + c);
  149.  
  150. if (punktya > punktyb) {
  151. return c;
  152. } else {
  153. return d;
  154. }
  155. }
  156.  
  157. public static void zagraneTurnieje(List<String> lista) {
  158. String zapis = "turnieje.txt"; // zapisze plik o podanej nazwie
  159. try {
  160. File turnieje = new File(zapis);
  161. FileWriter tekst1 = new FileWriter(turnieje, false);
  162. BufferedWriter tekst2 = new BufferedWriter(tekst1);
  163.  
  164. for (int i = 0; i < lista.size(); i++) {
  165. String linia = lista.get(i);
  166. tekst2.write(linia);
  167. tekst2.newLine();
  168. }
  169. tekst2.close();
  170. tekst1.close();
  171. }
  172. catch (IOException e) {
  173. System.out.println("Blad");
  174. }
  175. }
  176. }
  177.  
  178. *****************************************************************************************************
  179. package com.company;
  180.  
  181. import java.io.*;
  182. import java.util.Random;
  183.  
  184. public class zapisDNA {
  185. public int dlugosc;
  186. public String sekwencja;
  187.  
  188. zapisDNA(int dlugosc) {
  189. if (dlugosc > 40 || dlugosc < 0) {
  190. System.out.println("Nieprawidłowa długość łańcucha");
  191. return;
  192. }
  193. this.dlugosc = dlugosc;
  194. }
  195.  
  196. public String zrobDNA() { //tworzymy losowa nic
  197. StringBuilder buduj = new StringBuilder();
  198. Random losuj = new Random();
  199. int n = 4;
  200. String kod = null;
  201. char[] zasadyAzotowe = {'A', 'G', 'C', 'T'};
  202. for (int i = 0; i < dlugosc; i++) {
  203. buduj.append(zasadyAzotowe[losuj.nextInt(n)]);
  204. kod = buduj.toString();
  205. }
  206. this.sekwencja = kod;
  207. return kod;
  208. }
  209.  
  210. public void zapiszDNA() { //zapis sekwencji DNA do pliku txt
  211. String plik = "utworzoneDNA.txt";
  212. File dna = new File(plik);
  213. FileWriter a = null;
  214. try {
  215. a = new FileWriter(dna, false);
  216. BufferedWriter b = new BufferedWriter(a);
  217. String linia = this.sekwencja;
  218. a.write(linia);
  219. a.close();
  220. b.close();
  221. } catch (IOException e) {
  222. e.printStackTrace();
  223. System.out.println("Błąd");
  224. }
  225. }
  226. }
  227. ************************************************
  228. package com.company;
  229.  
  230. import java.io.BufferedReader;
  231. import java.io.FileReader;
  232.  
  233. public class odczytDNA {
  234. public String kod;
  235. public String kodKomplementarny;
  236.  
  237. odczytDNA(String zrodlo) {
  238. load(zrodlo); //bezposrednie zaladowanie pliku txt
  239. }
  240.  
  241. public void load(String zrodlo) { //wczytywanie kodu ze zrodla
  242. try {
  243. FileReader fr = new FileReader(zrodlo);
  244. BufferedReader br = new BufferedReader(fr);
  245. String line;
  246. while ((line = br.readLine()) != null) {
  247. kod = line;
  248. }
  249. } //try
  250. catch (Exception e) {
  251. System.out.println("Blad");
  252. }//catch
  253. }
  254.  
  255. public String generujKomplementarny() { //tworzenie nici komplementarnej i przyporzadkowanie polu klasy
  256. // "kodKomplementarny"
  257. StringBuilder buduj = new StringBuilder();
  258. char polimerazaDNA;
  259. String kodKomplementarny = null;
  260. for (int i = 0; i < this.kod.length(); i++) {
  261. polimerazaDNA = this.kod.charAt(i);
  262.  
  263. if (polimerazaDNA == 'C') buduj.append('G');
  264. else if (polimerazaDNA == 'A') buduj.append('T');
  265. else if (polimerazaDNA == 'G') buduj.append('C');
  266. else if (polimerazaDNA == 'T') buduj.append('A');
  267. kodKomplementarny = buduj.toString();
  268. this.kodKomplementarny = kodKomplementarny;
  269. }
  270. return kodKomplementarny;
  271. }
  272. }
  273. ***********************************************
  274. package com.company;
  275.  
  276. import java.io.IOException;
  277.  
  278. public class TestDNA {
  279. public static void main(String[] Args) throws IOException {
  280. zapisDNA DNA = new zapisDNA(40);
  281. DNA.zrobDNA();
  282. System.out.println("Otrzymana sekwencja : " + DNA.sekwencja);
  283. DNA.zapiszDNA();
  284.  
  285. odczytDNA odczytaj = new odczytDNA("utworzoneDNA.txt");
  286. odczytaj.generujKomplementarny();
  287. System.out.println("Utworzon nić komplementarna DNA : " + odczytaj.kodKomplementarny);
  288. }
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement