Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cs.bennington.edu;
- import java.util.Random;
- /**
- * Hw assignment 1 problem 2
- * Creating a Cat class, fed through Main class
- * Make it declare age, encounter dogs
- * and be snooty the way cats be
- * Created by rkarlinsky on 2/28/15.
- */
- public class Cat {
- /** generating a random number between 1 and 20, i.e. cat ages
- * props to stack overflow for showing me how to get it in a range
- */
- public static int randInt(int min, int max) {
- Random rand = new Random();
- int randomNum = rand.nextInt((max-min)+1)+1;
- return randomNum;
- }
- // making an Age method, cat declares its age
- public static int Age(){
- int randcatNum = randInt(1, 20);
- return randcatNum;
- }
- public static void Hello(){
- System.out.println("I'm a cat, I'm this old: " + Cat.Age());
- }
- /**
- * making an encounterDog method,
- * if the cat is older the dog is scared
- * if the cat is younger the dog chases it
- */
- public static void encounterDog() {
- if (Dog.Age() < Cat.Age())
- System.out.println("Cat says: 'You're beneath my dignity you filthy animal'");
- else
- System.out.println("Cat says: 'It's a huge fucking dog get away!'");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement