Question
Use the following to complete the question ArrayList, where E means a reference type for its items 1. Add a new package named hw2p2 to
Use the following to complete the question ArrayList, where E means a reference type for its items
1. Add a new package named hw2p2 to the project. a. Right click the package and add a new class named Operator without a main() method. b. Add another class named Launcher with a main() method. You will see Launcher.java in the Package Explorer, too.
2. Add a new text file called numbers2.txt containing numbers from 1 to 10 (i.e., 1 2 3 4 5 6 7 8 9 10) on a single line. For the choice of encoding, see Problem #1.
3. Write a non-static method called createArrayList() for the Operator class. The method should do the following: a. Store these stringsadd, subtract, multiply, divide, remainder, greaterthan, lessthan, max, min, and powerto an ArrayList. b. Read each number from the numbers2.txt and add it to an ArrayList. Consider Double.parseDouble(string s) method.
4. Write another non-static method named showOperations() for the Operator class. This method should do the following: a. Generate two random integers between 0 and 9 using the Math.randon() method (see here) and use them to get two of the 10 numbers stored in an array list of type ArrayList created in the previous method. b. Generates a random integer between 0 and 9 using the Random class' nextInt() method (see here) and use it to get one of the string values stored in an array list of type ArrayList in the previous method. The strings correspond to Java operators: add to +, subtract to -, multiply to *, divide to /, remainder to %, greaterthan to >, lessthan to <, max to Math.max(double a, double b), min to Math.min(double a, double b), and power to Math.pow(double a, double b) c. Now use the two numbers and the operator to show the operation results. For example, if the two numbers selected from an array list of type ArrayList are 4 and 5, and the operator selected from an array list of type ArralyList is +, then the output will be:
4 + 5 = 9.0 // if the operator is +
4 / 5 = 0.8 // if the operator is /
4 * 5 = 20.0 // if the operator is *
4 - 5 = -1.0 // if the operator is
4 > 5 = false // if the operator is >
4 < 5 = true // if the operator is <
4 % 5 = 0 // if the operator is %
Math.pow(4, 5) = 1024 // if the method is Math.pow()
Math.max(4, 5) = 5 // if the method is Math.max()
Math.min (4, 5) = 4 // if the method is Math.pow()
5. Write code for the main() method for the Launcher class to run the program.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started