Guest User

Untitled

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