import java.util.Scanner;
public class RandomNumber {
public static long money = 1000000; // set as the default amount of 10 million won
static int num1; //number 1
static int num2; //number 2
static int num3; //number 3
static int myumber1, mynumber2, mynumber3=0; // the lotto number I expect
static int choose = 0; // select
static int putMoney = 0; // money put in
static int setMoney = 0; // copper for bet
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
System.out.println("------------------------------------------------------");
System.out.println ("|1. View my current balance|2. Start Lotto|3. Add More Amount|4. Exit|");
System.out.println("------------------------------------------------------");
choose = sc.nextInt();
//If the balance becomes 0 won, notify after the program ends
for(int i=0; i<100; i++){
if(choose ==1){
ShowMoney();
choose = sc.nextInt();
} } else if (choose == 2){
StartLotto();
choose = sc.nextInt();
} } else if (choose == 3){
PutMoney();
choose = sc.nextInt();
} } else if (choose == 4){
EndLotto();
break;
} else { System.out.println ("Please choose between 1 and 4";}
}
}
private static void ShowMoney() {
System.out.println ("Your current balance is "" + Money + "won";"");
// // TODO Auto-generated method stub
System.out.println("------------------------------------------------------");
System.out.println ("|1. View my current balance|2. Start Lotto|3. Add More Amount|4. Exit|");
System.out.println("------------------------------------------------------");
}
private static void StartLotto() {
// // TODO Auto-generated method stub
String opening; // Comments on whether to do it again or exit
System.out.println ("Start Lotto").");
System.out.print("Please enter 3 of your numbers" (1-10): ");
mynumber1 = sc.nextInt();
mynumber2 = sc.nextInt();
mynumber3 = sc.nextInt();
System.out.print("Please enter the amount you want to bet on :");
setMoney = sc.nextInt();
num1 = (int) (Math.random()*10+1); //random value
num2 = (int) (Math.random()*10+1); //random value
num3 = (int) (Math.random()*10+1); //random value
System.out.print(num1 + " ");
System.out.print(num2 + " ");
System.out.print(num3 + " ");
If (num1 == mynumber1 &&& num2 == mynumber2 && num3 == mynumber3){ // when all three numbers are equal
System.out.println ("You won the bet!!) I'll give you double the amount you called!");
Money = setMoney*setMoney; //2x
} } else {
System.out.println();
System.out.println ("You lost the bet.") Your money is mine.");
Money -= setMoney;
System.out.print("Do you want to try again? (Y/N): ");
opnion = sc.nextLine(); //Enter Request
if(opnion == "Y"){
System.out.println ("The program will restart.")");
//Re-run StartLotto
} } else if (opnion =="N"){
//Return to original run window
System.out.println("------------------------------------------------------");
System.out.println ("|1. View my current balance|2. Start Lotto|3. Add More Amount|4. Exit|");
System.out.println("------------------------------------------------------");
}
}
}
private static void PutMoney() {
// // TODO Auto-generated method stub
System.out.println ("Please enter the amount you want to put into your account." 2The maximum unit is 100,000 won at a time.";
putMoney = sc.nextInt();
if(putMoney > 100000) {
System.out.println ("Enter less than 100,000 won");
PutMoney();
} } else if (putMoney < 0) {
System.out.println ("You can make a deposit from KRW 0 or more";
PutMoney();
}
else {
Money += putMoney;
System.out.println(putMoney + "Won has been deposited.");
System.out.println("------------------------------------------------------");
System.out.println ("|1. View my current balance|2. Start Lotto|3. Add More Amount|4. Exit|");
System.out.println("------------------------------------------------------");
}
}
private static void EndLotto() {
// // TODO Auto-generated method stub
System.out.println ("Lotto Program Ended"");
System.out.println ("Your current balance is " + Money + "won")
}
}
**The part where you receive the option and process it doesn't work continuously, but if you enter Y, Lotto will again
It repeats, and when N is entered, I try to go back to the original selection, but there is no error in the code, but when I run it, a debugging error occurs. Help me.**
When you receive an option and compare it, try using equality instead of ==~
© 2024 OneMinuteCode. All rights reserved.