Question

In: Computer Science

You will write a single class named WordsXX- replace the XX's with your initials. The program...

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

Solutions

Expert Solution

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!


Related Solutions

You will write a single class named WordsXX- replace the XX's with your initials. The program...
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...
Write a java program that has a class named Octagon that extends the class Circ and...
Write a java program that has a class named Octagon that extends the class Circ and implements Comparable (compare the object's area) and Cloneable interfaces. Assume that all the 8 sides of the octagon are of equal size. Your class Octagon, therefore, must represent an octagon inscribed into a circle of a given radius (inherited from Circle) and not introduce any new class variables. Provide constructors for clas Octagon with no parameters and with 1 parameter radius. Create a method...
Write a program (name it firstMiddleLast _yourInitials.java (yourInitials represents your initials) that will: 1. Ask the...
Write a program (name it firstMiddleLast _yourInitials.java (yourInitials represents your initials) that will: 1. Ask the user (include appropriate dialog) to enter their: first name middle name last name save each of the above as a String variable as follows: firstName middleName lastName 2. Print to the screen the number of characters in each of the names (first, middle and last) 3. Print to the screen total number of characters in all three names. Include appropriate dialog in your output....
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
Write a tester program to test the mobile class defined below. Create the class named with...
Write a tester program to test the mobile class defined below. Create the class named with your id (for example: Id12345678) with the main method. Create two mobiles M1 and M2 using the first constructor. Print the characteristics of M1 and M2. Create one mobile M3 using the second constructor. Change the id and brand of the mobile M3. Print the id of M3. Your answer should include a screenshot of the output. Otherwise, you will be marked zero for...
Write a complete java program that Define a class named sample containing: A method named division...
Write a complete java program that Define a class named sample containing: A method named division that receives two integers x and y and returns the division of the two numbers. It must handle any possible exceptions. A method named printArray that receives an array of double arr and an integer index and prints the element in the positon index. It must handle any possible exceptions. main method that recievs input from user and repeat if wrong input. Then it...
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
PYTHON Suppose you need to import a single class named GeneTools from a module named bioinformatics,...
PYTHON Suppose you need to import a single class named GeneTools from a module named bioinformatics, in Python. Which of the following represents the correct use of an import statement? import GeneTools from bioinformatics from bioinformatics import GeneTools from bioinformatics import * import GeneTools
write JAVA program have a public class named GeometricShapes that has the main() method. In the...
write JAVA program have a public class named GeometricShapes that has the main() method. In the main() method the user needs to select if he want 2D shapes or 3D shape -if user select 2D user needs to select the shape type (Square, Circle, or Triangle) after selected shape the user needs to specify whether to find the Area or the Perimeter or to find side-length (radius for the circles), accordingly the needed constructor is used. (using Polymorphism principle) -if...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique...
Assignment Write a program using turtle graphics which writes your initials, or any other three unique letters, to the display. Look to your program for lab 1 for reminders of how to use turtle graphics. Functions that must be written: def drawLetter (x, y, letterColor): Write three functions, one for three unique letters. Personally, I would write drawA, drawR, and drawS. Each function must draw that letter to the screen. The x and y values determine the upper left-hand location...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT