Java-2 – 2016 – Hafta – 4 – 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class nothesaplama implements ActionListener { JLabel jlab_sonuc; JTextField jtf_vize, jtf_final; public nothesaplama() { JFrame jfrm = new JFrame("Not Hesaplama"); jfrm.setSize(130,120); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jfrm.setLayout(new FlowLayout()); JLabel jlab1= new JLabel("Vize:"); jtf_vize = new JTextField(5); JLabel jlab2= new JLabel("Final:"); jtf_final = new JTextField(5); JButton jbtn = new JButton("Hesapla"); jbtn.addActionListener(this); // butonun tiklama olayini izle jlab_sonuc= new JLabel(); jfrm.add(jlab1); jfrm.add(jtf_vize); jfrm.add(jlab2); jfrm.add(jtf_final); jfrm.add(jbtn); jfrm.add(jlab_sonuc); jfrm.setVisible(true); } public void actionPerformed(ActionEvent ae) { // hesaplama kodu int vize_notu=kontrol(jtf_vize.getText()); int final_notu=kontrol(jtf_final.getText()); if(vize_notu>-1 && final_notu>-1) { String harf= "FF"; String sonuc=""; if(final_notu>29) { int ort=(int)Math.round(vize_notu*0.4+final_notu*0.6); String[] harfler={"AA","BA","BB","CB","CC","DC","DD","FD"}; int[] sinirlar={90,80,70,60,50,40,35,30}; for(int i=0;i<sinirlar.length;i++) { if(ort>=sinirlar[i]) { harf=harfler[i]; break; } } sonuc="Ort: "+ort+" Harf: "+harf; } else sonuc="Harf: FF (final<30)"; jlab_sonuc.setText(sonuc); } } public int kontrol(String str) { try { int not=Integer.parseInt(str); if(not>=0 && not<=100) return not; return -1; } catch(Exception ex) { } return -1; } public static void main(String[] adsd) { new nothesaplama(); } } |