close

    P.S. 這題我用的是不使用陣列的寫法,如果有同學需要的是陣列的再說吧!

    請利用物件導向程式設計的概念來設計一個公司的員工薪資程式。假設公司有5位員工,每位員工有職號、姓名、底薪、加班、請假天數、薪水的資料,薪水計算方式為底薪+加班時數*150-請假天數*1000

    import java.util.*;

    class pays
    {
        String id, name;
        int base, extra, excus, pay;
        pays link;
        
        pays()
        {
            link = null;
        }
        
        pays(String id,String name,int base, int extra, int excus)
        {
            this();
            this.id = id;
            this.name = name;
            this.base = base;
            this.extra = extra;
            this.excus = excus;    
        }
        
        void compPay()
        {
            pay = base + ( extra * 150 ) - ( excus * 1000 );
        }
        
        void show()
        {
            System.out.printf("%10s %20s %10d %10d %10d %10d\n",id, name, base, extra, excus, pay );
        }
    }
    public class pay
    {
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            pays top = new pays();
            pays p;
            
            for ( int i = 0; i < 5; i++ )
            {
                System.out.printf("請輸入職號: ");
                String id = sc.next();
                System.out.printf("請輸入性名: ");
                String name = sc.next();
                System.out.printf("請輸入底薪: ");
                int base = sc.nextInt();
                System.out.printf("請輸入加班時數: ");
                int extra = sc.nextInt();
                System.out.printf("請輸入請假天數: ");
                int excus = sc.nextInt();
                p = new pays(id, name, base, extra, excus);
                p.compPay();
                p.link = top.link;
                top.link = p;
            }
            
            p = top.link;
            while( p != null )
            {
                p.show();
                p = p.link;
            }
        }
    }


    arrow
    arrow
      全站熱搜
      創作者介紹
      創作者 Icen Zhong 的頭像
      Icen Zhong

      無止盡的Coding地獄

      Icen Zhong 發表在 痞客邦 留言(0) 人氣()