close

題目:
給定時數和時薪,求出薪資



step 1:建一個Salary class



public class Salary
{

private int hour;

private double money;


public Salary()
{
    hour=0;
    money=0;
}

public Salary(int hour,double money)
{
    this.hour=hour;
    this.money=money;
}

    public int getHour()
    {

         return hour;
    }

    public void setHour(int hour)
    {

      this.hour=hour;
    }

    public int getMoney()

       {          
          return money;
 

       }

        public int setMoney()

       {           
           this.money=money;

       }

        public double compute()      
       {
           return hour*money;
        }

}




step 2: Main class

public class Main 

{

public static void main(String[] args) 

{

Salary Niki=new Salary(9,500);

System.out.println("Niki's salary is:"+Niki.compute());

}

}


顯示結果:

Niki's salary is:4500.0


arrow
arrow
    文章標籤
    Java
    全站熱搜
    創作者介紹
    創作者 布拉怡 的頭像
    布拉怡

    nini的部落格

    布拉怡 發表在 痞客邦 留言(0) 人氣()