Write a program that calls methods for each of the following mini problems from its main method. Us a single Scanner for the program declared in the class as private Static Scanner keyboard = new Scanner(System.in); Write a method that reads a one-line sentence as input and then displays the following response: If the sentence ends with a question mark (?) and the input contains an even number of characters, display the word Yes. If the sentence ends with a question mark and the input contains an odd number of characters, display the word No. If the sentence ends with an exclamation point (!), display the word Wow. In all other cases, display the words You always say followed by the input string enclosed in quotes. Your output should all be on one line. Be sure to note that in the last case, your output must include quotation marks around the echoed input string. In all other cases, there are no quotes in the output. Your program does not have to check the input to see that the user has entered a legitimate sentence. Notes: This code requires a three-way selection statement and gives more practice with string methods.  The case statement can be used since the control expression is a single character.  It may be instructive to show the code using if/else, instead, and compare them for readability.   Write a method that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400. Notes: This project provides an opportunity to introduce format checking.  The solution uses case logic in combination

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter8: Advanced Method Concepts
Section: Chapter Questions
Problem 9E
icon
Related questions
Question

Write a program that calls methods for each of the following mini problems from its main method.

Us a single Scanner for the program declared in the class as
private Static Scanner keyboard = new Scanner(System.in);

  1. Write a method that reads a one-line sentence as input and then displays the following response: If the sentence ends with a question mark (?) and the input contains an even number of characters, display the word Yes. If the sentence ends with a question mark and the input contains an odd number of characters, display the word No. If the sentence ends with an exclamation point (!), display the word Wow. In all other cases, display the words You always say followed by the input string enclosed in quotes. Your output should all be on one line. Be sure to note that in the last case, your output must include quotation marks around the echoed input string. In all other cases, there are no quotes in the output. Your program does not have to check the input to see that the user has entered a legitimate sentence.

    Notes: This code requires a three-way selection statement and gives more practice with string methods.  The case statement can be used since the control expression is a single character.  It may be instructive to show the code using if/else, instead, and compare them for readability.  

  2. Write a method that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400.

    Notes: This project provides an opportunity to introduce format checking.  The solution uses case logic in combination with compound Boolean expressions.

Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,