-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessgame.java
More file actions
47 lines (43 loc) · 1.45 KB
/
Copy pathguessgame.java
File metadata and controls
47 lines (43 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package guessgame;
import java.util.Random;
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
*
* @author sbozen
*/
public class GuessGame {
public static void main(String[] args) {
Random rnd=new Random();
int generatedNumber=rnd.nextInt(89)+10;
int tenner,unity;
unity=generatedNumber%10;
tenner=(generatedNumber-unity)/10;
//System.out.println(generatedNumber);
int reverseNumber =unity*10+tenner;
int estimatedNumber=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the estimated number "));
if(estimatedNumber<100 && estimatedNumber>9){
int unityEstimated=estimatedNumber%10;
int tennerEstimated=(estimatedNumber-unityEstimated)/10;
if(estimatedNumber==generatedNumber)
{
JOptionPane.showMessageDialog(null,"Great! You won $ 10.000" );
}
else if(estimatedNumber==reverseNumber){
JOptionPane.showMessageDialog(null,"Great! You won $ 3.000" );
}
else if(unity==unityEstimated ||unity==tennerEstimated || tenner==unityEstimated || tenner==tennerEstimated){
JOptionPane.showMessageDialog(null,"Great! You won $ 1.000" );
}
else
JOptionPane.showMessageDialog(null,"Sorry! You lost");}
else{
JOptionPane.showMessageDialog(null,"You have not entered a two-digit number");
}
}
}