Question

In: Computer Science

***Using Java Using the switch/case construct, write a program that takes a character from the user...

***Using Java

Using the switch/case construct, write a program that takes a character from the user and classifies it as a number (‘1’,’2’, ‘3’, …), a letter from the alphabet (‘A’, ‘a’, ‘B’, ‘b’, …, ‘Z’, ‘z’), an arithmetic operator (‘+’, ‘-‘, ‘/’, ‘*’, ‘%’), a comparison operator (‘<’, ‘>’, ‘=’), punctuation (‘!’, ‘?’, ‘,’, ‘,’, ‘:’, ‘;’), and all other characters as a Special Character, and informs the user of the same.

If the user entered the character A, the system should say: “You entered a letter!”

If the user entered the character (, the system should say: “You entered a special character!”

Solutions

Expert Solution

//CharacterClassifier.java
import java.util.Scanner;
public class CharacterClassifier {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a character: ");
        char ch = scanner.next().charAt(0);
        switch (ch){
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                System.out.println("You entered a number!");
                break;
            case 'A':
            case 'B':
            case 'C':
            case 'D':
            case 'E':
            case 'F':
            case 'G':
            case 'H':
            case 'I':
            case 'J':
            case 'K':
            case 'L':
            case 'M':
            case 'N':
            case 'O':
            case 'P':
            case 'Q':
            case 'R':
            case 'S':
            case 'T':
            case 'U':
            case 'V':
            case 'W':
            case 'X':
            case 'Y':
            case 'Z':
            case 'a':
            case 'b':
            case 'c':
            case 'd':
            case 'e':
            case 'f':
            case 'g':
            case 'h':
            case 'i':
            case 'j':
            case 'k':
            case 'l':
            case 'm':
            case 'n':
            case 'o':
            case 'p':
            case 'q':
            case 'r':
            case 's':
            case 't':
            case 'u':
            case 'v':
            case 'w':
            case 'x':
            case 'y':
            case 'z':
                System.out.println("You entered a letter!");
                break;
            case '+':
            case '/':
            case '*':
            case '%':
                System.out.println("You entered an arithmetic operator!");
                break;
            case '<':
            case '>':
            case '=':
                System.out.println("You entered a comparison operator!");
                break;
            case '!':
            case '?':
            case ',':
            case ':':
            case ';':
                System.out.println("You entered a punctuation !");
                break;
            default:
                System.out.println("You entered a special character!");
        }
    }
}


Related Solutions

Using c# , Write a program using a switch statement that takes one character value from...
Using c# , Write a program using a switch statement that takes one character value from the user and checks whether the entered value is an arithmetic operator (+, -, * , /) If not the program display a message that it not of the operators ( (+, -, * , /) .
Write a Java program that takes an array of 10 "Int" values from the user and...
Write a Java program that takes an array of 10 "Int" values from the user and determines if all the values are distinct or not. Return TRUE if all the values of the array are distinct and FALSE if otherwise.
8. write a program using switch-case statements that ask a user to enter a temperature value...
8. write a program using switch-case statements that ask a user to enter a temperature value in degrees Fahrenheit (In your program, use an integer to record the user’s entry. If the temperature falls between 0 and 96 make it print “Temperature below normal”. If the temperature is 97, 98, make it “Temperature normal”. If the temperature is between 100 and 150, print “You have a fever”. If the temperature is outside the ranges given above, display “Are you human”....
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
write a java program that takes three numbers from the user and print the greatest number...
write a java program that takes three numbers from the user and print the greatest number (using if-statement). sample output: input the first number:35 input the second number:28 input the third number:87 the greatest number:87
Write a program using switch statement that asks user to enter the month number and then...
Write a program using switch statement that asks user to enter the month number and then it prints out the number of days for that month. For simplicity reasons have your program print 28 days for February no matter if it is a leap year or not. Your program should also handle any invalid month numbers that user could enter (hint use default for the switch). Use a while loop to allow user to test for different month entries till...
Write a program that will print out “W” using a character that a user provides. use...
Write a program that will print out “W” using a character that a user provides. use for loop statement. in java please
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter...
Write a program using the switch statement to calculate geometric quantities. Prompt the user to enter a radius. Then present a menu of choices for quantities to be calculated from that radius:                         A         Area of a Circle                         C         Circumference of a Circle                         S          Surface Area of a Sphere                         V         Volume of a Sphere Prompt the user to enter the character corresponding to the quantity to be calculated. Use a switch statement to handle the calculations. Use...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT