Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Oceny {
- private float [][] oceny = null;
- public Oceny(int liczbaStudnetow, int liczbaPrzedmiotow) {
- oceny = new float[liczbaStudnetow] [liczbaPrzedmiotow];
- for( int nrStudenta = 0; nrStudenta <oceny.length; ++nrStudenta ) {
- for ( int nrOceny = 0; nrOceny <oceny[nrStudenta].length; ++nrOceny) {
- oceny[nrStudenta][nrOceny] = -1;
- }
- }
- }
- public void Pisz() {
- for( int nrStudenta = 0; nrStudenta <oceny.length; ++nrStudenta ) {
- System.out.print("Student: "+nrStudenta+"\t");
- for ( int nrOceny = 0; nrOceny <oceny[nrStudenta].length; ++nrOceny) {
- if(oceny[nrStudenta][nrOceny] != -1) {
- System.out.print(oceny[nrStudenta][nrOceny]+" ");
- }
- }
- System.out.print("Srednia ocen: "+ObliczSrednia(nrStudenta));
- System.out.println("\n"+"Czy student nr: "+nrStudenta+" zaliczył semestr? > "+ZaliczonySemestr(nrStudenta)+"\n");
- }
- }
- public void WpiszOcene(int student, int przedmiot, float ocena) {
- if( student < 0 || student >= oceny.length)
- return;
- if( przedmiot < 0 || przedmiot >= oceny[student].length)
- return;
- if(ocena < 0 || ocena > 5)
- return;
- oceny[student][przedmiot] = ocena;
- }
- public void zmienOcene(int student, int przedmiot, float ocena) {
- if( ocena > 0 || ocena <= 5) {
- if(oceny[student][przedmiot] != -1) {
- oceny[student][przedmiot] = (oceny[student][przedmiot] + ocena)/2;
- }
- }
- }
- boolean ZaliczonySemestr(int student) {
- if ( ObliczSrednia(student) >2) {}
- else{return false;}
- return true;
- }
- public float ObliczSrednia(int student ) {
- float suma = 0;
- for( int nrOceny = 0; nrOceny <oceny[student].length; ++nrOceny) {
- if( oceny[student][nrOceny] != -1)
- suma += oceny[student][nrOceny];
- }
- return suma/oceny[student].length;
- }
- }
- public class SESJA_01 {
- public static void main(String[] args) {
- Oceny dzienniczek = new Oceny (3, 4);
- dzienniczek.WpiszOcene(1,2,4);
- dzienniczek.WpiszOcene(1,1,3);
- dzienniczek.WpiszOcene(1,0,5);
- dzienniczek.WpiszOcene(1,3,5);
- dzienniczek.Pisz();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement