Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Why do the values in Problems 5-78, 5-79, and .5-80 differ?

Answered: 1 week ago

Question

4. Identify the supernatural aid in The Wizard of Oz.

Answered: 1 week ago

Question

identify current issues relating to equal pay in organisations

Answered: 1 week ago