Question
*Help print these questions using JOptionPane instead of Scanner 1) import java.util.Random; import java.util.Arrays; import java.util.Scanner; public class lottery { public static String getlotteryticket1() {
*Help print these questions using JOptionPane instead of Scanner
1)
import java.util.Random;
import java.util.Arrays;
import java.util.Scanner;
public class lottery
{
public static String getlotteryticket1()
{
String lotteryTicket1 = " ";
// create random number generator
Random lotteryNumbers1 = new Random();
// 5 lotto number
int [] ticket1 = new int[5];
for( int count = 0; count < ticket1.length; ++count )
{
ticket1[count] = (1 + lotteryNumbers1.nextInt(47) );
}
Arrays.sort( ticket1 );
//add the element
for(int count = 0; count < ticket1.length; ++count )
{
lotteryTicket1 += ticket1[count];
lotteryTicket1 += " ";
}
//ticket
lotteryTicket1 += "value: ";
lotteryTicket1 += (1 + lotteryNumbers1.nextInt(27) );
lotteryTicket1 += " ";
return lotteryTicket1;
}
public static void main( String [] args )
{
int numberOfTickets1;
Scanner input = new Scanner( System.in );
System.out.print( "generate tickets " );
numberOfTickets1 = input.nextInt();
// display the ticket
for( int count = 1; count <= numberOfTickets1; ++count)
{
System.out.printf( "LOTTERY TICKET %d:", count );
System.out.print( getlotteryticket1() );
}
System.out.print( " done" );
}
}
2)
import java.util.Scanner;
public class GuessGame { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String color; String favColor = "pink"; while(true) { System.out.print("What is your favorite color? or press 'Q' to quit the game : "); color = sc.nextLine(); //reads input from user if(color.equalsIgnoreCase("Q")) //if user presses 'Q' the loop will breaks break;
if(color.equalsIgnoreCase(favColor)) //if the user input color is equivalent to favColor then { System.out.println("Your guess is correct"); break; //loop will break } else System.out.println("Your guess is wrong"); //else it will keep on looping until guess is correct } } }
3)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started