Results 1 to 3 of 3
  1. #1
    tenhotshot is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Exclamation Help with linking classes please

    I am a noob at java so dont look at me funny. this is a tester for a "gaming center". i have written one of the classes for it which would be the high low game here is the code for the menu(tester):

    Java Code:
    import java.util.Scanner;
    import java.util.Random;
    /**
     * Main Menu for all games.
     * 
     * @author (Dylan Harlow) 
     * @version (12/9/10)
     */
    public class GameTester
    {
        public static void main(String[] args)
        {
            //start assignments
            boolean begginer = false;
            boolean menu = false;
            boolean correctNum = false;
            boolean rightGame = false;
            boolean isInt2 = false;
            boolean startHighLow = true;
            String playans;
            int op = 0;
            highLow game1 = new highLow();
            
            Scanner begin = new Scanner(System.in);
            Scanner menu2 = new Scanner(System.in);
            
            System.out.println("Would you like to play a game?");
            while(!begginer)
              {
                playans = begin.nextLine();
                if (playans.equalsIgnoreCase("sure") || playans.equalsIgnoreCase("yes") || playans.equalsIgnoreCase("ya") || playans.equalsIgnoreCase("love to") || playans.equalsIgnoreCase("i'd love to") ||  playans.equalsIgnoreCase("yes ") || playans.equalsIgnoreCase("love to") || playans.equalsIgnoreCase("ok") || playans.equalsIgnoreCase("yeah") ||
                playans.equalsIgnoreCase("id love to") || playans.equalsIgnoreCase("uh huh") || playans.equalsIgnoreCase("absolutely") || playans.equalsIgnoreCase("of course") || playans.equalsIgnoreCase("course") || playans.equalsIgnoreCase("obviously") || playans.equalsIgnoreCase("yep") ||  playans.equalsIgnoreCase("yup") ||  playans.equalsIgnoreCase("course"))
                {
                    begginer = true;
                }
                else if (playans.equalsIgnoreCase("no") || playans.equalsIgnoreCase("no thanks") || playans.equalsIgnoreCase("nope") || playans.equalsIgnoreCase("no thank you"))
                {
                   System.out.println("Your loss. Program Terminated.");
                   menu = true;
                   correctNum = true;
                   begginer = true;
                }
                else
                {
                    System.out.println("Come on now... enter something that resembles a yes or no.");
                }
            }
            while(!menu)
            {
                while(!rightGame)
                {
                    System.out.println("Which game would you like to play?");
                    System.out.println("[1] High Low");
                    System.out.println("[2] Tic Tac Toe");
                    System.out.println("[3] Yahtzee");
                    System.out.println("[4] Connect 4");
                    System.out.println("[5] High Card");
                    System.out.println("");
                    System.out.println("Type 0 to quit");
                    rightGame = true;
                }
                isInt2 = false;
    
               while (!isInt2)
        
               try 
               {
                   op = menu2.nextInt();
                   isInt2 = true;
                } 
                catch (Exception a) 
                {
                    System.out.println("Please enter the number of the game you wish to play in digit form or 0 to quit. ");
                    menu2.nextLine();
                }
                if (op == 1)
                {
                    menu = true;
                    startHighLow = false;
                }
                else if (op > 1 && op < 6)
                {
                    System.out.println("Sorry this game is under constrction please choose another.");
                }
                else if (op == 0)
                {
                    menu = true;
                    correctNum = true;
                    begginer = true;
                    System.out.println("Thanks for Playing! Goodbye.");
                }
                else
                {
                    System.out.println("Please enter the number of the game you want to play in digit form.");
                }
            }
            }
        }


    And here is the HIGH LOW game:

    Java Code:
    import java.util.Random;
    import java.util.Scanner;
    
    public class highLow extends GameTester
    {
        public static void main(String[] args) 
        {
            //start assignments
            //ints
            final int MAX = 100;
            final int MIN = 1;
            int highNum = 100;
            int highNum2 =100;
            int lowNum = 1;
            int lowNum2 = 1;
            int answer = 0; 
            int selected = 0;
            int guessCount = 0;
            //Strings
            String choice;
            String q;
            String play;
            //booleans
           
            boolean correctNum = false;
            boolean rightNum = false;
            boolean isInt = false;
            
            boolean yn = false;
            //inputs
            Scanner in = new Scanner(System.in);
            Scanner sense = new Scanner(System.in);
            Scanner quit = new Scanner(System.in);
            Random gen = new Random();
            answer = gen.nextInt(MAX) + 1;
            //end assignments
              
    
        //Start of HIGH LOW
            while (!correctNum ) 
            {
                 isInt = false;
             while(!rightNum)
             { 
                System.out.println("HIGH LOW");
                System.out.println("");
                System.out.println("I'm thinking of a number between 1 and 100. Guess what it is: ");
                rightNum = true;
            }
               while (!isInt)
               {
                   
                   try 
               {
                   selected = in.nextInt();
                   isInt = true;
                } 
                catch (Exception e) 
                {
                    System.out.println("You must enter a number from " + lowNum2 + " to " + highNum2 + " in digit form.");
                    in.next();
                }
            }
      
                        
        
                if (selected < answer)
                {
                    lowNum = selected;
                } 
                else if (selected > answer)
                {
                    highNum = selected;
                }
                if (lowNum > lowNum2)
                {
                    lowNum2 = lowNum;
                }
                if (highNum < highNum2)
                {
                    highNum2 = highNum;
                }
                
                if (selected == 0) 
                {
                    System.out.println("You quit. The number was " + answer);
                    correctNum = true;
                    rightNum = false;
                }
                else if (selected > highNum2)
                {
                    System.out.println("Please Choose a number within the range of " + lowNum2 + " to " + highNum2);
                }
                else if (selected < lowNum2)
                {
                    System.out.println("Please Choose a number within the range of " + lowNum2 + " to " + highNum2);
                }
                else
                {
                {
                    if (selected > answer) 
                {
                    System.out.println("The number is too high.");
                    System.out.println("Pick another number between " + lowNum2 + " and " + highNum2 +" (Or 0 to give up)");
                    guessCount = guessCount++;
                    guessCount = guessCount + 1;
                }
                
                if (selected < answer) 
                {
                    System.out.println("The number is too low.");
                    System.out.println("Pick a number between " + lowNum2 + " and " + highNum2 +" (Or 0 to give up)");
                    guessCount = guessCount++;
                    guessCount = guessCount + 1;
                }
        
                if (selected == answer) 
                    {
                        guessCount = guessCount++;
                        guessCount = guessCount + 1;
                        System.out.println("");
                        System.out.println("You got it!");
                        System.out.println("");
                        System.out.println("I picked " + answer);
                        System.out.println("It took you " + guessCount + " guesses to get it.");
                        System.out.println("");
                        System.out.print("Enter yes to play again or no to go back to the Main Menu: ");
                        guessCount = 0;
                        highNum = MAX;
                        highNum2 = MAX;
                        lowNum = MIN;
                        lowNum2 = MIN;
                        yn = false;
                        while(!yn)
                        {
                            choice = sense.nextLine();
                            if (choice.equalsIgnoreCase("yes") || choice.equalsIgnoreCase("y")) 
                            {  
                                correctNum = false;
                                yn = true;
                                answer = gen.nextInt(MAX) + 1;
                                System.out.println("Ok, lets play again.");
                                System.out.println("I'm thinking of another number between 1 and 100. Guess it: ");
                            } 
                            else if (choice.equalsIgnoreCase("no") || choice.equalsIgnoreCase("n"))
                            {
                                correctNum = true;
                                rightNum = false;
                                yn = true;
                            }
                            else
                            {
                                System.out.println("Please enter yes or no.");
                                yn = false;
                                answer = gen.nextInt(MAX) + 1;
                            }
                        }
                    }
                
                
            }
        }
    }
    }
    }
    All i want to do is make it so when a user inputs something in the tester the program will go to the highLow class and do everything in there. and if they want to go back to the main menu(tester) they have to option to. CAN SOMEONE PLEASE HELP??

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Java Code:
    public class One {
    	public static void main(String args[]){
    		Two two=new Two("hello");
    	}
    }
    
    class Two{
    	
    	public Two(String msg){
    		System.out.println(msg);
    	}
    }

  3. #3
    tenhotshot is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    sorry i dont really understand what making an object has to do with this....

Similar Threads

  1. Linking two classes together
    By JonniBravo in forum New To Java
    Replies: 6
    Last Post: 09-11-2010, 10:53 PM
  2. Linking constructors
    By willemien in forum New To Java
    Replies: 3
    Last Post: 05-04-2010, 11:31 PM
  3. linking to a web page
    By Juuno in forum Advanced Java
    Replies: 7
    Last Post: 05-01-2009, 02:47 PM
  4. linking 2 Jframes
    By suhaib1thariq in forum New To Java
    Replies: 9
    Last Post: 02-13-2009, 01:30 AM
  5. Linking of exe files
    By archu2friends in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-06-2008, 06:08 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •