Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package osoba;
  8.  
  9. import java.util.StringTokenizer;
  10. import java.util.Scanner;
  11. import java.io.File;
  12. import java.io.*;
  13. import java.io.FileNotFoundException;
  14. import java.io.PrintWriter;
  15. /**
  16. *
  17. * @author stud
  18. */
  19. public class Zad1 {
  20.  
  21. public static void main(String[] args) {
  22.  
  23. Scanner scanner = new Scanner(System.in);
  24. int wybor = 0;
  25. boolean koniec = false;
  26.  
  27. while(true) {
  28.  
  29. wybor = scanner.nextInt();
  30.  
  31. switch(wybor) {
  32.  
  33. case 0:
  34.  
  35. koniec = true;
  36.  
  37. break;
  38. case 1:
  39.  
  40. Osoba osoba = new Osoba("Jan", "Nowak");
  41.  
  42. osoba.wypisz();
  43.  
  44. break;
  45. case 2:
  46.  
  47. Indeks[] indeks = new Indeks[3];
  48. indeks[0] = new Indeks("matematyka", 5.0);
  49. indeks[1] = new Indeks("fizyka", 4.5);
  50. indeks[2] = new Indeks("informatyka", 4.0);
  51.  
  52. Student student = new Student("Dawid", "Kowalski", "UPH", "Informatyka", 1, indeks);
  53.  
  54. student.wypisz();
  55.  
  56. System.out.println("Czy studiuje informatyke? " + student.sprawdz("Informatyka"));
  57. System.out.println("Czy studiuje ekonomie? " + student.sprawdz("Ekonomia"));
  58.  
  59. if(student.getRok() == 1 && student.getKierunek().equals("Informatyka")) {
  60.  
  61.  
  62.  
  63. try {
  64.  
  65. PrintWriter zapis = new PrintWriter("student.txt");
  66. zapis.println(student.getImie() + "\r\n");
  67. zapis.println(student.getNazwisko() + "\r\n");
  68. zapis.close();
  69. }
  70. catch(FileNotFoundException e) {
  71.  
  72. System.out.println(e.toString());
  73. }
  74.  
  75.  
  76. }
  77.  
  78. break;
  79. case 3:
  80.  
  81. try {
  82.  
  83. BufferedReader br = new BufferedReader(new FileReader(new File("studenci.txt")));
  84.  
  85. String line;
  86.  
  87. while((line = br.readLine()) != null) {
  88.  
  89. StringTokenizer token = new StringTokenizer(line);
  90.  
  91. while(token.hasMoreTokens()) {
  92.  
  93. String imie = token.nextToken();
  94. String nazwisko = token.nextToken();
  95. String uczelnia = token.nextToken();
  96. String kierunek = token.nextToken();
  97. String rok = token.nextToken();
  98. String przedmiot1 = token.nextToken();
  99. String ocena1 = token.nextToken();
  100. String przedmiot2 = token.nextToken();
  101. String ocena2 = token.nextToken();
  102. String przedmiot3 = token.nextToken();
  103. String ocena3 = token.nextToken();
  104.  
  105. Indeks[] przedmioty = new Indeks[3];
  106. przedmioty[0] = new Indeks(przedmiot1, Double.parseDouble(ocena1));
  107. przedmioty[1] = new Indeks(przedmiot2, Double.parseDouble(ocena2));
  108. przedmioty[2] = new Indeks(przedmiot3, Double.parseDouble(ocena3));
  109.  
  110. Student studenci = new Student(imie, nazwisko, uczelnia, kierunek, Integer.parseInt(rok), przedmioty);
  111.  
  112. studenci.wypisz();
  113.  
  114. System.out.println("Czy studiuje informatyke? " + studenci.sprawdz("Informatyka"));
  115. System.out.println("Czy studiuje ekonomie? " + studenci.sprawdz("Ekonomia"));
  116. }
  117. }
  118. }
  119. catch(FileNotFoundException e) {
  120.  
  121. System.out.println(e.toString());
  122. }
  123. catch(IOException e) {
  124.  
  125. System.out.println(e.toString());
  126. }
  127.  
  128. break;
  129. default:
  130. break;
  131. }
  132.  
  133. if(koniec) break;
  134. }
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement