Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Problem05 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int startingPoints = Integer.parseInt(scan.nextLine());
- boolean wonWithBullseye = false;
- int moves = 0;
- while (startingPoints > 0) {
- String sector = scan.nextLine();
- moves++;
- if ("bullseye".equals(sector)) {
- wonWithBullseye = true;
- break;
- }
- int currentPoints = Integer.parseInt(scan.nextLine());
- switch (sector) {
- case "number section":
- startingPoints -= currentPoints;
- break;
- case "double ring":
- startingPoints -= currentPoints * 2;
- break;
- case "triple ring":
- startingPoints -= currentPoints * 3;
- break;
- }
- if (startingPoints < 0) {
- break;
- }
- }
- if (wonWithBullseye) {
- System.out.printf("Congratulations! You won the game with a bullseye in %d moves!", moves);
- } else if (startingPoints == 0) {
- System.out.printf("Congratulations! You won the game in %d moves!", moves);
- } else {
- System.out.printf("Sorry, you lost. Score difference: %d.", Math.abs(startingPoints));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement