Advertisement
fosterbl

Pet.java - Mostly complete from Friday

Feb 10th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. /**
  2. Create a class that keeps track of the attributes above for pet records at the animal clinic. Decide what instance variables are needed and their data types. Make sure you use int, double, and String data types. Make the instance variables private. The attributes are:
  3. name, age, weight, type (dog, cat, lizard, etc.), breed
  4.  
  5. Create 2 constructors, one with no parameters (default constructor) and one with many parameters to initialize all the instance variables.
  6.  
  7. Create Accessor (get) methods for each of the instance variables.
  8.  
  9. Create a toString() method that returns all the information in a pet record.
  10.  
  11. */
  12. public class Pet{
  13.    // complete class definition
  14.    private String name, type, breed;
  15.    private int age;
  16.    private double weight;
  17.    
  18.    public Pet(){
  19.       name = "";
  20.       type = "";
  21.       breed = "";
  22.       age = 0;
  23.       weight = 0.0;
  24.    }
  25.    
  26.    public Pet(String n, String t, String b, int a, double w){
  27.       name = n;
  28.       type = t;
  29.       breed = b;
  30.       age = a;
  31.       weight = w;
  32.    }
  33.    
  34.    //accessors/getters
  35.    public String getName(){
  36.       return name;
  37.    }
  38.    
  39.    public String getType(){
  40.       return type;
  41.    }
  42.    
  43.    public String getBreed(){
  44.       return breed;
  45.    }
  46.    
  47.    public int getAge(){
  48.       return age;
  49.    }
  50.    
  51.    public double getWeight(){
  52.       return weight;
  53.    }
  54.    
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement