Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package osoba;
- import java.util.StringTokenizer;
- import java.util.Scanner;
- import java.io.File;
- import java.io.*;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- /**
- *
- * @author stud
- */
- public class Zad1 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int wybor = 0;
- boolean koniec = false;
- while(true) {
- wybor = scanner.nextInt();
- switch(wybor) {
- case 0:
- koniec = true;
- break;
- case 1:
- Osoba osoba = new Osoba("Jan", "Nowak");
- osoba.wypisz();
- break;
- case 2:
- Indeks[] indeks = new Indeks[3];
- indeks[0] = new Indeks("matematyka", 5.0);
- indeks[1] = new Indeks("fizyka", 4.5);
- indeks[2] = new Indeks("informatyka", 4.0);
- Student student = new Student("Dawid", "Kowalski", "UPH", "Informatyka", 1, indeks);
- student.wypisz();
- System.out.println("Czy studiuje informatyke? " + student.sprawdz("Informatyka"));
- System.out.println("Czy studiuje ekonomie? " + student.sprawdz("Ekonomia"));
- if(student.getRok() == 1 && student.getKierunek().equals("Informatyka")) {
- try {
- PrintWriter zapis = new PrintWriter("student.txt");
- zapis.println(student.getImie() + "\r\n");
- zapis.println(student.getNazwisko() + "\r\n");
- zapis.close();
- }
- catch(FileNotFoundException e) {
- System.out.println(e.toString());
- }
- }
- break;
- case 3:
- try {
- BufferedReader br = new BufferedReader(new FileReader(new File("studenci.txt")));
- String line;
- while((line = br.readLine()) != null) {
- StringTokenizer token = new StringTokenizer(line);
- while(token.hasMoreTokens()) {
- String imie = token.nextToken();
- String nazwisko = token.nextToken();
- String uczelnia = token.nextToken();
- String kierunek = token.nextToken();
- String rok = token.nextToken();
- String przedmiot1 = token.nextToken();
- String ocena1 = token.nextToken();
- String przedmiot2 = token.nextToken();
- String ocena2 = token.nextToken();
- String przedmiot3 = token.nextToken();
- String ocena3 = token.nextToken();
- Indeks[] przedmioty = new Indeks[3];
- przedmioty[0] = new Indeks(przedmiot1, Double.parseDouble(ocena1));
- przedmioty[1] = new Indeks(przedmiot2, Double.parseDouble(ocena2));
- przedmioty[2] = new Indeks(przedmiot3, Double.parseDouble(ocena3));
- Student studenci = new Student(imie, nazwisko, uczelnia, kierunek, Integer.parseInt(rok), przedmioty);
- studenci.wypisz();
- System.out.println("Czy studiuje informatyke? " + studenci.sprawdz("Informatyka"));
- System.out.println("Czy studiuje ekonomie? " + studenci.sprawdz("Ekonomia"));
- }
- }
- }
- catch(FileNotFoundException e) {
- System.out.println(e.toString());
- }
- catch(IOException e) {
- System.out.println(e.toString());
- }
- break;
- default:
- break;
- }
- if(koniec) break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement