Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. package cs.bennington.edu;
  2.  
  3. import java.util.Random;
  4. // Bringin' in random numbahs
  5.  
  6.  
  7. /**
  8. * First hw assignment, problem 2
  9. * Creating Cat and Dog classes with all sorts of instances
  10. * Running through the Main class!
  11. * Created by rkarlinsky on 2/28/15.
  12. * @ authored by Roi
  13. */
  14.  
  15. // Creating a Dog class
  16. public class Dog {
  17.  
  18. /**
  19. * generating a random number between 1 and 14, i.e. dog ages
  20. * props to stack overflow for showing me how to get it in a range
  21. */
  22. public static int randInt(int min, int max) {
  23.  
  24. Random rand = new Random();
  25.  
  26. int randomNum = rand.nextInt((max - min) + 1) + 1;
  27.  
  28. return randomNum;
  29. }
  30.  
  31. // making an Age method, dog declares its age
  32. public static int Age() {
  33. int randogNum = randInt(1, 14);
  34.  
  35. return randogNum;
  36. }
  37.  
  38. public static void Hello(){
  39. System.out.println("I'm a dog, I'm this old: " + Dog.Age());
  40. }
  41.  
  42.  
  43. /**
  44. * making an encounterCat method,
  45. * if the cat is older the dog is scared
  46. * if the cat is younger the dog chases it
  47. */
  48. public static void encounterCat() {
  49. if (Dog.Age() < Cat.Age())
  50. System.out.println("Dog says: 'Jesus... ok, fine, yes I'm leaving you bitchy cat'");
  51. else
  52. System.out.println("Dog says: 'I'm gonna get you you tasty kitten'");
  53.  
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement