Advertisement
Guest User

exercise four

a guest
Feb 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ExerciseFourV3 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String command = scanner.nextLine();
  8.  
  9. int startingDistance = 5364;
  10. int days = 1;
  11. int metersClimbed = 0;
  12.  
  13. while (!command.equalsIgnoreCase("end")) {
  14. if (command.equalsIgnoreCase("Yes")){
  15. metersClimbed = Integer.parseInt(scanner.nextLine());
  16. days++;
  17. } else if (command.equalsIgnoreCase("No")){
  18. metersClimbed = Integer.parseInt(scanner.nextLine());
  19. }
  20. startingDistance += metersClimbed;
  21. if (startingDistance >= 8848) {
  22. System.out.printf("Goal reached for %d days!" , days);
  23. break;
  24. }
  25. if (days == 5) {
  26. System.out.printf("Failed!%n%d" ,startingDistance);
  27. break;
  28. }
  29. command = scanner.nextLine();
  30. if (command.equalsIgnoreCase("End")) {
  31. System.out.printf("Failed!%n%d" , startingDistance);
  32. break;
  33. }
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement