Java'da Sınav YAPMA.. PHP- Kodu: import java.applet.Applet; import java.awt.Button; import java.awt.Checkbox; import java.awt.CheckboxGroup; //import java.awt.Graphics; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class NewApplet extends Applet implements ActionListener { Label Soru = new Label(); Label PuanDurumu = new Label(); //Checkboxlar Radio button olsunlar diye CheckboxGroup Cevaplar = new CheckboxGroup(); Checkbox Acevap = new Checkbox("", Cevaplar, false); Checkbox Bcevap = new Checkbox("", Cevaplar, false); Checkbox Ccevap = new Checkbox("", Cevaplar, false); Checkbox Dcevap = new Checkbox("", Cevaplar, false); Checkbox Ecevap = new Checkbox("", Cevaplar, false); Button Tamam = new Button("Tamam"); String Sorular[][] = { {"4+2 Kaç eder2", "5", "6", "7", "8", "9", "2", "5"}, {"Türkiyenin baş kenti neresidir?", "Ankara", "İstanbul", "İzmir", "Bursa", "Edirne", "1", "10"} }; int SuankiSoru = 0; int Puan = 0; int DogruSayisi=0; public void init() { setLayout(null); PuanDurumu.setLocation(250, 5); PuanDurumu.setSize(200, 20); add(PuanDurumu); Soru.setLocation(10, 10); Soru.setSize(200, 20); add(Soru); Acevap.setLocation(10, 40); Acevap.setSize(200, 20); add(Acevap); Bcevap.setLocation(10, 60); Bcevap.setSize(200, 20); add(Bcevap); Ccevap.setLocation(10, 80); Ccevap.setSize(200, 20); add(Ccevap); Dcevap.setLocation(10, 100); Dcevap.setSize(200, 20); add(Dcevap); Ecevap.setLocation(10, 120); Ecevap.setSize(200, 20); add(Ecevap); SorulariYaz(SuankiSoru); Tamam.setLocation(10, 140); Tamam.setSize(60, 20); add(Tamam); Tamam.addActionListener(this); } public void actionPerformed(ActionEvent Olay) { if (SuankiSoru <Sorular.length) { CevabiKontrolEt(SuankiSoru); } SuankiSoru++; if (SuankiSoru < Sorular.length) { SorulariYaz(SuankiSoru); } else { SinaviBitir(); } } public void SorulariYaz(int SoruNo) { Cevaplar.setSelectedCheckbox(null); Soru.setText(Sorular[SoruNo][0]); Acevap.setLabel(Sorular[SoruNo][1]); Bcevap.setLabel(Sorular[SoruNo][2]); Ccevap.setLabel(Sorular[SoruNo][3]); Dcevap.setLabel(Sorular[SoruNo][4]); Ecevap.setLabel(Sorular[SoruNo][5]); } public void CevabiKontrolEt(int SoruNosu) { int VerilenCevapIndex = 0; if (Acevap.getState()) { VerilenCevapIndex = 1; } else if (Bcevap.getState()) { VerilenCevapIndex = 2; } else if (Ccevap.getState()) { VerilenCevapIndex = 3; } else if (Dcevap.getState()) { VerilenCevapIndex = 4; } else if (Ecevap.getState()) { VerilenCevapIndex = 5; } if (Integer.valueOf(Sorular[SoruNosu][6]) == VerilenCevapIndex) { //String tip integera dönüştürülüyor Puan += Integer.valueOf(Sorular[SoruNosu][7]); DogruSayisi++; //Integer deger stringe donusuyor PuanDurumu.setText(Integer.toString(Puan)); } } public void SinaviBitir() { //Var olan nesneleri gizliyoruz Soru.setVisible(false); Acevap.setVisible(false); Bcevap.setVisible(false); Ccevap.setVisible(false); Dcevap.setVisible(false); Ecevap.setVisible(false); Tamam.setVisible(false); Label Sonuc=new Label(Sorular.length + " soru içerisinden "+DogruSayisi+" doğru cevap ile "+ Puan+ " puan aldınız."); Sonuc.setLocation(10, 30); Sonuc.setSize(400, 20); add(Sonuc); } }
Resim -> [Üye Olmadan Linkleri Göremezsiniz. Üye Olmak için TIKLAYIN...]
Sorular Dizgi Halindedir.. Kod:
String Sorular[][] = {
{"4+2 Kaç eder2", "5", "6", "7", "8", "9", "2", "5"},
{"Türkiyenin baş kenti neresidir?", "Ankara", "İstanbul", "İzmir", "Bursa", "Edirne", "1", "10"}
}; Burdan Çoğaltabilirsiniz.. |