1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yuradex [85]
3 years ago
14

Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constr

uctor should use the Random class (from the Java API) to generate a random number in the range of 0 through 9 for each element in the array. The class should also have a method that accepts an array of five integers that represent a person’s lottery picks. The method is to compare the corresponding elements in the two arrays and return the number of digits that match. For example, the following shows the lotteryNumbers array and the user’s array with sample numbers stored in each. There are two matching digits (elements 2 and 4).
Engineering
1 answer:
Bezzdna [24]3 years ago
5 0

Answer:

Output:-

Enter the five digit lottery number

Enter the digit 1 : 23

Enter the digit 2 : 44

Enter the digit 3 : 43

Enter the digit 4 : 66

Enter the digit 5 : 33

YOU LOSS!!

Computer Generated Lottery Number :

|12|38|47|48|49|

Lottery Number Of user:

|23|33|43|44|66|

Number Of digit matched: 0

Code:-

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((50 - 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("\n\nLottery 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);

}

}

Explanation:

You might be interested in
A fair die is thrown, What is the probability gained if you are told that 4 will
Semmy [17]

Answer:

1/6

Explanation:

A dice has 6 sides, the probability of 4 appearing is 1/6.

7 0
3 years ago
Two wastewater treatment plant workers (one male and one female) are exposed to hydrogen sulfide in confined spaces in the treat
Vlada [557]

Answer:

Go to explaination for the details of the answer.

Explanation:

In order to determine the lifetime (75 years) chronic daily exposure for each individual, we have to first state the terms of our equation:

CDI = Chronic Daily Intake

C= Chemical concentration

CR= Contact Rate

EFD= Exposure Frequency and Distribution

BW= Body Weight

AT = Average Time.

Having names our variables lets create the equations that will be used to derive our answers.

Please kindly check attachment for details of the answer.

5 0
3 years ago
While discussing what affects the amount of pressure exerted by the brakes: Technician A says that the shorter the line, the mor
harina [27]

Answer:

Only Technician B is right.

Explanation:

The cylindrical braking system for a car works through the mode of pressure transmission, that is, the pressure applied to the brake pedals, is transmitted to the brake pad through the cylindrical piston.

Pressure applied on the pedal, P(pedal) = P(pad)

And the Pressure is the applied force/area for either pad or pedal. That is, P(pad) = Force(pad)/A(pad) & P(pedal) = F(pedal)/A(pedal)

If the area of piston increases, A(pad) increases and the P(pad) drops, Meaning, the pressure transmitted to the pad reduces. And for most cars, there's a pressure limit for the braking system to work.

If the A(pad) increases, P(pad) decreases and the braking force applied has to increase, to counter balance the dropping pressure and raise it.

This whole setup does not depend on the length of the braking lines; it only depends on the applied force and cross sectional Area (size) of the piston.

5 0
3 years ago
Each cout statement has a syntax error. Type the first cout statement, and press Run to observe the error message. Fix the error
saul85 [17]

Answer:

1. cout << "Num: " << songNum << endl;

2. cout << songNum << endl;

3. cout << songNum <<" songs" << endl;

Explanation:

//Full Code

#include <iostream>

using namespace std;

int main ()

{

int songNum;

songNum = 5;

cout << "Num: " << songNum << endl;

cout << songNum << endl;

cout << songNum <<" songs" << endl;

return 0;

}

1. The error in the first cout statement is that variable songnum is not declared.

C++ is a case sensitive programme language; it treats upper case and lower case characters differently.

Variable songNum was declared; not songnum.

2. Cout us used to print a Variable that has already been declared.

The error arises in int songNum in the second cout statement.

3. When printing more than one variables or values, they must be separated with <<

4 0
3 years ago
The following data were obtained when a cold-worked metal was annealed. (a) Estimate the recovery, recrystallization, and grain
Oduvanchick [21]
Sorrry needdddd pointssssss
7 0
3 years ago
Other questions:
  • If the efficiency of the boiler is 91.2 % , the overall efficiency of the turbine, which includes the Carnot efficiency and its
    5·1 answer
  • An Otto cycle engine is analyzed using the air standard method. Given the conditions at state 1, compression ratio (r), and pres
    6·1 answer
  • By efficiency, we generally mean the ratio of the desired output to the required input. That is, efficiency is a measure of what
    7·1 answer
  • A mechanical system comprises three subsystems in series with reliabilities of 98, 96, and 94 percent. What is the overall relia
    10·1 answer
  • The parts of a feature control frame are the tolerance value, the datum references, and the
    14·1 answer
  • The 5 ft wide gate ABC is hinged at C and contacts a smooth surface at A. If the specific weight of the water is 62.4 lb/ft3 , f
    8·1 answer
  • The annual average of solar photovoltaic energy in Phoenix is 6,720
    8·1 answer
  • Why is it important to follow the engineering design process before building a prototype
    13·1 answer
  • Jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
    12·2 answers
  • A motor takes 38 amperes on a 220-volt circuit. Find the horsepower output (hp) of the motor shown with an efficiency of 90%. Ex
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!