The file must be called Proper coding conventions required t

The file must be called <LastInitialFirstInitialUnit5.java>
Proper coding conventions required the first letter of the class start with a capital
letter and the first letter of each additional word start with a capital letter.
Only submit the .java file needed to make the program run. Do not submit the .class
file or any other file.
5%
Style Components
Include properly formatted prologue, comments, indenting, and other style elements
as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892.
5%
Topics covered in chapter
Topics with * are covered in this assignment. Ensure you use every item listed below with
an * in your completed assignment.
*The API Library
*Match Class
*Wrapper Classes for Primitive Types
Character Class
*String Methods
*Formatted Output with the printf Method
*Problem Solving with Random Numbers
LiFiUnit5.java - Main Method
• Get input for maximum random number into a String variable. Allow a
maximum of 8 (see example).
• Use the Integer wrapper class to parse the integer out of the string and store
in an integer variable.
• Get input for number of rounds into an integer. Allow a maximum of 8 (see
example).
• Create a Header and Data format string to output results as shown in the
sample at the bottom.
• Utilizing a for loop, output results meeting following criteria:
o One line should be output for each round.Each line should contain:
§ Round Number.
§ Random number chosen.
§ The random number raised to the round number.
• Utilize Math class to calculate using exponents.
• Example: Round 2 random number 6 = 62 = 36
§ The modulus of the random number % round.
• Modulus returns the remainder, see page 81 in Chapter 3.
• Example: 8%3 = 2 (2 is the remainder or modulus)
§ The random number divided by the round number.
• Ensure you output the result as a float with 2 decimal
places.
• Output “End Run…” after all lines have been output.
Mimic the output in the sample below exactly.
Numbers will change due to random
and selection but format will be the same.
Sample output is provided below. Be sure to mimic the layout exactly. Output will
vary based on input.

Solution

import java.util.Scanner;
class LiFiU5
{
public static void main(String args[])
{
Scanner userInput = new Scanner(System.in);
Integer maxrand, round;
int i,ranum;
while(true)
{
System.out.println(\"Enter the maximum allowed random number (Max 8 digits)\");
String smaxrand = userInput.next();
if(smaxrand.length()<=8)
{
maxrand = Integer.valueOf(smaxrand);
break;
}
else
{
   System.out.println(\"Maximum allowed digits is 8\");
}
}
while(true)
{
System.out.println(\"Enter the number of rounds (Max 8 digits)\");
String sround = userInput.next();
if(sround.length()<=8)
{
round = Integer.valueOf(sround);
break;
}
else
{
   System.out.println(\"Maximum allowed digits is 8\");
}
}
for(i=1;i<=round;i++)
{
ranum = (int)(Math.random()*maxrand);
System.out.println(\"Round Number \"+i);
System.out.println(\"Power of Random Number \"+ranum+\" = \"+ranum+\"^\"+i+\" = \"+Math.pow(ranum,i));
System.out.println(\"Modulus of Random Number \"+ranum+\" = \"+ranum+\"%\"+i+\" = \"+(ranum%i));
}
}
}

The file must be called <LastInitialFirstInitialUnit5.java> Proper coding conventions required the first letter of the class start with a capital letter a
The file must be called <LastInitialFirstInitialUnit5.java> Proper coding conventions required the first letter of the class start with a capital letter a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site