close

{寶可夢物件使用藍圖}

[主程式]-[使用物件]

public class hello
{
    
    public static void main(String[] args)
    {
        
        Monster.NUM_MONSTERS = 386;
        
        Monster pikatu = new Monster();
        pikatu.HP = 100;
        pikatu.DAMAGE = 10;
        
        Monster fire = new Monster();
        fire.ID = 1;
        
    }
}

 

 

[宣告類別]

public class Monster 
{
    public static int NUM_MONSTERS;
    
    public int HP;
    public int ID;
    public int DAMAGE;
    
    public Monster()
    {
        
    }
}

{算BMI}

[主程式]

public class hello
{
    
    public static void main(String[] args)
    {
        Student A = new Student();
        Student B = new Student();
        Student C = new Student();
        
        A.height = 1.7f;
        A.weight = 60.0f;
        
        B.height = 1.5f;
        B.weight = 40.0f;
        
        C.height = 1.9f;
        C.weight = 90.0f;
        
        System.out.println(A.bmi());
        System.out.println(B.bmi());
        System.out.println(C.bmi());

    }
}

 

[類別宣告]

public class Student 
{
    public float height;
    public float weight;

public float bmi()
    {
        return weight / (height * height);
    }

}

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 她家 的頭像
    她家

    她家

    她家 發表在 痞客邦 留言(0) 人氣()