about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/3/Java/Cow.java
blob: 36a10513639628528844f25d04f4740c4d591515 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class Cow
{
  private String name;
  private String breed;
  private int age;

  public Cow(String name, String breed)
  {
    this(name, breed, 0);
  }

  public Cow(String name, String breed, int age)
  {
    this.name = name;
    this.breed = breed;
    setAge(age);
  }

  public static void moo()
  {
    System.out.println("Moo...!");
  }

  public int getAge()
  {
    return age;
  }

  public void setAge(int age)
  {
    if (age < 0)
      throw new IllegalArgumentException(
        "age must be nonnegative, instead got " + age);
    this.age = age;
  }
}