Question

In: Computer Science

Determining character type without using char methods. (epic confusion) 1. Call your class Program4A, so your...

Determining character type without using char methods. (epic confusion)

1. Call your class Program4A, so your filename will be Program4A.java. It is essential for grading purposes that everyone have the same class name.

5. Ask the user for a single character "Please enter a single character, followed by the enter/return key.

6. Read in the character and assign it to a variable of char.

7. compile and run program. Don't move on until this part is working. I have entered a temporary print statement just to make sure this is working. It should be commented out before turning in the program.

8. Use nested if-else statements to determine the character type. (Cannot use char methods like isLetter or isDigit) (Must use single quotes for char)

9. Put a printf statement after each if statement to print a sentence which states the type of character. (Required ugh)

10. After you get the earlier steps working properly for letter types (uppercase or lowercase) find the opposite case and print that. Do not use char methods.

Test userString's length in an if-else statement.

Sample run: (should look like this)

Please enter a character: 2

2 is a digit.

Please enter a character: d

d is a lowercase letter.

The uppercase of d is D.

Please enter a character: G

G is an uppercase letter.

The lowercase of G is g.

Please enter a character: $

$ is a special character.

Please enter a character: asdf

You entered more than a single character. Please rerun to try again.

Please enter a character: You did not enter anything. Please rerun to try again.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// Program4A.java

import java.util.Scanner;

public class Program4A {

   public static void main(String[] args) {
       //Declaring variables
       char ch;
       String str;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

               //Getting the input entered by the user
System.out.print("Please enter a character:");
str=sc.nextLine();
if(str.length()>1)
{
   System.out.println("You entered more than a single character. Please rerun to try again.");
   System.exit(0);
}
else if(str.isEmpty())
{
   System.out.println("You did not enter anything. Please rerun to try again.");
   System.exit(0);
}
      
ch=str.charAt(0);
  
//Checking the type of character
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
{
   System.out.printf("'%c' is a character.\n",ch);
}
else if((ch>='0' && ch<='9'))
{
   System.out.printf("'%c' is a digit.\n",ch);
}
else
{
   System.out.printf("'%c' is a special character.\n",ch);
}
  
System.out.print("Please enter a character:");
ch=sc.next(".").charAt(0);
//If the character is Upper case, converting it to Lower case
if(ch>='A' && ch<='Z')
{
   System.out.printf("'%c' is a uppercase character.\n",ch);
   System.out.printf("The lowercase of '%c' is '%c'\n",ch,ch+32);
}
else if(ch>='a' && ch<='z') //If the character is Lower case, converting it to Upper case
{
   System.out.printf("'%c' is a lowercase character.\n",ch);
   System.out.printf("The uppercase of '%c' is '%c'.\n",ch,ch-32);
}

  
   }

}
____________________________

Output#1:

Please enter a character:asdf
You entered more than a single character. Please rerun to try again.

_____________________

Output#2:

Please enter a character:
You did not enter anything. Please rerun to try again.

_____________________

Output#3:

Please enter a character:2
'2' is a digit.
Please enter a character:d
'd' is a lowercase character.
The uppercase of 'd' is 'D'.

_____________________

Output#4:

Please enter a character:G
'G' is a character.
Please enter a character:f
'f' is a lowercase character.
The uppercase of 'f' is 'F'.

_______________Could you plz rate me well.Thank You


Related Solutions

Redo Program 1 so that you have a template class, that works with a char, string,...
Redo Program 1 so that you have a template class, that works with a char, string, int, or double data type. Program 1 is below: #include <iostream> #include <string> #define CAPACITY 12 using namespace std; class queue { private: string strArray[CAPACITY]; int frontIndex, endIndex; int queueSize; public: queue() { frontIndex = endIndex = -1; queueSize = 0; } void enqueue(string); string dequeue(); int size() { return queueSize; } int front() { return frontIndex; } int end() { return endIndex; }...
Please try to type your solution for this question, so I can read it without a...
Please try to type your solution for this question, so I can read it without a problem. I truly appreciate you for typing in advance. The Question: An FBI survey shows that about 80% of all property crimes go unsolved. Suppose that in your town 3 such crimes are committed and they are each deemed independent of each other. X is the number of crimes will be solved in your town. Complete the table below for the probability mass function...
Please try to type your solution for this question, so I can read it without a...
Please try to type your solution for this question, so I can read it without a problem. I truly appreciate you for typing in advance. The Question: For some Mechanical Engineer students, data for 224 student’s GPAs in their first 4 semesters of college were compared using several predictors, namely HSM, HSS, HSE, SATM, and SATV. Here significant level α is 0.05. Then, the researcher fit a regression model and got the following results (intercept is included in the model):...
Write a Java class called CityDistances in a class file called CityDistances.java.    1. Your methods...
Write a Java class called CityDistances in a class file called CityDistances.java.    1. Your methods will make use of two text files. a. The first text file contains the names of cities. However, the first line of the file is a number specifying how many city names are contained within the file. For example, 5 Dallas Houston Austin Nacogdoches El Paso b. The second text file contains the distances between the cities in the file described above. This file...
Please, explain your answer clearly (step-by-step), so I can trace the output without using the Visual...
Please, explain your answer clearly (step-by-step), so I can trace the output without using the Visual Studio Program. Please, clearly describe how the mechanism of the loop works. The answers in bold. What is printed by the following code snippet? for (int i = 0; i < 5; i++) {    for (int j = 0; j <= i; j++)    {       cout << i << " ";    } } 0 1 2 3 4 5 0 0...
           Homework: Polynomial Using Array Description: Implement a polynomial class (1) Name your class...
           Homework: Polynomial Using Array Description: Implement a polynomial class (1) Name your class Polynomial (2) Use array of doubles to store the coefficients so that the coefficient for x^k is stored in the location [k] of the array. (3) define the following methods: a. public Polynomial()    POSTCONDITION: Creates a polynomial represents 0 b. public Polynomial(double a0)    POSTCONDITION: Creates a polynomial has a single x^0 term with coefficient a0 c. public Polynomial(Polynomial p)    POSTCONDITION: Creates...
Without using google or encyclopedia, in your own words write a definition for each: 1. Finance...
Without using google or encyclopedia, in your own words write a definition for each: 1. Finance 2. Bonds 3. Financial Assets 4. Financial Instruments 5. Securitized assets
solve the following using Siri Solutions. Verify your solution using usual methods (if possible). 1. y"...
solve the following using Siri Solutions. Verify your solution using usual methods (if possible). 1. y" - 2y' + y = 0 2. y" - 2xy' + y = 0
Will Aps replace textbooks? Using the models discussed in class, 1) construct 5 pro and 5 con arguments. 2) Based on your arguments, take a position on the question. Provide your justification.
Information Technology:Will Aps replace textbooks? Using the models discussed in class, 1) construct 5 pro and 5 con arguments. 2) Based on your arguments, take a position on the question. Provide your justification.Note: In the case you make, be sure to discuss class models – Rich/Lean, Diffusion of Innovation, Use Diffusion, Sense-Making/Information Politics; you should use contingency statements that will predict the future success or failure (revenue generation and profitability). These are “if/then” statements: for example, “If these things occur,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT