Advertisement
Dido09

5.4a - Game Of Words

May 8th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameOfWords {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. String bestWord="";
  9. int bestPoints=0;
  10.  
  11. System.out.println("Моля въведете дума, въведете'END OF GAME', за да прекратите играта:");
  12. while(true) {
  13. String entry = scanner.nextLine();
  14. if(entry.equalsIgnoreCase("end of game")) {
  15. break;
  16. } else {
  17. int entrysPoints = points(entry);
  18. if(entrysPoints>bestPoints) {
  19. bestWord = entry;
  20. bestPoints = entrysPoints;
  21. }
  22. }
  23.  
  24. }
  25.  
  26. System.out.println();
  27. System.out.println("Winner is word:"+bestWord);
  28. System.out.println("Points:"+bestPoints);
  29.  
  30. }
  31.  
  32. static int points(String word) {
  33. int score=0;
  34. char[] letters = word.toCharArray();
  35.  
  36. if(Character.isUpperCase(letters[0])) {
  37. score+=15;
  38. }
  39.  
  40. for(int i=0;i<letters.length;i++) {
  41. score+=letters[i];
  42. }
  43.  
  44. if(letters[letters.length-1]=='t') {
  45. score+=20;
  46. }
  47.  
  48. if(letters.length>=10) {
  49. score+=30;
  50. }
  51.  
  52. return score;
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement