Create a program “MethodTests" which will contain a number of methods all called from the main method. 1) Method 1: - Takes 1 String parameter - Prints out "Hello" + the String argument 2) Method 2: - Requests an int and a String input from the user and stores them in local variables in main() - Create a method which takes these two values as parameters - Call a Math library method of your choice (like Math.abs(int i) or Math.exp(int i) or something else) with the int parameter value in your method and print the result of it along with the String you passed in. Example: Say int num entered by user is -10 And String str entered by user is "Fairfield" Then if you use Math.abs(num), then output would be: "10 Fairfield" 3) Method 3: - Requests two double values from the user and stores them in local variables in main() - Create a method which takes these two values as parameters - The method will use Math library functions to: o Print the square root of the 1st parameter o Print the log of the 2nd parameter o Print the value of the 1st parameter raised to the power of the 2nd parameter

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Why is my second method not executing correctly? Also, help regarding third method is appreciated.

 

 

 

 

package assignments;
import java.util.Scanner;

public class Assignment4 {

public static void main(String[] args) {

MethodTests("");


int randomNum1 = (int) (Math.random() * 100);
System.out.println("I am thinking of a number between 1 and 100. can you figure out what it is?");


Scanner input = new Scanner(System.in);
int number = input.nextInt();
System.out.println("Your guess was " + number);

if (number == randomNum1) {
System.out.println("The number I was thinking of was" + randomNum1);
System.out.println("Your guess was correct!");

} else {
System.out.println("The number I was thinking of was " + randomNum1);
System.out.println("Your number was incorrect :(");



}

String yourstring = input.nextLine();
int firstint=input.nextInt();
String stringy = input.nextLine();
MethodTests(yourstring);
MethodTests2(firstint, stringy);
//MethodTests3();




}

public static void MethodTests(String yourstring){
System.out.println("Input your string");
Scanner input = new Scanner(System.in);
yourstring = input.nextLine();

System.out.println("Hello " + yourstring);






}

public static void MethodTests2(int firstint, String stringy){
System.out.println("Enter an int");
Scanner input = new Scanner(System.in);
firstint = input.nextInt();
System.out.println("Enter a String: ");
stringy =input.nextLine();
System.out.println(" Math.abs =" + Math.abs(firstint) + stringy);


}

// public static void MethodTests3(){


//}
}

Create a program "MethodTests" which will contain a number of methods all called from the main
method.
1) Method 1:
- Takes 1 String parameter
- Prints out "Hello" + the String argument
2) Method 2:
- Requests an int and a String input from the user and stores them in local variables in
main()
- Create a method which takes these two values as parameters
- Call a Math library method of your choice (like Math.abs(int i) or Math.exp(int i) or
something else) with the int parameter value in your method and print the result of it along
with the String you passed in.
Example:
Say int num entered by user is -10
And String str entered by user is "Fairfield"
Then if you use Math.abs(num), then output would be:
"10 Fairfield"
3) Method 3:
- Requests two double values from the user and stores them in local variables in main()
- Create a method which takes these two values as parameters
- The method will use Math library functions to:
o Print the square root of the 1st parameter
o Print the log of the 2nd parameter
o Print the value of the 1st parameter raised to the power of the 2nd parameter
Transcribed Image Text:Create a program "MethodTests" which will contain a number of methods all called from the main method. 1) Method 1: - Takes 1 String parameter - Prints out "Hello" + the String argument 2) Method 2: - Requests an int and a String input from the user and stores them in local variables in main() - Create a method which takes these two values as parameters - Call a Math library method of your choice (like Math.abs(int i) or Math.exp(int i) or something else) with the int parameter value in your method and print the result of it along with the String you passed in. Example: Say int num entered by user is -10 And String str entered by user is "Fairfield" Then if you use Math.abs(num), then output would be: "10 Fairfield" 3) Method 3: - Requests two double values from the user and stores them in local variables in main() - Create a method which takes these two values as parameters - The method will use Math library functions to: o Print the square root of the 1st parameter o Print the log of the 2nd parameter o Print the value of the 1st parameter raised to the power of the 2nd parameter
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY