Difference between revisions of "Telgar/Problem311"

From Exalted - Unofficial Wiki
Jump to: navigation, search
m (link fix)
m
(One intermediate revision by one other user not shown)
Line 1: Line 1:
public class Collection
+
import java.util.*;
 +
 
 +
public class Problem311
 
{
 
{
     public Collection()
+
    int guess;
 +
    int enigma;
 +
    int counter;
 +
    char response;
 +
 
 +
     public Problem311()
 
     {
 
     {
        [[ArrayList]] CDC = new [[ArrayList]]();
 
 
     }
 
     }
 
      
 
      
    public void addCD()
+
    public void Random()
 +
    {}
 +
   
 +
    public void genNum()
 +
    {
 +
        Random gen = new Random();
 +
        enigma = gen.nextInt(100) +1;
 +
    }
 +
   
 +
    public void enterNum()
 
     {
 
     {
        int ye;
+
         System.out.print ("The game has started! Please enter your guess: ");
        int id;
+
         guess = Keyboard.readInt();
        String ti;
+
         counter = 0;
        String ar;
 
        String ge;   
 
       
 
         System.out.println ("Enter year of purchase");
 
         ye = Keyboard.readInt();
 
         System.out.println ("Enter title of CD");
 
        ti = Keyboard.readString();
 
        System.out.println ("Enter arist");
 
        ar = Keyboard.readString();
 
        System.out.println ("Enter genre");
 
        ge = Keyboard.readString();
 
        System.out.println ("Enter ID number");
 
        id = Keyboard.readInt();
 
        Collection.addCD();
 
 
     }
 
     }
 +
   
 +
    public void guessAgain()
 +
    {
 +
        System.out.print ("Enter your new guess:");
 +
        guess = Keyboard.readInt();
 +
        counter ++;
 +
        guessNum();
 +
    }
 +
   
 +
    public void checkPlaying()
 +
    {
 +
        System.out.println ("Do you want to play again? Y/N?");
 +
        response = Keyboard.readChar();
 +
        if (response == 'Y')
 +
            {
 +
                guessAgain();
 +
            }
 +
        else
 +
            {
 +
                System.out.println ("Thanks for playing!");
 +
            }
 +
               
 +
    }
 +
   
 +
    public void guessNum()
 +
        {
 +
            if (guess > enigma)
 +
            {
 +
                System.out.println ("You have guessed high.");
 +
                checkPlaying();
 +
            }
 +
            else if (guess < enigma)
 +
            {
 +
                System.out.println ("You have guessed low.");
 +
                checkPlaying();
 +
            }
 +
            else if (guess == enigma)
 +
            {
 +
                System.out.println ("You guessed right! You took "+ counter +" guesses. Play again? Y/N");
 +
                response = Keyboard.readChar();
 +
                if (response == 'Y')
 +
                {
 +
                    genNum();
 +
                    enterNum();
 +
                    guessNum();
 +
                }
 +
                else
 +
                {
 +
                    System.out.print ("Thanks for playing!");
 +
                }
 +
            }
 +
        }
 +
 +
    public void main()
 +
    {
 +
        Problem311 game = new Problem311();
 +
       
 +
        game.genNum();
 +
        game.enterNum();
 +
        game.guessNum();
 +
    }
 
}
 
}

Revision as of 17:20, 17 November 2004

import java.util.*;

public class Problem311 {

   int guess;
   int enigma;
   int counter;
   char response;
   public Problem311()
   {
   }
   
   public void Random()
   {}
   
   public void genNum()
   {
       Random gen = new Random();
       enigma = gen.nextInt(100) +1;
   }
   
   public void enterNum()
   {
       System.out.print ("The game has started! Please enter your guess: ");
       guess = Keyboard.readInt();
       counter = 0;  
   }
   
   public void guessAgain()
   {
       System.out.print ("Enter your new guess:");
       guess = Keyboard.readInt();
       counter ++;
       guessNum();
   }
   
   public void checkPlaying()
   {
       System.out.println ("Do you want to play again? Y/N?");
       response = Keyboard.readChar();
       if (response == 'Y')
           {
               guessAgain();
           }
       else
           {
               System.out.println ("Thanks for playing!");
           }
               
   }
   
   public void guessNum()
       {
           if (guess > enigma)
           {
                System.out.println ("You have guessed high.");
                checkPlaying();
           }
           else if (guess < enigma)
           {
                System.out.println ("You have guessed low.");
                checkPlaying();
           }
           else if (guess == enigma)
           {
               System.out.println ("You guessed right! You took "+ counter +" guesses. Play again? Y/N");
               response = Keyboard.readChar();
               if (response == 'Y')
               {
                   genNum();
                   enterNum();
                   guessNum();
               }
               else
               {
                   System.out.print ("Thanks for playing!");
               }
           }
       }

    public void main()
    {
        Problem311 game = new Problem311();
        
        game.genNum();
        game.enterNum();
        game.guessNum();
    }

}