1String[] available_cards = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Queen", "King", "Jack", "Ace"};
2java.util.Random random = new java.util.Random();
3int random_computer_card = random.nextInt(available_cards.length);
4System.out.println(available_cards[random_computer_card]);
1// Import all the libraries
2import javax.swing.*;
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Random;
6
7// Declare the Class
8public class Hello
9{
10 // Declare the Main Function
11 public static void main(String[] args)
12 {
13 // Declare a List (Be sure to include java.util.ArrayList; and java.util.List;)
14 List<String> l = new ArrayList<>();
15 l.add("Quote of the Day \r\nIf you find it in your heart to care for somebody else, you will have succeeded. \r\nReopen the program for another quote.");
16 l.add("Love Quote of the Day \r\nIf there's delight in love, 'Tis when I see that heart, which others bleed for, bleed for me. \r\nReopen the program for another quote.");
17 l.add("Art Quote of the Day \r\nArt is the stored honey of the human soul, gathered on wings of misery and travail. \r\nReopen the program for another quote.");
18 l.add("Nature Quote of the Day \r\nThe earth has received the embrace of the sun and we shall see the results of that love. \r\nReopen the program for another quote.");
19 l.add("Funny Quote Of the Day \r\nThe first condition of understanding a foreign country is to smell it. \r\nReopen the program for another quote.");
20 l.add("Quote of the Day \r\nAnger cannot be dishonest. \r\nReopen the program for another quote.");
21 l.add("Love Quote of the Day \r\nLove is when he gives you a piece of your soul, that you never knew was missing. \r\nReopen the program for another quote.");
22 l.add("Art Quote of the Day \r\nIt is only an auctioneer who can equally and impartially admire all schools of art. \r\nReopen the program for another quote.");
23 l.add("Nature Quote of the Day \r\nNature reserves the right to inflict upon her children the most terrifying jests. \r\nReopen the program for another quote.");
24 l.add("Funny Quote Of the Day \r\nMarriage is not just spiritual communion, it is also remembering to take out the trash. \r\nReopen the program for another quote.");
25
26
27 // Object name should be same as class
28 Hello obj = new Hello();
29 // Display the input dialog box from JOptionPane
30 String inputValue = JOptionPane.showInputDialog("Please enter your name: ");
31 // Declare Random object (Be sure to include java.util.Random;)
32 Random rand = new Random();
33 // Get Random Index from the List
34 int randomIndex = rand.nextInt(l.size());
35 // Get the element on the random index in the list
36 String randomElement = l.get(randomIndex);
37 //Display the output dialog box from JOptionPane to display the random element
38 JOptionPane.showMessageDialog(null, randomElement + "\r\n\r\nHave a nice day " + inputValue + "!");
39 }
40
41}
42
1List<Foo> list = createItSomehow();
2Collections.shuffle(list);
3Foo foo = list.get(0);