Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. /**
  2. * Created by nfswo on 25-Mar-17.
  3. */
  4. public class VeterinaryReport {
  5. private int numberOfDogs;
  6. private int numberOfCats;
  7.  
  8. public VeterinaryReport(int numberOfDogs, int numberOfCats){
  9. this.numberOfDogs = numberOfDogs;
  10. this.numberOfCats = numberOfCats;
  11. }
  12.  
  13. public VeterinaryReport(int numberOfBoth){
  14. this.numberOfCats = numberOfBoth / 2;
  15. this.numberOfDogs = numberOfBoth / 2;
  16. }
  17.  
  18. public void addDogs(int additionalDogs){
  19. this.numberOfDogs += additionalDogs;
  20. }
  21.  
  22. public void addCats(int additionalCats){
  23. this.numberOfCats += additionalCats;
  24. }
  25.  
  26. public void showReport(){
  27. System.out.println(this.numberOfDogs + " dogs\n" + this.numberOfCats + " cats");
  28. }
  29.  
  30. public static void main(String[] args){
  31. VeterinaryReport vr = new VeterinaryReport(12, 13);
  32. VeterinaryReport vr2 = new VeterinaryReport(24);
  33. vr.addCats(3);
  34. vr.addDogs(4);
  35. vr.showReport(); // shows 16 and 16
  36. vr2.addCats(5);
  37. vr2.showReport(); // shows 12 and 17
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement