Difference between revisions of "Telgar/Problem311"

From Exalted - Unofficial Wiki
Jump to: navigation, search
m
m
Line 1: Line 1:
import java.util.*;
+
public class Collection
 
 
public class Problem311
 
 
{
 
{
    int guess;
+
     public Collection()
    int enigma;
 
    int counter;
 
    char response;
 
 
 
     public Problem311()
 
 
     {
 
     {
 +
        ArrayList CDC = new ArrayList();
 
     }
 
     }
 
      
 
      
    public void Random()
+
    public void addCD()
    {}
 
   
 
    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: ");
+
        int ye;
         guess = Keyboard.readInt();
+
        int id;
         counter = 0;
+
        String ti;
 +
        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 16:46, 16 February 2005

public class Collection {

   public Collection()
   {
       ArrayList CDC = new ArrayList();
   }
   
    public void addCD()
   {
       int ye;
       int id;
       String ti;
       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();
   }

}