Results 1 to 3 of 3
Thread: Help with linking classes please
- 12-10-2010, 04:04 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
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:
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??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; } } } } } } } }
- 12-10-2010, 04:35 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
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); } }
- 12-10-2010, 04:38 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Linking two classes together
By JonniBravo in forum New To JavaReplies: 6Last Post: 09-11-2010, 10:53 PM -
Linking constructors
By willemien in forum New To JavaReplies: 3Last Post: 05-04-2010, 11:31 PM -
linking to a web page
By Juuno in forum Advanced JavaReplies: 7Last Post: 05-01-2009, 02:47 PM -
linking 2 Jframes
By suhaib1thariq in forum New To JavaReplies: 9Last Post: 02-13-2009, 01:30 AM -
Linking of exe files
By archu2friends in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-06-2008, 06:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks