Guest User

EasterEggsBattle

a guest
Feb 27th, 2020
105
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class EasternEggsBattle {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int numberOfEggsPlayerOne=Integer.parseInt(scanner.nextLine());
  7.         int numberOfEggsPlayerTwo=Integer.parseInt(scanner.nextLine());
  8.         String command= scanner.nextLine();
  9.         while (!command.equals("End of battle")){
  10.             if (command.equals("one")){
  11.                 numberOfEggsPlayerTwo=numberOfEggsPlayerTwo-1;
  12.                 if (numberOfEggsPlayerTwo==0){
  13.                     System.out.printf("Player two is out of eggs. Player one has %d eggs left.",numberOfEggsPlayerOne);
  14.                 }
  15.             }
  16.             else if(command.equals("two")){
  17.                 numberOfEggsPlayerOne=numberOfEggsPlayerOne-1;
  18.                 if (numberOfEggsPlayerOne==0){
  19.                     System.out.printf("Player one is out of eggs. Player two has %d eggs left.",numberOfEggsPlayerTwo);
  20.                 }
  21.             }
  22.             command= scanner.nextLine();
  23.         }
  24.         if (numberOfEggsPlayerOne>0 && numberOfEggsPlayerTwo>0) {
  25.             System.out.printf("Player one has %d eggs left.%n", numberOfEggsPlayerOne);
  26.             System.out.printf("Player two has %d eggs left.", numberOfEggsPlayerTwo);
  27.         }
  28.     }
  29. }
RAW Paste Data