Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. public class Program{
  4. Student[] tab;
  5. public int policz(){
  6. int i=0;
  7. try{
  8. Scanner s= new Scanner(new FileReader("plik.txt"));
  9. s.nextLine();
  10. while(s.hasNextLine()){
  11. Scanner sca = new Scanner(s.nextLine());
  12. i++;
  13. }
  14. }
  15. catch(FileNotFoundException e){}
  16. return i;
  17. }
  18. public void wczytaj(){
  19. tab=new Student[policz()-1];
  20. int j=0;
  21. try{
  22. Scanner s= new Scanner(new FileReader("plik.txt"));
  23. s.nextLine();
  24. while(s.hasNextLine()){
  25. Scanner sca = new Scanner(s.nextLine());
  26. int indeks = sca.nextInt();
  27. String nazwisko = sca.next();
  28. String imie = sca.next();
  29. double srednia = sca.nextDouble();
  30. tab[j] = new Student(indeks, nazwisko, imie, srednia);
  31. sca.close();
  32. j++;
  33. }
  34. }
  35. catch(FileNotFoundException e){}
  36. }
  37. public void wpiszOcene(){
  38. int i=0;
  39. Scanner s = new Scanner(System.in);
  40. System.out.println("Podaj numer indeksu studenta");
  41. int indeks = s.nextInt();
  42. for(;i<tab.length;i++){
  43. if(indeks==tab[i].indeks){}
  44. else{System.out.println("Studenta o takim numerze indeksu nie ma");}
  45. }
  46. System.out.println("Podaj ocenę którą chcesz wpisać");{
  47. int ocena = s.nextInt();
  48. }
  49. }
  50. public void wyswietl(){
  51. for(int i=0;i<tab.length;i++){
  52. System.out.println(tab[i].indeks+ " " +tab[i].nazwisko+ " " +tab[i].imie + " " +tab[i].srednia);
  53. }
  54. }
  55. public double wyswietlSredniaOcenPoz(){
  56. double suma=0;
  57. int licz=0;
  58. for(int i=0;i<tab.length;i++){
  59. if(tab[i].srednia>=3.0){
  60. suma+=tab[i].srednia;
  61. licz++;
  62. }
  63. }
  64. return suma/licz;
  65. }
  66. public void wyswietlStudNiez(){
  67. for(int i=0;i<tab.length;i++){
  68. if(tab[i].srednia<3.0){
  69. System.out.println(tab[i].indeks+ " " +tab[i].nazwisko+ " " +tab[i].imie + " " +tab[i].srednia);
  70.  
  71. }
  72. }
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement