Guest User

Untitled

a guest
Apr 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. /**
  2. * @(#)proj1.java
  3. *
  4. * proj1 application
  5. *
  6. * @author
  7. * @version 1.00 2011/11/20
  8. */
  9.  
  10. import java.util.Scanner;
  11. public class proj1 {
  12.  
  13. public static void main(String[] args) {
  14. char c;
  15. boolean flag=true;
  16. int index = 1,guessCounter;
  17. char[] answerStr;
  18. int length = 0;
  19. Scanner sc = new Scanner(System.in);
  20.  
  21.  
  22.  
  23. // set array of sentences
  24. String[] sentences={
  25. "make love not war",
  26. "you can only go as far as you push",
  27. "actions speak louder than words"
  28. ,"some people make the world special just by being in it",
  29. "everything is okay in the end. if it's not okay, then it's not the end",
  30. "i'm going to make him an offer he can't refuse",
  31. "toto I've got a feeling we're not in kansas anymore",
  32. "may the force be with you",
  33. "e.t. phone home",
  34. "there's no place like home",
  35. "you can't handle the truth",
  36. "i'll be back",
  37. "i see dead people",
  38. "houston, we have a problem",
  39. "keep your friends close, but your enemies closer"};
  40.  
  41.  
  42. /***************** bonus loop ********************************************/
  43.  
  44. /***************** chooce a random index(2) ******************************/
  45.  
  46. index=(int) (Math.random())*15;
  47.  
  48. /***************** prepare the chosen sentence(3) ************************/
  49.  
  50.  
  51. //replaces the chosen sentence in answerStr
  52. guessCounter=0;
  53. length = sentences[index].length();
  54. char[ ] codedStr = new char [length];
  55. answerStr = sentences[index].toCharArray();
  56.  
  57. //preparing codedStr
  58. for (int i=0;i<length;i++){
  59. if ((answerStr[i]>='a') && (answerStr[i]<='z'))
  60. codedStr[i]='_';
  61. else
  62. codedStr[i]=answerStr[i];
  63. }
  64. /*************** main loop(4) ********************************************/
  65. while(flag){
  66.  
  67. System.out.println("Please enter your guess");
  68. c=sc.nextLine().toCharArray()[0];
  69. //check if the c appears in answerStr
  70. for (int i=0;i<length;i++){
  71. //if yes, then update codedStr
  72. if (c==answerStr[i])
  73. codedStr[i]=c;
  74. }
  75. //checks if all letters were discovered
  76.  
  77. //print if the guess was false/right
  78.  
  79. //check if the user lost
  80.  
  81. }//end while
  82.  
  83. //will be showen at the end of game.
  84.  
  85. }//main
  86. }//class
Add Comment
Please, Sign In to add comment