Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by nfswo on 25-Mar-17.
- */
- public class VeterinaryReport {
- private int numberOfDogs;
- private int numberOfCats;
- public VeterinaryReport(int numberOfDogs, int numberOfCats){
- this.numberOfDogs = numberOfDogs;
- this.numberOfCats = numberOfCats;
- }
- public VeterinaryReport(int numberOfBoth){
- this.numberOfCats = numberOfBoth / 2;
- this.numberOfDogs = numberOfBoth / 2;
- }
- public void addDogs(int additionalDogs){
- this.numberOfDogs += additionalDogs;
- }
- public void addCats(int additionalCats){
- this.numberOfCats += additionalCats;
- }
- public void showReport(){
- System.out.println(this.numberOfDogs + " dogs\n" + this.numberOfCats + " cats");
- }
- public static void main(String[] args){
- VeterinaryReport vr = new VeterinaryReport(12, 13);
- VeterinaryReport vr2 = new VeterinaryReport(24);
- vr.addCats(3);
- vr.addDogs(4);
- vr.showReport(); // shows 16 and 16
- vr2.addCats(5);
- vr2.showReport(); // shows 12 and 17
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement