Skip to content

Instantly share code, notes, and snippets.

@emirozturk
Created March 12, 2020 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emirozturk/ec4e28d4491caec0c3da19ec935ac9d7 to your computer and use it in GitHub Desktop.
Save emirozturk/ec4e28d4491caec0c3da19ec935ac9d7 to your computer and use it in GitHub Desktop.
NYP 4.Hafta Uygulama
package net.emirozturk;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
class Ogrenci{
private int numara;
private String ad;
Ogrenci(int numara,String ad){
this.numara = numara;
this.ad = ad;
}
boolean esitMi(Ogrenci o){
return o.numara == numara && o.ad.equals(ad);
}
}
class OgrenciIslemleri{
boolean ogrenciKarsilastir(Ogrenci o1,Ogrenci o2){
return o1.esitMi(o2);
}
Ogrenci ogrenciOku(String kayit){
return new Ogrenci(Integer.parseInt(kayit.split("-")[0]),kayit.split("-")[1]);
}
boolean listedeVarMi(List<Ogrenci> liste,Ogrenci o){
for(var eleman: liste)
if(eleman.esitMi(o))
return true;
return false;
}
}
public class Main {
public static void main(String[] args) throws IOException {
OgrenciIslemleri oi = new OgrenciIslemleri();
List<Ogrenci> ogrenciListesi = new ArrayList<Ogrenci>();
List<String> lines = Files.readAllLines(Paths.get("/Users/emirozturk/Desktop/ogrenciler.txt"), StandardCharsets.UTF_8);
for(var line : lines){
ogrenciListesi.add(oi.ogrenciOku(line));
}
Ogrenci o = new Ogrenci(1,"a");
System.out.println(oi.listedeVarMi(ogrenciListesi,o));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment