Guest User

Untitled

a guest
May 24th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. class Dog {
  2. String name;
  3. int age;
  4.  
  5. String bark(){
  6. return "This dog barks like this : RUFF RUFF.";
  7. }
  8. }//end of class
  9.  
  10. public class Kennel{
  11. public static void main(String[] args){
  12.  
  13. //setting up the array mydogs from the Dog Class
  14.  
  15. Dog[] mydogs = new Dog[3];
  16.  
  17. // setting up the new dog objects to the arrays
  18.  
  19. mydogs[0] = new Dog();
  20. mydogs[1] = new Dog();
  21. mydogs[2] = new Dog();
  22. // adding value to the objects created in the array
  23.  
  24. // adding info to the first dog
  25. mydogs[0].name = "ROOFIE";
  26. mydogs[0].age = 4;
  27.  
  28. // adding info to the second dog
  29. mydogs[1].name = "Spike";
  30. mydogs[1].age = 7;
  31.  
  32. // adding info to the third dog
  33. mydogs[2].name = "GayLassie";
  34. mydogs[2].age = 50;
  35.  
  36. //calling name and ages of the set up Dogs in the arrays
  37.  
  38. //creating a loop to show all the dogs and ages of the dogs!
  39.  
  40. int x =0;
  41. while(x < 3) {
  42. System.out.println("name =" + " " + mydogs[x].name + " " + "Age =" + " " + mydogs[x].age + " " + mydogs[x].bark());
  43.  
  44. x++;
  45. }//end of while
  46.  
  47. }//end of main
  48.  
  49. }//end of class
Add Comment
Please, Sign In to add comment