Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement