Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class DogOwner{
  4.  
  5. private String ownerName;
  6. private int foodAmount;
  7. private Dog dogOne = new Dog();
  8. private Dog dogTwo = new Dog();
  9.  
  10. public DogOwner(){
  11.  
  12. Random randNum = new Random();
  13.  
  14. ownerName = "some name";
  15. foodAmount = randNum.nextInt(40) + 10;
  16. dogOne.setName("Fido");
  17. dogTwo.setName("Fido");
  18. }
  19.  
  20. public String getOwnerName(){
  21. return ownerName;
  22. }
  23.  
  24. public void setOwnerName(String newOwnerName){
  25. ownerName = newOwnerName;
  26. }
  27.  
  28. public int getFoodAmount(){
  29. return foodAmount;
  30. }
  31.  
  32. public void setFoodAmount(int newFoodAmount){
  33. foodAmount = newFoodAmount;
  34. }
  35.  
  36. public int feedDog(){
  37. foodAmount = (foodAmount - 1);
  38. System.out.println("Remaining food = " + foodAmount);
  39. return foodAmount;
  40. }
  41.  
  42. public static void main(String args[]){
  43. DogOwner test = new DogOwner();
  44. test.setFoodAmount(25);
  45. System.out.println("Initial food = " + test.getFoodAmount() );
  46. test.feedDog();
  47. Dog noError = new Dog();
  48. noError.setSpeed(5);
  49.  
  50. dogOne.setSpeed(5);
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement