Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 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. package liczwystapienia;
  7.  
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.IOException;
  11. import java.io.PrintWriter;
  12. import java.util.Scanner;
  13.  
  14. /**
  15. *
  16. * @author Darkey
  17. */
  18. public class main {
  19.  
  20. public static void main(String[] args){
  21.  
  22.  
  23.  
  24. /*
  25. Egzamin egz = new Egzamin(2,3);
  26.  
  27. egz.wpiszOcene(0, 0, 4);
  28. egz.wpiszOcene(0, 1, 4);
  29. egz.wpiszOcene(0, 2, 4);
  30.  
  31. egz.wpiszOcene(1, 0, 2);
  32. egz.wpiszOcene(1, 1, 2);
  33. egz.wpiszOcene(1, 2, 3);
  34.  
  35. System.out.println(egz.zaliczonyEgzamin(0));
  36. System.out.println(egz.zaliczonyEgzamin(1));
  37.  
  38. egz.piszDane();
  39. */
  40. }
  41.  
  42. public void funkcja(String plik){
  43.  
  44. int nr_zamowienia;
  45. String nazwa;
  46. double cena;
  47. int l_sztuk;
  48.  
  49. try{
  50. Scanner sc = new Scanner(new File(plik + ".txt"));
  51. PrintWriter writer = new PrintWriter(new File(plik + ".wyn"));
  52.  
  53.  
  54. while(sc.hasNext()){
  55. nr_zamowienia = sc.nextInt();
  56. nazwa = sc.nextLine();
  57. cena = sc.nextDouble();
  58. l_sztuk = sc.nextInt();
  59. }
  60.  
  61.  
  62. }
  63. catch(Exception e ){
  64. System.out.println("XD");
  65. }
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. }
  73.  
  74.  
  75. class Egzamin{
  76. private float[][] oceny;
  77.  
  78. Egzamin(int lStudentow, int lZadan){
  79. this.oceny = new float[lStudentow][lZadan];
  80. }
  81. public float ObliczSrednia(int student){
  82. float suma = 0;
  83. int counter = 0;
  84. for(int x = 0; x < oceny[student].length; x++){
  85. if(oceny[student][x] > 2){
  86. counter++;
  87. }
  88. suma = suma + oceny[student][x];
  89. }
  90.  
  91. if(counter > (oceny[student].length/2))
  92. return 2;
  93. else
  94. return (suma / (oceny[student].length));
  95.  
  96. }
  97.  
  98. public boolean zaliczonyEgzamin(int student){
  99. float srednia = ObliczSrednia(student);
  100. System.out.println(srednia);
  101. if(srednia >= 3 ){
  102. return true;
  103. }
  104. else
  105. return false;
  106.  
  107. }
  108.  
  109. public void wpiszOcene(int student, int zadanie, float ocena){
  110. oceny[student][zadanie] = ocena;
  111. }
  112. public void piszDane(){
  113. for(int i = 0; i < oceny.length; i++){
  114. System.out.print(i + "; ");
  115. for(int j = 0; j < oceny[i].length; j++){
  116.  
  117. System.out.print(oceny[i][j] + "; ");
  118. }
  119. System.out.println(ObliczSrednia(i));
  120.  
  121. }
  122. }
  123.  
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement