Guest User

Untitled

a guest
Oct 15th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. package dogs;
  2.  
  3. import java.util.Random;
  4.  
  5.  
  6.  
  7. import java.util.Random;
  8. public class IN_CLASS_ACTIVITY_A {
  9.  
  10. public static void main(String[] args) {
  11. PetShop pets = new PetShop();
  12. pets.runApplication();
  13. }
  14.  
  15. }
  16.  
  17. abstract class Pet {
  18. public String petName;
  19. public int petStrength;
  20.  
  21. public Pet() {
  22. Random rand1 = new Random();
  23. petStrength = rand1.nextInt(100);
  24. }
  25.  
  26. }
  27.  
  28. class PetShop{
  29. public void runApplication() {
  30.  
  31. //result of calling doCompetition is that we will get an
  32. // array of 2 items
  33. // 0th element of Array: Number Dog Winners
  34. // First element of the Array: Number of Cat Winners
  35.  
  36. System.out.println("numberOfDogWinners : " + this.doCompetition()[0]);
  37. System.out.println("numberOfCatWinners : " + this.doCompetition()[1]);
  38.  
  39. }
  40.  
  41. public int[] doCompetition() {
  42. int[] returnValues = new int[2];
  43. int numberOfDogWinners = 0;
  44. int numberOfCatWinners = 0;
  45.  
  46. for (int i = 0; i<10; i++) {
  47.  
  48. if ((new Dog()).petStrength > (new Cat()).petStrength) {
  49. numberOfDogWinners++;
  50. }
  51. else {
  52. numberOfCatWinners++;
  53. }
  54. }
  55.  
  56. if (numberOfDogWinners > numberOfCatWinners) {
  57. returnValues[1] = numberOfDogWinners;
  58. returnValues[0] = numberOfCatWinners;
  59. }
  60. else {
  61.  
  62. returnValues[0] = numberOfDogWinners;
  63. returnValues[1] = numberOfCatWinners;}
  64. return returnValues;
  65.  
  66. }
  67.  
  68. }
  69.  
  70. class Dog extends Pet{
  71.  
  72. }
  73.  
  74. class Cat extends Pet{
  75.  
  76. }
Add Comment
Please, Sign In to add comment