Question

In: Computer Science

Write a computer program for a logic bomb that continually generates 8-digit numbers randomly and increases...

  1. Write a computer program for a logic bomb that continually generates 8-digit numbers randomly and increases a counter by one each time. If the random number meets the current date in a format mmddyyyy, it will display 6 times on screen the following message:

Today is [date]!

The count is: [nnnn]

Hint: Since everyday is a different date, don’t hard code the date in your program. And the [nnnn] should be the number from your counter.

Solutions

Expert Solution

1).ANSWER:

GIVEN BELOW:

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class GenerateRandom {

public static void main(String[] args)throws Exception {
DateFormat dateFormat = new SimpleDateFormat("MMddyyyy");//declaring the date format
Date date = new Date();//creating an object for the date
int s = Integer.parseInt(dateFormat.format(date));//converting the date from string to int
int num = 0;//initializing num
int count =0;//initializing count
Random generator = new Random();//creating an object for random class
//generator.setSeed(System.currentTimeMillis());
do{ //do while loop to iterate the loop until date equals to random number
num = generator.nextInt(9999999) + 9999999; //generating 8 digit random number
count ++;//incrementing the count
}while(s != num); //checking random number is equal to date or not
if(s == num){//if date equals to random number then
for(int i = 0;i<5; i++){ //iterate for loop to print the message 5 times
System.out.println("Today date is "+num);//display date
System.out.println("The count is "+count);//display count
System.out.println("\n");//assign one line space
}
}
}
}

output:


Related Solutions

Write a program in C++ that generates and displays the first N three digit odd numbers....
Write a program in C++ that generates and displays the first N three digit odd numbers. Whereas the number N is provided by the user.
Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
Suppose that a computer program randomly generates an 8-letter string from the letters A,B,C,D,E. For example,...
Suppose that a computer program randomly generates an 8-letter string from the letters A,B,C,D,E. For example, the program might generate the string CCCCCCCC or DAAEDCBB. The letter in each of the 8 positions is chosen independently of the other positions, and each of the five letters is chosen with equal likelihood. What is the probability that the string contains at least one A or at least one B?
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
You will write a program that prompts the user to enter a 7-digit phone numbers, and...
You will write a program that prompts the user to enter a 7-digit phone numbers, and finds the 3- and 4-letter words that map to the phone number, according to the restrictions outlined earlier. A sample run: unixlab% java MapNumbers Enter name of dictionary file: words10683 Enter a test word (3 letters): cat Test word maps to 228 Enter telephone number (7 digits, no 0's or 1's, negative to quit): 2282273 Options for first 3 digits: act cat bat Options...
Write a C++ program that asks the user to enter a series of single-digit numbers with...
Write a C++ program that asks the user to enter a series of single-digit numbers with nothing separating them. Read the input as a C-string or a string object. The program should display the sum of all the single-digit numbers in the string. For example, if the user enters 2514, the program should display 12, which is the sum of 2, 5, 1, and 4. The program should also display the highest and lowest digits in the string. It is...
Write a program that randomly generates 100 dates and store them into a vector. Use the...
Write a program that randomly generates 100 dates and store them into a vector. Use the Date.h provided . The dates generated must be within 1000 days after 1/1/2000. and Sort the 100 dates generated in ascending order. date.h #ifndef DATE_H_ #define DATE_H_ #include #include using namespace std; class Date {    friend ostream &operator<<( ostream &, const Date & ); private:    int day;    int month;    int year; static const int days[]; // array of days per...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
Write a Java program with comments that randomly generates an array of 500,000 integers between 0...
Write a Java program with comments that randomly generates an array of 500,000 integers between 0 and 499,999, and then prompts the user for a search key value. Estimate the execution time of invoking the linearSearch method in Listing A below. Sort the array and estimate the execution time of invoking the binarySearch method in Listing B below. You can use the following code template to obtain the execution time: long startTime = System.currentTimeMillis(); perform the task; long endTime =...
Write a program that generates all prime numbers between 2 and 1000, using the Sieve of...
Write a program that generates all prime numbers between 2 and 1000, using the Sieve of Eratosthenes method. You can find many articles that describe the method for finding primes in this manner on the Internet. Display all the prime values. This program should be in assembly language.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT