In: Computer Science
You will write a single class named WordsXX- replace the XX's with your initials.
The program will have 2 overloaded methods named wordMaker. They will have to be declared as static. Both methods will not have a return type but they will print some text.
The first method wordMaker signature will not accept any parameters and when invoked will simply print out the line "lower case words".
The second overloaded wordMaker method will accept an integer and print "Words in UPPER CASE" . The method will print the phrase as many times as the parameter indicates with each new iteration printed on a new line.
Write a main method that prompts users to enter either the word
"lower" or "upper". (Make sure you allow for all varieties of
capitalization.)
If they enter "upper" then generate a random number from 3-9 and call wordMaker to print the upper case phrase that many times.
If they enter "lower" it will use the other version of the method.
Part 2
1a. Write a program that randomly generates an integer between 0 AND 50 inclusive. The program should then prompt the user to enter a number until the user input number matches the randomly generated number. For each user input the program tells the user if the number that is input by the user is too high or too low, so the user can make the next guess intelligently. Repeat until match is found
1b. Once the the number is guessed print on the screen whether the number is odd or even.
(Hint to generate Random numbers)
import java.util.Random;
Random rand = new Random();
int n = rand.nextInt(50) + 1;
Please this is urgent do please Java
CODE:
package com.company; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; //class class WordsXX{ //static overloaded methods public static void wordMaker(){ System.out.println("lower case words"); } //passed an int n public static void wordMaker(int n){ //prints the sentence n times for(int i=0;i<n;i++) System.out.println("Words in UPPER CASE"); } } //main driver class class Main { //main method public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //asking the user to make an input System.out.println("Enter lower or upper: "); String choice = in.readLine(); //calling the class function as per the user entry if(choice.equalsIgnoreCase("upper")){ //asking the value of n System.out.println("Enter the value of n"); int n = Integer.parseInt(in.readLine()); //calling the function WordsXX.wordMaker(n); }else if(choice.equalsIgnoreCase("lower")){ //calling the function WordsXX.wordMaker(); }else{ System.out.println("Invalid choice!"); } } }
OUTPUT:
_____________________________________________________
PART 2:
CODE:
package com.company; import java.io.*; import java.util.Random; //main driver class class Main { //main method public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //generating the random number Random random = new Random(); int n = random.nextInt(50) + 1; while(true){ //asking the user to guess the number System.out.println("Guess the number: "); int guess = Integer.parseInt(in.readLine()); //if the user entered greater or lesser than n the appropriate message is displayed if(guess < n) System.out.println("Number you entered is lesser than the number!"); else if(guess > n) System.out.println("Number you entered is greater than the number!"); else { //if the number guessed is right System.out.println("Number you entered is right!"); //displaying whether the number is even or odd if(guess %2 == 0) System.out.println("The number guessed is even"); else System.out.println("The number guessed is odd"); break; } } } }
______________________________________
CODE IMAGES:
__________________________________________________
OUTPUT:
________________________________________
Feel free to ask any questions in the comments section
Thank You!