Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication3;
- import java.io.*;
- import java.util.Scanner;
- public class G4{
- private String name;
- private String vname;
- private int id;
- public G4(String nev,String vnev,int id){
- this.name = nev;
- this.vname = vnev;
- this.id = id;
- }
- public void setName(String nev){
- this.name = nev;
- }
- public String getName(){
- return name;
- }
- public void setVname(String vnev){
- this.vname = vnev;
- }
- public String getVname(){
- return vname;
- }
- public void setId(int id){
- this.id = id;
- }
- public int getId(){
- return id;
- }
- public static void main(String args[]) throws Exception{
- G4 obj1 = new G4("Nev","Vnev", 22);
- int tanuloszam;
- int i = 0;
- Scanner in = new Scanner(System.in);
- InputStreamReader r = new InputStreamReader(System.in);
- BufferedReader br = new BufferedReader(r);
- File file = new File("C://modul.txt");
- if(!file.exists()){
- file.createNewFile();
- }
- FileWriter fw = new FileWriter(file,true);
- BufferedWriter bw = new BufferedWriter(fw);
- PrintWriter pw = new PrintWriter(bw);
- System.out.println("Kérem adja meg a csoport tanulóianak a számát: ");
- tanuloszam = in.nextInt();
- while( i < tanuloszam){
- System.out.println("Kérem adja meg a tanuló keresztnevét: ");
- obj1.setName(br.readLine());
- System.out.println("Kérem adja meg a tanuló vezetéknevét: ");
- obj1.setVname(br.readLine());
- System.out.println("Kérem adja meg a tanuló azonosító számát: ");
- obj1.setId(in.nextInt());
- pw.println(obj1.getName()+" "+obj1.getVname()+" "+obj1.getId());
- i++;
- }
- Scanner entireFileText = new Scanner(new File("C://modul.txt"));//.useDelimiter("\\A");
- i = 0;
- br.close();
- r.close();
- in.close();
- pw.close();
- bw.close();
- fw.close();
- while( i < tanuloszam){
- obj1.setName(entireFileText.nextLine());
- obj1.setVname(entireFileText.nextLine());
- obj1.setId(entireFileText.nextInt());
- System.out.println(obj1.getName()+" "+obj1.getVname()+" "+obj1.getId());
- i++;
- }
- entireFileText.close();
- }}
Advertisement
Add Comment
Please, Sign In to add comment