Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Program{
- Student[] tab;
- public int policz(){
- int i=0;
- try{
- Scanner s= new Scanner(new FileReader("plik.txt"));
- s.nextLine();
- while(s.hasNextLine()){
- Scanner sca = new Scanner(s.nextLine());
- i++;
- }
- }
- catch(FileNotFoundException e){}
- return i;
- }
- public void wczytaj(){
- tab=new Student[policz()-1];
- int j=0;
- try{
- Scanner s= new Scanner(new FileReader("plik.txt"));
- s.nextLine();
- while(s.hasNextLine()){
- Scanner sca = new Scanner(s.nextLine());
- int indeks = sca.nextInt();
- String nazwisko = sca.next();
- String imie = sca.next();
- double srednia = sca.nextDouble();
- tab[j] = new Student(indeks, nazwisko, imie, srednia);
- sca.close();
- j++;
- }
- }
- catch(FileNotFoundException e){}
- }
- public void wpiszOcene(){
- int i=0;
- Scanner s = new Scanner(System.in);
- System.out.println("Podaj numer indeksu studenta");
- int indeks = s.nextInt();
- for(;i<tab.length;i++){
- if(indeks==tab[i].indeks){}
- else{System.out.println("Studenta o takim numerze indeksu nie ma");}
- }
- System.out.println("Podaj ocenę którą chcesz wpisać");{
- int ocena = s.nextInt();
- }
- }
- public void wyswietl(){
- for(int i=0;i<tab.length;i++){
- System.out.println(tab[i].indeks+ " " +tab[i].nazwisko+ " " +tab[i].imie + " " +tab[i].srednia);
- }
- }
- public double wyswietlSredniaOcenPoz(){
- double suma=0;
- int licz=0;
- for(int i=0;i<tab.length;i++){
- if(tab[i].srednia>=3.0){
- suma+=tab[i].srednia;
- licz++;
- }
- }
- return suma/licz;
- }
- public void wyswietlStudNiez(){
- for(int i=0;i<tab.length;i++){
- if(tab[i].srednia<3.0){
- System.out.println(tab[i].indeks+ " " +tab[i].nazwisko+ " " +tab[i].imie + " " +tab[i].srednia);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement