Question

Create a class called Play that has an InputReader as an instance variable. Be sure to...

Create a class called Play that has an InputReader as an instance variable. Be sure to initialize it in the constructor. The class has two methods. Write a method with this signature:

Write a method with this signature:

public void stringPlay()

The method prompts the user for a string, reads it in, and then displays the string as many times as the length of that string. The output string should be formatted with the first letter uppercase and the rest lowercase. For example:

If the user enters jAvA

The result will be Java Java Java Java

Write a method with this signature:

public void getMultiplicationTable()

This method will use a while loop to ask the user to enter two integer numbers between 1 and 10, the while loop will stop if the numbers provided by the user were in the specified range otherwise, an error message will be printed and the user will be asked to enter another two numbers. The first number given by the user will be incremented by one then used as the rows number and the second one will be incremented by 1 and used as the column number of a two dimensional array. The method will calculate the multiplication table and store it in the array and then display it. Example if the user entered 5, 7 your code should create an int array with 6 rows and 8 columns and then creates and load the array with the multiplication table. The printed result should be like so:

0 0 0 0 0 0 0 0

0 1 2 3 4 5 6 7

0 2 4 6 8 10 12 14

0 3 6 9 12 15 18 21

0 4 8 12 16 20 24 28

0 5 10 15 20 25 30 35

Create a main method: public static void main(String[] args)

In the method create an object of class Play and then call the methods stringPlay () and getMultiplicationTable()

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

Let me know for any help with any other questions.

Thank You !

===========================================================================

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Play {

    private BufferedReader reader;

    public Play() {
        reader =
                new BufferedReader(new InputStreamReader(System.in));
    }

    public void stringPlay() {
        System.out.print("Enter a string: ");
        try {
            String word = reader.readLine();
            for (int times = 1; times <= word.length(); times++) {
                word = word.toLowerCase();
                System.out.println(word.substring(0, 1).toUpperCase() + word.substring(1));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void getMultiplicationTable() {

        int first = 1, second = 1;

        try {
            System.out.print("Enter the first number (1-10) : ");
            first = Integer.parseInt(reader.readLine());
            System.out.print("Enter the second number (1-10) : ");
            second = Integer.parseInt(reader.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        }
        while (1 <= first && first <= 10 && 1 <= second && second <= 10) {

            int tables[][] = new int[first + 1][second + 1];
            for (int row = 0; row < tables.length; row++) {
                for (int col = 0; col < tables[row].length; col++) {
                    tables[row][col] = row * col;
                }
            }

            for (int row = 0; row < tables.length; row++) {
                for (int col = 0; col < tables[row].length; col++) {
                    System.out.printf("%4d",tables[row][col]);
                }
                System.out.println();
            }

            try {
                System.out.print("Enter the first number (1-10) : ");
                first = Integer.parseInt(reader.readLine());
                System.out.print("Enter the second number (1-10) : ");
                second = Integer.parseInt(reader.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        System.out.println("Error : value(s) out of range.");

    }

    public static void main(String[] args) {

        Play play = new Play();
        play.stringPlay();
        play.getMultiplicationTable();
    }
}

=================================================================

Play.java x new DUITETEUREAUET (new InputSLIEGUREAUET (Pystem. I 1: Project Run: + → IR public void stringPlay () { System.ou

Add a comment
Know the answer?
Add Answer to:
Create a class called Play that has an InputReader as an instance variable. Be sure to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • Create a class called Reverse that reverses an array of integers. The class should have two...

    Create a class called Reverse that reverses an array of integers. The class should have two method: - public static void reverse(int [] array) – Which calls the private recursive method, passing the array parameter and which two array elements should be swapped. - private static void reverseRecursive(int [] array, int startIndex, int endIndex) – Which swaps the two elements of the array parameter pointed to by the startIndex and endIndex parameters. The method should be called again, this time,...

  • Create a class Circle with one instance variable of type double called radius. Then define an...

    Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...

  • Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredi...

    Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredients (an array of up to 10 ingredients, such as ham, capicola, American cheese, lettuce, tomato) -condiments (an array of up to 5 condiments, such as mayonnaise, oil, vinegar and mustard) Create a two argument constructor Write the getters and setters for the instance variables Override the toString method using the...

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • 5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create...

    5.4 Java Create a program that generates SuperLotto lottery numbers. Create a class called SuperLottoPlus.java Create a method called generateSuperLottoNumbers() that returns an array of 6 random SuperLotto lottery numbers. The first 5 numbers must be from the range 1 to 47 The 6th number (the MEGA) must be from 1 to 27. Create a method called printTicket() that takes an integer array as an parameter it will loop through the integer array and print out the data Display the...

  • Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this...

    Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this class in future exercises to fully build out a Tic Tac Toe game! The TicTacToe class should have a 2D array as an instance variable and a constructor that initializes the 2D array with the "-" value. Add a getter method that returns the private 2D instance variable. public class TicTacToeTester { //You don't need to alter any of the code in this class!...

  • JAVA help Create a class Individual, which has: Instance variables for name and phone number of...

    JAVA help Create a class Individual, which has: Instance variables for name and phone number of individual. Add required constructors, accessor, mutator, toString() , and equals method. Use array to implement a simple phone book , by making an array of objects that stores the name and corresponding phone number. The program should allow searching in phone book for a record based on name, and displaying the record if the record is found. An appropriate message should be displayed if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT