java
Create a method that will be used to test an IQ. This method will receive only a String and a Random object when called, and return an int. In this method you will: create a new Scanner object, say hi to the user by name, get 2 random numbers between 0 and 49, and ask the user what the sum of the 2 numbers is. If the user is correct say "Great Job!", and then assign IQ the value of 100 plus the sum of the 2 numbers. If the user is incorrect, say "No, the answer was...", display the answer, and assign IQ the value of 10 plus the sum of the 2 numbers. Return IQ.
Code:

Output:
Raw Code:
import java.util.*;
public class IQ{ // class
public static int test_iq(String name,Random randobj){
// method with a String and a Random object as parameters
Scanner input = new
Scanner(System.in); // creating a new Scanner object,
System.out.println("hi " + name);
// say hi to the user by name
// getting two Random numbers
between 0 and 49 (inclusive)
int r1 = randobj.nextInt(49);
int r2 = randobj.nextInt(49);
System.out.print("Enter the sum
of two numbers: ");
int sum = input.nextInt(); //
taking the sum of the 2 numbers from user
int IQ;
if (sum == r1+r2){ // If the user
input is correct than print "Great Job!", and assign IQ the value
of 100 + the sum of the 2 numbers.
System.out.println("Great Job!");
IQ = 100 + (r1 +
r2);
}
else{ // otherwise print "No, the
answer was " + sum, and assign IQ the value of 10 + the sum of the
2 numbers
System.out.println("No, the answer was " + (r1 + r2));
IQ = 10 + (r1 +
r2);
}
return IQ; // return IQ
}
public static void main(String[] args) {
String Name = "Henry"; // Name
variable with value Henry
Random random = new Random(); //
creating random object
System.out.println("IQ : " +
test_iq(Name,random)); // calling test_i method and printing the
return value.
}
}
If you have any doubts feel free to comment in comment section.
DO VOTE(LIKE).
java Create a method that will be used to test an IQ. This method will receive...
Java 7) Create a method that will be used to test an IQ. This method will receive only a String and a Random object when called, and return an int. In this method you will: create a new Scanner object, say hi to the user by name, get 2 random numbers between 0 and 49, and ask the user what the sum of the 2 numbers is. If the user is correct say "Great Job!", and then assign IQ the...
3. Write a Java method (called sumOfSquares) that reads in a sequence of integer numbers using a Scanner object. As each integer is read, the method displays that integer. The method also accumulates the sum of the squares of the integers and displays the sum when all integers are read. The method reads integers until a negative integer is read. The negative integer should not be display or added to the sum of squares. The method will not return a...
Create a function without using import scanner and you must create and use a java method in this assignment | x+2 x<= 2 f(x) = | | -x^2 +2x +2 x>2 Name the function f Ask the user to enter a double, calculate and display the resulting value of f(x) +5 pts: loop the ask-and-calculate-and-display loop Your main program should: Get a number (x) Use f to calculate a value of the function Display the result (optional) loop back and...
Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...
This is for a java program public class Calculation { public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object //Task 1. Write your code here //Print the prompt and ask the user to enter an...
Please include comments in java Create a command line program that can be used for computer inventory purposes Create a super class that will store the following data: CPU speed Amount of RAM Hard Disk size Operating System Allow the user to enter data using any units of measurement they desire (i.e. - 500GB or 1TB for hard disk size). Create a class that inherits from the previous class and stores information for a Windows based computer. Store the following...
Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...
I need this in java please Create an automobile class that will be used by a dealership as a vehicle inventory program. The following attributes should be present in your automobile class: private string make private string model private string color private int year private int mileage. Your program should have appropriate methods such as: default constructor parameterized constructor add a new vehicle method list vehicle information (return string array) remove a vehicle method update vehicle attributes method. All methods...