Nesne Tabanlı Programlama-1 (Yaz-2016) Hafta-6/2
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 |
package main; import yardimci.ortak; import islemler.cevre.*; import islemler.hacim.*; public class baslat extends ortak { public baslat() { boolean durum=true; do{ yaz("",true); yaz(".::MENU::.",true); yaz("1) Dikdörtgen Hacim Hesabı",true); yaz("2) Dikdörtgen Çevre Hesabı",true); yaz("3) Küre Hacim Hesabı",true); yaz("4) Daire Çevre Hesabı",true); yaz("5) Çıkış",true); String secim = verigetir("Seçim Yapınız:"); switch (secim) { case "1": new islemler.hacim.dikdortgen().sonucgoster("Dikdörgen Hacim Hesabı"); break; case "2": new islemler.cevre.dikdortgen().sonucgoster("Dikdörgen Çevre Hesabı"); break; case "3": new kure().sonucgoster("Küre Hacim Hesabı"); break; case "4": new daire().sonucgoster("Daire Çevre Hesabı"); break; case "5": yaz("Çıkış yapılıyor!",true); durum=false; break; default: yaz("Geçerli bir seçim yapmadınız!",true); break; } }while(durum); } public static void main(String[] args) { new baslat(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
package islemler.cevre; import yardimci.*; public class daire extends soyut { public double hesapla() { int r = sayigetir("Yarıçapı giriniz:"); //Math.PI return 2*3.14*r; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package islemler.cevre; import yardimci.*; public class dikdortgen extends soyut { public double hesapla() { int a = sayigetir("1. Kenarı Giriniz:"); int b = sayigetir("2. Kenarı Giriniz:"); return (a+b)*2; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package islemler.hacim; import yardimci.*; public class dikdortgen extends soyut { public double hesapla() { int a = sayigetir("Eni Giriniz:"); int b = sayigetir("Boyu Giriniz:"); int c = sayigetir("Yükseklik Giriniz:"); return a*b*c; } } |
1 2 3 4 5 6 7 8 9 10 11 |
package islemler.hacim; import yardimci.*; public class kure extends soyut{ public double hesapla() { int r = sayigetir("Yarıçapı giriniz:"); return (4/3)*Math.PI*Math.pow(r, 3); } } |
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 |
package yardimci; import java.util.*; public class ortak { public void yaz(String metin,boolean altsatir) { if(altsatir) System.out.println(metin); else System.out.print(metin); } public String verigetir(String metin) { yaz(metin,false); Scanner sc = new Scanner(System.in); return sc.nextLine(); } public int sayigetir(String metin) { int sayi=0; boolean durum=true; do{ Scanner sc = new Scanner(System.in); try{ yaz(metin,false); sayi=sc.nextInt(); durum=false; }catch(Exception ex) { yaz("Girilen bilgi sayi degil",true); } }while(durum); return sayi; } } |
1 2 3 4 5 6 7 8 9 10 11 12 |
package yardimci; public abstract class soyut extends ortak { public abstract double hesapla(); public void sonucgoster(String metin) { yaz(metin+" işleminin sonucu:"+hesapla(), true); } } |
NTP1 (Yaz-2017) Hafta-6/2
Okumaya devam et
Son Yorumlar