Question

In: Computer Science

Write program#2 upload .java file. 2A) Write a java program that uses the Random class to...

Write program#2 upload .java file.

2A) Write a java program that uses the Random class to generate a number in the range 21 to 64.  Print the generated number.

2B) Using the Random class and nextInt(6), rolls two die generating two random numbers each in the range 1 through 6. Total by adding the two values together. Print the value of each die, and the total value.

2C) Using the Math class and sqrt(num), calculate the square root of integer twenty-two divided by integer seven, print the result formated to ten decimal places. Hint: the result of the division needs data conversion to support a double.

<END>

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Question 2A :

//import package
import java.util.Random;
//Java class
public class RandomNumber {
   //entry point of the program ,main() method
   public static void main(String[] args) {
       //creating object of Random class
       Random random=new Random();
       //generate random number between 21 to 64
       int randomNumber=random.nextInt(64 - 21 + 1) + 21;
       //print the random number
       System.out.println("Random number between 21 to 64 :"+randomNumber);
   }

}

================

Output Screen :RandomNumber.java

****************************

Question 2B:

DieRoll.java :


//import package
import java.util.Random;

//Java class
public class DieRoll {
   // entry point of the program ,main() method
   public static void main(String[] args) {
       // creating object of Random class
       Random random = new Random();
       // generate random numbers
       int randomNumber1 = random.nextInt(6 - 1 + 1) + 1;
       int randomNumber2 = random.nextInt(6 - 1 + 1) + 1;
       // add value
       int totalValue = randomNumber1 + randomNumber2;
       // print random numbers
       System.out.println("Value for die 1:" + randomNumber1);
       System.out.println("Value for die 2:" + randomNumber2);
       // print total value
       System.out.println("Total Value :" + totalValue);
   }

}
=======================

Screen output :DieRoll.java

********************************

Question 2C:

squareRoot.java :

//Java class
public class squareRoot {
//Entry point of the class , main method
   public static void main(String[] args) {
       //calculate square root
       double num=Math.sqrt(22/7);
       //print square root of a number
       System.out.printf("Square Root of 22/7 is : %.10f", num);
   }

}
====================

Output :squareRoot.java

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Write program#2 upload .java file. 2A) Write a java program that uses the Random class to...
Write program#2 upload .java file. 2A) Write a java program that uses the Random class to generate a number in the range 21 to 64.  Print the generated number. 2B) Using the Random class and nextInt(6), rolls two die generating two random numbers each in the range 1 through 6. Total by adding the two values together. Print the value of each die, and the total value. 2C) Using the Math class and sqrt(num), calculate the square root of integer twenty-two...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write a java program: Write a program that creates a text file. Write to the file...
Write a java program: Write a program that creates a text file. Write to the file three lines each line having a person's name. In the same program Append to the file one line of  'Kean University'.  In the same program then Read the file and print the four lines without lines between.
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in...
Write a Java program that uses the file EnglishWordList.txt which contains a collection of words in English (dictionary), to find the number of misspelled words in a story file called Alcott-little-261.txt. Please note that the dictionary words are all lower-cased and there are no punctuation symbols or numbers. Hence it is important that you eliminate anything other than a-z and A-Z and then lower case story words for valid comparisons against the WordList file. When you read each line of...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire...
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
Write a Java program such that it consists of 2 classes: 1. a class that serves...
Write a Java program such that it consists of 2 classes: 1. a class that serves as the driver (contains main()) 2. a class that contains multiple private methods that compute and display a. area of a triangle (need base and height) b area of a circle (use named constant for PI) (need radius) c. area of rectangle (width and length) d. area of a square (side) e. surface area of a solid cylinder (height and radius of base) N.B....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT