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 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 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
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...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list...
Write a Java program (single file/class) whose filename must be Numbers.java. The program reads a list of integers from use input and has the following methods: 1. min - Finds the smallest integer in the list. 2. max- Finds the largest integer in the list. 3. average - Computes the average of all the numbers. 4. main - method prompts the user for the inputs and ends when the user enter Q or q and then neatly outputs the entire...
Write a program to remove extra blanks from text files. Your program should replace any string...
Write a program to remove extra blanks from text files. Your program should replace any string of two or more blanks with one single blank. It should work as follows: * Create a temporary file. * Copy from the input file to the temporary file, but do not copy extra blanks. * Copy the contents of the temporary file back into the original file. * Remove the temporary file. Your temporary file must have a different name than any existing...
Java program Create a public method named saveData for a class named Signal that will hold...
Java program Create a public method named saveData for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp...
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT