Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**Java Language only** Directions: The code below tells the user to enter 5 numbers 0-9, To see if they will match the randomly selected numbers.

**Java Language only**

Directions: The code below tells the user to enter 5 numbers 0-9, To see if they will match the randomly selected numbers. the code is Imitating the lottery. For the code below put descriptive comments on the code including an introduction of what the code does at the begining of the code. Add descritive java doc to the code and a uml diagram as well.

Also let the code be copy pastable to textpad.

Thank you I will thumbs up good work

import java.util.Arrays; import java.util.Random; import java.util.Scanner;

public class Lottery {

int[] lotteryNumbers = new int[5];

public int[] getLotteryNumbers() { return lotteryNumbers; }

Lottery() { Random randomVal = new Random(); for (int i = 0; i < lotteryNumbers.length; i++) { lotteryNumbers[i] = randomVal.nextInt((10 - 1) + 1); }

}

int compare(int[] personLottery) { int count = 0; Arrays.sort(lotteryNumbers); Arrays.sort(personLottery); for (int i = 0; i < lotteryNumbers.length; i++) { if (lotteryNumbers[i] == personLottery[i]) { count++; } }

return count; }

public static void main(String[] args) { int[] personLotteryNum = new int[5]; int matchNum; Lottery lnum = new Lottery(); Scanner input = new Scanner(System.in);

System.out.println("Enten the five digit lottery number"); for (int i = 0; i < personLotteryNum.length; i++) { System.out.println("Enter the digit " + (i + 1) + " :"); personLotteryNum[i] = input.nextInt(); }

matchNum = lnum.compare(personLotteryNum); if (matchNum == 5) System.out.println("YOU WIN!!"); else System.out.println(" YOU LOSS!!");

System.out.println("Computer Generated Lottery Number :"); System.out.print("|"); for (int i = 0; i < lnum.getLotteryNumbers().length; i++) { System.out.print(lnum.getLotteryNumbers()[i] + "|"); } System.out.println(" Lottery Number Of user:"); System.out.print("|"); for (int i = 0; i < personLotteryNum.length; i++) { System.out.print(personLotteryNum[i] + "|"); } System.out.println();

System.out.println("Number Of digit matched: " + matchNum);

}

}

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

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

=+What is the extent of the use of each type of IE?

Answered: 1 week ago