Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package cs.bennington.edu;
  2.  
  3. import java.util.Random;
  4.  
  5. /**
  6. * Hw assignment 1 problem 2
  7. * Creating a Cat class, fed through Main class
  8. * Make it declare age, encounter dogs
  9. * and be snooty the way cats be
  10. * Created by rkarlinsky on 2/28/15.
  11. */
  12.  
  13. public class Cat {
  14.  
  15. /** generating a random number between 1 and 20, i.e. cat ages
  16. * props to stack overflow for showing me how to get it in a range
  17. */
  18. public static int randInt(int min, int max) {
  19.  
  20. Random rand = new Random();
  21.  
  22. int randomNum = rand.nextInt((max-min)+1)+1;
  23.  
  24. return randomNum;
  25. }
  26.  
  27. // making an Age method, cat declares its age
  28. public static int Age(){
  29.  
  30. int randcatNum = randInt(1, 20);
  31.  
  32. return randcatNum;
  33. }
  34.  
  35. public static void Hello(){
  36. System.out.println("I'm a cat, I'm this old: " + Cat.Age());
  37. }
  38.  
  39. /**
  40. * making an encounterDog method,
  41. * if the cat is older the dog is scared
  42. * if the cat is younger the dog chases it
  43. */
  44. public static void encounterDog() {
  45. if (Dog.Age() < Cat.Age())
  46. System.out.println("Cat says: 'You're beneath my dignity you filthy animal'");
  47. else
  48. System.out.println("Cat says: 'It's a huge fucking dog get away!'");
  49. }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement