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 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.
8) When the user enters 2 (in a switch statement), back in the main method, call the method you created in #7, send the user's name and the random object you created as arguments to the method. Display the returned value as the user's IQ.
CODE:-
import java.util.*;
public class HomeworkLib {
public static void main(String[] args) {
Random rand = new Random(); // this is random class object
Scanner sc = new Scanner(System.in);
System.out.print("Enter the user name: ");
String userName = sc.next(); // taking the name input
System.out.print("Enter 2 to start the IQ game: "); // asking for user input
int n = sc.nextInt();
switch (n) {
case 2:
int reuslt = testIQ(userName, rand); // calling the method with name and random object
break;
default:
System.out.println("try again");
}
}
public static int testIQ(String userName, Random rand) {
Scanner sc1 = new Scanner(System.in); // creating the scanner object
int IQ = 0;
System.out.println("Hi! " + userName);
int a = rand.nextInt(49); // creating values between 0 to 49
int b = rand.nextInt(49);
System.out.println("What is the sum of " + a + " and " + b); //asking for sum
int sum = sc1.nextInt();
if (sum == a + b) {
System.out.println("Great Job!"); // when correct
IQ = 100 + a + b;
} else {
System.out.println("No, the answer wa " + (a + b)); // when wrong
IQ = 10 + a + b;
}
return IQ;
}
}

FOR ANY OTHER QUERY PLEASE COMMENT
Java 7) Create a method that will be used to test an IQ. This method will...
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...
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...
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...
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...
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...
C++ programming Phone Book Create a class that can be used for a Phone Book. The class should have attributes for the name and phone number. The constructor should accept a name and a phone number. You should have methods that allow the name to be retrieved, the phone number to be retrieved, and one to allow the phone number to be changed. Create a toString() method to allow the name and number to be printed. Write a program that...
// Group Names: // Date: // Program Description: // Import required packages //--> // Declare class (SwitchDoLab) //--> { // Declare the main method //--> { // Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3. //--> //--> //--> // Create an integer variable named choice to store user's option. //--> // Create a Scanner object // Create...
create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...
I Need Help with this using Java Programming
:
Class name
fname
lname
Class variable
total Number
Constructor (no arguments)
Constructor (takes two arguments, fname and lname)
One getter method to return the fname and lname
One setter method for fname and lname
Inside Main:
Create three objects with the following
names
Jill Doe
John James
Jack Smith
When creating the first object (Should
not be an anonymous object)
use the argument-less constructor
Then use the setter method to assign...
PLEASE INCLUDE COMMENTS In java Create a Java Program Add the following comments at the beginning of the file: Your name. The name of the class(es) used in the program. The core concept (found below) for this lesson. The date the program was written. Include a recursive method separate from the main method that will add together all of the even numbers between and including 1 and the value the user supplies. For instance, if the user enters 10 then...