SHARE
TWEET

Untitled

a guest Sep 16th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Animal {
  2.     //Homework18
  3.  
  4.     private int age;
  5.     private double weight;
  6.     public int getAge() {
  7.         return age;
  8.     }
  9.     public void setAge(int age) {
  10.         this.age = age;
  11.     }
  12.     public double getWeight() {
  13.        
  14.         return weight;
  15.     }
  16.     public void setWeight(double weight) {
  17.         if(weight <= 0) {
  18.             System.out.println("輸入錯誤");
  19.         }else {
  20.             this.weight = weight;
  21.         };
  22.        
  23.     }
  24.     public void speak(double weight,int age) {
  25.         System.out.println("體重:"+weight+"kg,年紀:"+age+"歲");
  26.     }
  27.    
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top