Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Carson Ricketts
- public class Program {
- public static void main(String[] args) {
- // age and name of animals
- int age;
- String name;
- Animal phil, gene, rob;
- // New animal Phil the duck
- age = 17;
- name = "phil";
- phil = new Animal();
- phil.type = "duck";
- phil.color = "yellow";
- phil.feet = 2;
- phil.canFly = true;
- phil.message = "quack";
- phil.speak();
- // New animal Gene the wombat
- age = 12;
- name = "gene";
- gene = new Animal();
- gene.type = "wombat";
- gene.color = "grey";
- gene.feet = 4;
- gene.canFly = false;
- gene.message = "squeal";
- gene.speak();
- // New animal rob the snake
- age = 3;
- name = "rob";
- rob = new Animal();
- rob.type = "snake";
- rob.color = "green";
- rob.feet = 0;
- rob.canFly = false;
- rob.message = "hisss";
- rob.speak();
- }
- }
- // Code to make program run
- class Animal{
- String type;
- String color;
- int feet;
- boolean canFly;
- String message;
- public void speak() {
- System.out.println(message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement