Delta_Sierra

Pet

Sep 11th, 2025
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. public class Main {
  2.   public static void main(String[] args) {
  3.     Pet myPet = new Pet();
  4.    
  5.     System.out.println("Action: Invoking move() method of the Pet object");
  6.     System.out.print("Output: ");
  7.     myPet.move();
  8.     System.out.println();
  9.    
  10.     System.out.println("Action: Invoking givecompanionship(1) method");
  11.     System.out.print("Output: ");
  12.     myPet.givecompanionship(1);
  13.     System.out.println();
  14.    
  15.     System.out.println("Action: Invoking givecompanionship(3) method (multiple repetitions)");
  16.     System.out.println("Output:");
  17.     myPet.givecompanionship(3);
  18.   }
  19. }
  20. class Pet {
  21.  
  22.   public void move() {
  23.     System.out.println("The pet has moved.");
  24.   }
  25.   public void givecompanionship(int n) {
  26.     for (int i = 0; i < n; i++) {
  27.       System.out.println("The pet is giving you companionship.");
  28.     }
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment