Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @(#)proj1.java
- *
- * proj1 application
- *
- * @author
- * @version 1.00 2011/11/20
- */
- import java.util.Scanner;
- public class proj1 {
- public static void main(String[] args) {
- char c;
- boolean flag=true;
- int index = 1,guessCounter;
- char[] answerStr;
- int length = 0;
- Scanner sc = new Scanner(System.in);
- // set array of sentences
- String[] sentences={
- "make love not war",
- "you can only go as far as you push",
- "actions speak louder than words"
- ,"some people make the world special just by being in it",
- "everything is okay in the end. if it's not okay, then it's not the end",
- "i'm going to make him an offer he can't refuse",
- "toto I've got a feeling we're not in kansas anymore",
- "may the force be with you",
- "e.t. phone home",
- "there's no place like home",
- "you can't handle the truth",
- "i'll be back",
- "i see dead people",
- "houston, we have a problem",
- "keep your friends close, but your enemies closer"};
- /***************** bonus loop ********************************************/
- /***************** chooce a random index(2) ******************************/
- index=(int) (Math.random())*15;
- /***************** prepare the chosen sentence(3) ************************/
- //replaces the chosen sentence in answerStr
- guessCounter=0;
- length = sentences[index].length();
- char[ ] codedStr = new char [length];
- answerStr = sentences[index].toCharArray();
- //preparing codedStr
- for (int i=0;i<length;i++){
- if ((answerStr[i]>='a') && (answerStr[i]<='z'))
- codedStr[i]='_';
- else
- codedStr[i]=answerStr[i];
- }
- /*************** main loop(4) ********************************************/
- while(flag){
- System.out.println("Please enter your guess");
- c=sc.nextLine().toCharArray()[0];
- //check if the c appears in answerStr
- for (int i=0;i<length;i++){
- //if yes, then update codedStr
- if (c==answerStr[i])
- codedStr[i]=c;
- }
- //checks if all letters were discovered
- //print if the guess was false/right
- //check if the user lost
- }//end while
- //will be showen at the end of game.
- }//main
- }//class
Add Comment
Please, Sign In to add comment