Notes
![]() ![]() Notes - notes.io |
import java.util.Random;
public class SimpleColorBettingGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Random random = new Random();
// The list of colors
String[] colors = {"red", "green", "blue", "yellow", "white", "pink"};
String[] userColors = new String[3];
// Ask user to choose from the list of colors
System.out.println("Choose 3 colors from the following: red, green, blue, yellow, white, pink");
for (int i = 0; i < 3; i++) {
System.out.print("Enter color " + (i + 1) + ": ");
userColors[i] = scanner.next().toLowerCase();
// check inputted color
boolean validColor = false;
for (int j = 0; j < colors.length; j++) {
if (userColors[i].equals(colors[j])) {
validColor = true;
break;
}
}
// If the color is not valid, ask for the color again
if (!validColor) {
System.out.println("Invalid color! Please choose from the list.");
i--; // Re-ask for this color
}
}
// Ask the user to place a bet (maximum of 20 pesos)
int bet = 0;
while (bet < 1 || bet > 20) {
System.out.print("Place your bet (maximum of 20 pesos): ");
bet = scanner.nextInt();
if (bet < 1 || bet > 20) {
System.out.println("Invalid bet amount! Please enter a value between 1 and 20.");
}
}
// Generate 3 random colors
String[] randomColors = new String[3];
System.out.println("nRandomizing 3 colors...");
for (int i = 0; i < 3; i++) {
randomColors[i] = colors[random.nextInt(colors.length)];
System.out.println("Random Color " + (i + 1) + ": " + randomColors[i]);
}
// Compare random colors with users chosen colors
int matches = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (userColors[i].equals(randomColors[j])) {
matches++;
break; // Stop if we find a match to avoid double counting
}
}
}
// Calculate the winnings
if (matches > 0) {
int winnings = bet * 2 * matches;
System.out.println("nYou matched " + matches + " color(s).");
System.out.println("You win: " + winnings + " pesos!");
} else {
System.out.println("nNo matches. You lost your bet.");
}
scanner.close();
}
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team