• 12-11-2013, 22:27:41
    #1
    Üyeliği durduruldu
    Merhaba İyi geceler;

    Java ya yeni başladık biraz kendimi geliştirmeye çalışyorum . Ama yazdığım bir programda hata alıyorum. Program 'da 3 isci tipi farklı bir metodla işçilerin ması hesaplanıyor. 1.tip sadece mesaj çalışıyor ama 2 ve 3 tipte komisyon için sattığı ürün sayısını sormuyor. Yardım edebilecek varmı?
    Alıntı
    import java.util.Scanner;


    public class Emp {

    public static void main(String[] args) {
    //
    Scanner s = new Scanner(System.in);

    int maas=1500;
    int type = 1;
    int b = 0;
    int sell=0;
    double c =Maas(maas,type,b,sell);
    System.out.println("Lütfen İsim Girin");
    String isim = s.nextLine();
    System.out.println("Lütfen Kişi Tipini Giriniz ");
    type = s.nextInt();

    System.out.println(c);
    }
    public static double Maas( int a,int tip,int c,int sold ){
    Scanner s = new Scanner(System.in);
    a = 1500;
    if (tip == 1){
    return c=a ;
    }

    else if (tip == 2)
    {
    System.out.println("Toplam Kaç Ürün Sattı");
    sold = s.nextInt();
    return c= (int) (a + (sold*0.01));
    }
    else if (tip ==3)
    {
    System.out.println("Toplam Kaç Ürün Sattı");
    sold = s.nextInt();
    return c= (int) (sold*0.1);
    }
    return c;




    }

    }
  • 13-11-2013, 02:34:49
    #2
    main metod'daki
    double c =Maas(maas,type,b,sell);
    System.out.println("Lütfen İsim Girin");
    String isim = s.nextLine();
    System.out.println("Lütfen Kişi Tipini Giriniz ");
    type = s.nextInt();

    şu kısmı incelersek.Sizin yazdıgınız kod double tipinde bir c değişkenine Maas(...) metodundan buldugu sonucu atıyor.Yani siz kullanıcıdan kişi tipini istemeden önce maaşı hesaplatıyorsunuz


    System.out.println("Lütfen İsim Girin");
    String isim = s.nextLine();
    System.out.println("Lütfen Kişi Tipini Giriniz ");
    type = s.nextInt();
    double c =Maas(maas,type,b,sell);

    Bu şekilde değiştirdiğinizde sorununuz çözülecektir.

    Kolay gelsin, iyi çalışmalar.