package f09;
/**
 * @author Fenyvesi Tibor
 */
import java.io.*;
import java.util.Scanner;

public class f09 {
    public static void main(String[] args) {

        // 9.1. feladat
        Scanner sc = new Scanner(System.in);
        System.out.println("Kérem az első egész számot!");
        int x = sc.nextInt();
        System.out.println("Kérem a második egész számot!");
        int y = sc.nextInt();

        System.out.println("A két szám szorzata: " + x*y);

        // 9.2. feladat - írás
        try {
            FileWriter fw = new FileWriter("abc.txt");
            for (int i = 97; i <= 122; i++)
                fw.write(i);

            fw.close();
        }
        catch (IOException ioe){
            System.err.println(ioe.getMessage());
        }

        // 9.2. feladat - olvasás
        try {
            FileReader fr = new FileReader("abc.txt");
            int c;
            while ((c = fr.read()) != -1) {
                System.out.print((char)(c-32));
            }
            System.out.println("");
            fr.close();
        }
        catch (IOException ioe){
            System.err.println(ioe.getMessage());
        }

        // 9.3. feladat - írás
        try {
            System.setProperty("file.encoding", "UTF8");
            PrintWriter pw = new PrintWriter("napok.txt");
            pw.println("hétfő");
            pw.println("kedd");
            pw.println("szerda");
            pw.println("csütörtök");
            pw.println("péntek");
            pw.println("szombat");
            pw.println("vasárnap");
            pw.close();
        }
        catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }

        // 9.3. feladat - olvasás
        try {
            System.setProperty("file.encoding", "UTF8");
            BufferedReader br = new BufferedReader(new FileReader("napok.txt"));
            String sor;
            while ((sor = br.readLine()) != null) {
                System.out.print(sor + (sor.equals("vasárnap")?"":", "));
            }
            System.out.println("");
            br.close();
        }
        catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }

        // 9.4. feladat - írás/olvasás
        try {
            RandomAccessFile raf = new RandomAccessFile("abc.txt", "rw");
            long hossz = raf.length();
            long poz = 2; 
            int kód;
            while (poz < hossz) {
                raf.seek(poz); 
                kód = raf.read(); 
                raf.seek(poz); 
                raf.write(kód-32);
                poz += 3;
            }

            raf.seek(0);
            while ((kód = raf.read()) != -1) {
                System.out.print((char)kód);
            }
            System.out.println("");
            raf.close();
        }
        catch (IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        
    }
}
