Question

In: Computer Science

Write a driver to get a String input from keyboard and if the input string has...

Write a driver to get a String input from keyboard and if the input string has less than 10 characters, throw a StringTooShortException.

public class StringTooShortException extends Exception
{
    //-----------------------------------------------------------------
    // Sets up the exception object with a particular message.
    //-----------------------------------------------------------------
    public StringTooShortException()
    {
        super("String does not have enough characters");
    }
}

Solutions

Expert Solution

import java.util.Scanner;

class StringTooShortExceptionTest {

    public static void main(String[] args) throws StringTooShortException {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String s = in.nextLine();
        if (s.length() < 10)
            throw new StringTooShortException();
    }
}

public class StringTooShortException extends Exception {
    //-----------------------------------------------------------------
    // Sets up the exception object with a particular message.
    //-----------------------------------------------------------------
    public StringTooShortException() {
        super("String does not have enough characters");
    }
}


Related Solutions

In Python Write a function to read a Sudoku board from an input string. The input...
In Python Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5 385...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard...
in c++ QUESTION 4: Write the code to do the following: -read input from the keyboard by displaying the message on the screen to ask and read the following information: * customer ID (string) * customer name (string)                                                        * balance (float) -open output file customer .txt to write -Write to the output file customer.txt the following information:                 Customer ID – customer name – balance For example: 1561175753 - James Smith – 1255.25 -close file QUESTION 5: -create one notepad...
Write a C++ function called parse that reads one line of user input from the keyboard...
Write a C++ function called parse that reads one line of user input from the keyboard and creates an array of the strings found in the input.  Your function should be passed the array and a reference variable that is to be assigned the length of the array.  Prompt the user and read the input from within the function. For example:  If the user inputs copy this that, the resulting array would have length 3 and contain the strings “copy”, “this”, and “that”....
Fix this broken code? # Get our input from the command line import sys string =...
Fix this broken code? # Get our input from the command line import sys string = sys.argv[1] # Your code goes here if string 'Bingo' print('Missed') else: print('Hit!')
In Python, write a program to get a positive integer n from keyboard first (your program...
In Python, write a program to get a positive integer n from keyboard first (your program must be able to check the validation of n being positive), and then get n integers from keyboard and store these n integers in a list. Do some processing, and print out average of the elements in the list at end of your program. For example, suppose user enters 3 first (n = 3), which means we get another three integers from the user....
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
arms64 assembly language Write a function to read a Sudoku board from an input string. The...
arms64 assembly language Write a function to read a Sudoku board from an input string. The input string must be exactly 81 characters long (plus the terminating null that marks the end of the string) and contains digits and dots (the `.` character represents an unmarked position). The input contains all 9 rows packed together. For example, a Sudoku board that looks like this: ``` ..7 ... ... 6.4 ... ..3 ... .54 ..2 ... .4. ... 9.. ... ..5...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT