Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.14 KB | None | 0 0
  1. class Oceny {
  2.    
  3.     private float [][] oceny = null;
  4.    
  5.     public Oceny(int liczbaStudnetow, int liczbaPrzedmiotow) {
  6.        
  7.         oceny = new float[liczbaStudnetow] [liczbaPrzedmiotow];
  8.         for( int nrStudenta = 0; nrStudenta <oceny.length; ++nrStudenta ) {
  9.             for ( int nrOceny = 0; nrOceny <oceny[nrStudenta].length; ++nrOceny) {
  10.                 oceny[nrStudenta][nrOceny] = -1;
  11.             }      
  12.         }
  13.     }
  14.    
  15.     public void Pisz() {
  16.         for( int nrStudenta = 0; nrStudenta <oceny.length; ++nrStudenta ) {
  17.                 System.out.print("Student: "+nrStudenta+"\t");
  18.             for ( int nrOceny = 0; nrOceny <oceny[nrStudenta].length; ++nrOceny) {
  19.                
  20.                 if(oceny[nrStudenta][nrOceny] != -1) {
  21.                 System.out.print(oceny[nrStudenta][nrOceny]+" ");
  22.                 }
  23.             }
  24.             System.out.print("Srednia ocen: "+ObliczSrednia(nrStudenta));
  25.             System.out.println("\n"+"Czy student nr: "+nrStudenta+" zaliczył semestr? > "+ZaliczonySemestr(nrStudenta)+"\n");
  26.         }
  27.     }
  28.    
  29.     public void WpiszOcene(int student, int przedmiot, float ocena) {
  30.         if( student < 0 || student >= oceny.length)
  31.             return;
  32.        
  33.         if( przedmiot < 0 || przedmiot >= oceny[student].length)
  34.             return;
  35.        
  36.         if(ocena < 0 || ocena > 5)
  37.             return;
  38.        
  39.             oceny[student][przedmiot] = ocena; 
  40.     }
  41.    
  42.     public void zmienOcene(int student, int przedmiot, float ocena) {
  43.         if( ocena > 0 || ocena <= 5) {
  44.             if(oceny[student][przedmiot] != -1) {
  45.                 oceny[student][przedmiot] = (oceny[student][przedmiot] + ocena)/2;
  46.             }
  47.         }
  48.     }
  49.    
  50.     boolean ZaliczonySemestr(int student) {
  51.         if ( ObliczSrednia(student) >2) {}
  52.         else{return false;}
  53.        
  54.         return true;
  55.     }
  56.    
  57.     public float ObliczSrednia(int student ) {
  58.        
  59.         float suma = 0;
  60.        
  61.             for( int nrOceny = 0; nrOceny <oceny[student].length; ++nrOceny) {
  62.                 if( oceny[student][nrOceny] != -1)
  63.                 suma += oceny[student][nrOceny];
  64.             }
  65.         return suma/oceny[student].length;
  66.        
  67.     }
  68. }
  69.  
  70. public class SESJA_01 {
  71.    
  72.     public static void main(String[] args) {
  73.        
  74.         Oceny dzienniczek = new Oceny (3, 4);
  75.         dzienniczek.WpiszOcene(1,2,4);
  76.         dzienniczek.WpiszOcene(1,1,3);
  77.         dzienniczek.WpiszOcene(1,0,5);
  78.         dzienniczek.WpiszOcene(1,3,5);
  79.         dzienniczek.Pisz();
  80.  
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement