Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. package egzaminoceny;
  2.  
  3.  
  4.  
  5. //class Oceny
  6. //{
  7. // private float[][] oceny = null;
  8. //
  9. // public Oceny( int liczbaStudentow, int liczbaPrzedmiotow )
  10. // {
  11. // oceny = new float[liczbaStudentow][liczbaPrzedmiotow];
  12. // for( int nrStud = 0; nrStud < oceny.length; ++nrStud )
  13. // for( int nrPrzed = 0; nrPrzed < oceny[ nrStud ].length; ++nrPrzed )
  14. // oceny[ nrStud ][ nrPrzed ] = -1;
  15. // }
  16. // public void wpiszOcene(int student, int przedmiot, float ocena )
  17. // {
  18. // if( student < 0 || student >= oceny.length )
  19. // return;
  20. // if( przedmiot < 0 || przedmiot >= oceny[ student ].length )
  21. // return;
  22. // if( ocena >= 2 && ocena <= 5 )
  23. // oceny[ student ][ przedmiot ] = ocena;
  24. // }
  25. // public float obliczSredna( int student )
  26. // {
  27. // if( student < 0 || student >= oceny[ student ].length )
  28. // return 0;
  29. //
  30. // float suma = 0;
  31. // int ileOcenWystawionych = 0;
  32. // for( int nrPrzed = 0; nrPrzed < oceny[ student ].length; ++nrPrzed )
  33. // if( oceny[ student ][ nrPrzed ] != -1 )
  34. // {
  35. // suma += oceny[ student ][ nrPrzed ];
  36. // ileOcenWystawionych++;
  37. // }
  38. //
  39. // if( ileOcenWystawionych > 0 )
  40. // return suma / ileOcenWystawionych;
  41. // else
  42. // return 0;
  43. // }
  44. //
  45. // public boolean zaliczonySemestr(int student)
  46. // {
  47. // float srednia=0;
  48. // srednia=obliczSredna(student);
  49. //
  50. // for( int nrStud = 0; nrStud < oceny.length; ++nrStud )
  51. // for( int nrPrzed = 0; nrPrzed < oceny[ nrStud ].length; ++nrPrzed )
  52. // if( oceny[ student ][ nrPrzed ] == -1 )
  53. // return false;
  54. //
  55. // if(srednia<3.0)
  56. // return false;
  57. //
  58. // else
  59. // return true;
  60. //
  61. // }
  62. //
  63. // void zmienOcene (int student, int przedmiot, float ocena)
  64. // {
  65. // if (student <0 || student >= oceny.length)
  66. // return;
  67. // if (przedmiot<0 || przedmiot>=oceny[student].length)
  68. // return;
  69. // if( !(ocena >= 2 && ocena <= 5) )
  70. // return;
  71. //
  72. // float srednia=0;
  73. //
  74. // if(oceny[student][przedmiot]==-1)
  75. // srednia = ocena/2;
  76. //
  77. // srednia = (oceny[student][przedmiot] + ocena)/2;
  78. // oceny[ student ][ przedmiot ] = srednia;
  79. //
  80. // }
  81. //
  82. // void pisz()
  83. // {
  84. //
  85. // }
  86. //}
  87. public class EgzaminOceny
  88. {
  89.  
  90. public static void main(String[] args)
  91. {
  92.  
  93. // Oceny dzienniczek = new Oceny( 5, 3 );
  94. // dzienniczek.wpiszOcene( 0, 0, 5.0f );
  95. // float srednia = dzienniczek.obliczSredna( 1 );
  96. //
  97. // System.out.println( "Średnia: " + srednia );
  98. //
  99. // dzienniczek.zaliczonySemestr(2);
  100.  
  101.  
  102. int tab[][] =
  103. {
  104. {-1,10,123},
  105. {8,30,13,},
  106. {0,-10,153}
  107. };
  108. for (int i=0; i<tab.length;i++)
  109. {
  110. String listaOcen = "";
  111. float srednia = 0;
  112. float suma = 0;
  113. for (int j=0; j>tab[i].length;j++)
  114. {
  115. if(tab[i][j] != -1)
  116. {
  117. listaOcen = listaOcen + " " + tab[i][j] + " ";
  118. suma += tab[i][j];
  119. }
  120. System.out.println("Student " + i +" Oceny" + listaOcen + " średnia " + suma/tab[i].length);
  121.  
  122. }
  123.  
  124.  
  125. }
  126.  
  127. // for (int i=0;i<tab.length;i++)
  128. // for(int j = 0; j<tab[i].length;j++)
  129. // System.out.print(tab[i][j] + " ");
  130.  
  131.  
  132. }
  133.  
  134.  
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement