how For the next step, you will append a hyphen and then a random integer To det
ID: 670140 • Letter: H
Question
how For the next step, you will append a hyphen and then a random integer To determine the random integer fin t take the first two digits o f the zip code, and then generate a random integer between I and that number inclusive For this problem you may assume that none o f the zip codes starting with "00" are entered For full credit, format this number to always take two decimal places even if the number generated is less than ten Be careful to test your code fully to ensure that your random number generation is working correctly In your output reporting on the processing you should include the maximum value being used within the random number generation Two sample interactions are shown Enter your first name: than Enter your rip code:15301Explanation / Answer
If the code is being written in JAVA, the random generation is simple. Extract the first two digits of the pin code using a while loop. Construct your new two digit number using the extracted digits. You can either extract digits to an array or save them to a new variable. We make use of the rand() method to get the max of the random numbers generated. Here is how you can make use of the random method in your code and then compare those random numbers generated to extract the max value using a counter variable.
To use rand() you first need to import the above package and then you can add a method specifying the range of the random number generation.
Basically every time the function is called when provided to a max and a min range it returns a random number. So in your case the min is always fixed as 01 and max is formed using the first two digits of the zip code.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.