Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the following...

90.2K

Verified Solution

Question

Programming

Create a program RandomFile.java that generates files with random numbers/characters.

You arerequired to write the following three methods in the classRandomFile:

​publicstatic void randomBinaryFile(StringfileName,int length)

​publicstatic void randomNumberFile(StringfileName,intlength)

​publicstatic void randomCharFile(StringfileName,int length)

The parameter “fileName”specifies the file name, and “length” specifies the length of thesequence in the file.

● randomBinaryFile will generatea file containing a sequence of 0 or 1 of the specifiedlength;
● randomNumberFile will generatea file containing a sequence of digits 0, 1, 2, …, 9 of thespecified length;
● randomCharFile will generatea file containing a sequence of characters A, B, C, …, Z of thespecified length;

Also write a main()method to test your code. In the main()method, you may ask the user to type in a file name, a type ofrandomness (binary, digit or character), and the length of thefile.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The following code generates a random character between A andZ:

​​Randomr = new Random();​​

​​chara = (char) (r.nextInt(26)+ 'A');

Another way is as below:

Random r = new Random();​​

String alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";

char a = alphabet.charAt(r.nextInt(26));

Answer & Explanation Solved by verified expert
4.0 Ratings (532 Votes)
Here is the completed code for this problem Comments are included go through it learn how things work and let me know if you have any doubts or if you need anything to change If you are satisfied with the solution please rate the answer Thanks RandomFilejava import javaioFile import javaioFileNotFoundException import javaioPrintWriter import javautilRandom import javautilScanner public class RandomFile method to generate a file containing random binary values public static void randomBinaryFileString    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students