Course: Java Lab class: 201352 Name: Ellis No.: 20135210
Score: Instructor: Lou Jia Peng Experimental Date: 15.06.03
Experiment level: Preview degree: Experiment time:
Instrument Group: Compulsory/Elective: Elective experiment number: 3
Experiment Name: java guessing digital game development
(Jing Mengxin, Ellis Group)
First, the purpose and requirements of the experiment:
By writing Java Application System Comprehensive example-guessing the number game, summarizing, reviewing and practicing the object-oriented programming idea and programming method, and mastering the Java language programming skills by writing programs, integrating the learning knowledge, improving the ability of debugging program, developing good programming habit, and enhance the design of the overall thinking of the grasp.
Second, equipment and environment
Hardware: Macbookair
Software: JDK 1.8.0; Eclipse
Iii. contents of the experiment
(1) Experimental requirements analysis:
1. The player enters a number, the range of the number is between 1-100, and the system obtains a random number.
2. To determine the size of the number entered by the player, if not the system requirements of the number, the system will prompt you, you enter not the number please re-enter, give a reminder so that the player further select.
3. When the player guesses the system to give the time and the level of the game to judge, the system gives the continuation of the prompt and judgment. 4. The system automatically counts according to the number of times you guess the number.
5. Until the user guesses the number, if the message continues to guess the number, if it continues to enter the next game, exiting will exit the game system.
(2) Detailed design of function module
1. Acquisition of random numbers
Function Description: The player enters a number, the number range is between 1-100, the system obtains the random number.
2 Input/Output module
Function Description: Judge and prompt the number entered by the player. If the player does not enter a number that is not required by the system, you will be prompted to enter it without a number. If the number entered by the player is compared with the random generation number, it is smaller than the random generation number. The system prompts you, the number is too small please re-enter. If the number entered by the player is compared with the number of randomly generated numbers, it is larger than the random generation number. The system prompts you, the number is too large please re-enter.
3 Judgment Module
Function Description: The system gives the judgment of its level and whether to continue the prompt;
4 Automatic Counting module
Function Description: The system is automatically counted according to the number of times you guess the number.
5 Result Output Module
Function Description: Until the user guesses the number, whether the message continues to guess the number, if you continue to enter the next game, if exiting will exit the game system.
(3) The code looks like this:
Code:
Import java.util.InputMismatchException;
Import Java.util.Scanner;
Public class Main {
public static void Main (string[] args) {
//Generate a random number
int number = (int) (Math.random () * +) + 1;
//Join Count
int count = 0;
//Add the maximum value, and the minimum value here
int max = +;
int min = 1;
While (true) {
//Keypad input data
Scanner sc = new Scanner (System. in);
System. out.println ("Welcome to the" Guess Number Game ");
System. out.println ("Please enter your guess number: (" + min + "~" + Max + " )");
try {
count++;
int guessnumber = sc.nextint ();
//judgment
if (guessnumber > number ) {
max = guessnumber;
System. Out.println ("big guess");
}
Else if (guessnumber < number ) {
min = guessnumber;
System. Out.println ("guess small");
}
Else {
System. Out.println ("Congratulations, only use the" + count + "time to guess! ");
//ask if you want to continue
System. Out.println ("Would you like to continue?") (yes) ");
sc = new Scanner (System. in);
String str = sc.nextline ();
if ("yes". Equals (str)) {
//Override assigned random number
Number = (int) (Math.random () * +) + 1;
count = 0;
max = +;
min = 1;
}
else {
Break ;
}
}
}
catch (inputmismatchexception e) {
System. Out.println ("The data you entered is incorrect");
}
}
}
}
(3). Game Run Results
Iv. Experimental Results and analysis
Through this comprehensive Java experiment, I have a systematic understanding of Java.
Java language is now one of the most popular programming languages, it has object-oriented, platform-independent, secure, multi-threaded and other characteristics. In this experiment, the editing interface was simple, practical, and easy to modify, using the Eclipse integrated development environment. In the writing program began to encounter a lot of problems, such as: input, output exception thrown, etc., through the Internet to find data have been resolved. Through the compilation of comprehensive experiments, has aroused my great interest in the Java language, in the future learning process to further the Java system, a comprehensive understanding and mastery. I will try to learn Java better.
Experiment three Java guessing digital game development