Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cs.bennington.edu;
- import java.util.Random;
- // Bringin' in random numbahs
- /**
- * First hw assignment, problem 2
- * Creating Cat and Dog classes with all sorts of instances
- * Running through the Main class!
- * Created by rkarlinsky on 2/28/15.
- * @ authored by Roi
- */
- // Creating a Dog class
- public class Dog {
- /**
- * generating a random number between 1 and 14, i.e. dog 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, dog declares its age
- public static int Age() {
- int randogNum = randInt(1, 14);
- return randogNum;
- }
- public static void Hello(){
- System.out.println("I'm a dog, I'm this old: " + Dog.Age());
- }
- /**
- * making an encounterCat method,
- * if the cat is older the dog is scared
- * if the cat is younger the dog chases it
- */
- public static void encounterCat() {
- if (Dog.Age() < Cat.Age())
- System.out.println("Dog says: 'Jesus... ok, fine, yes I'm leaving you bitchy cat'");
- else
- System.out.println("Dog says: 'I'm gonna get you you tasty kitten'");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement