Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Animal {
- //Homework18
- private int age;
- private double weight;
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public double getWeight() {
- return weight;
- }
- public void setWeight(double weight) {
- if(weight <= 0) {
- System.out.println("輸入錯誤");
- }else {
- this.weight = weight;
- };
- }
- public void speak(double weight,int age) {
- System.out.println("體重:"+weight+"kg,年紀:"+age+"歲");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement