This document provides instructions for a demo question that will guess a user's name based on input and utilize various Java concepts like switch/case statements and loops. It includes 14 steps to comment the program, declare constants, get user input, use a switch/case to output names based on the first letter, print a message with the guessed name, get the length of the first word, and use a loop to get an awesome count within a minimum and maximum range.
1. CS 115 DEMO QUESTION!
TA: Aditya Parakh
This is a demo question. Attempt this question at your own will. No extra credit is being offered for this question.!
!
Checklist before you start: !
__ Know how to comment!
__ Know how to write/define constants!
__ Know how to use Scanner to get user input!
__ Know how to use Switch/Case statement !
__ Know how to convert Strings to char (using charAt())!
__ Know how to use different types of loops !
!
!
!
!
!
Question 1: You are writing a program that will guess the name of your TA based on
inputs given. You will utilize switch/case statements along with loops in this task.!
!
1) Insert a comment at the start of the program describing what the program does!
2) Declare a constant called AWESOMEMIN and initialize it to 22!
3) Declare a constant called AWESOMEMAX and initialize it to 83!
4) Ask user for their name and store it in a String variable called “usrName”!
5) Use a switch/case statement to do the following: !
I. If the first letter of the name is ‘A’ or ‘a’: Print “Aditya Parakh”!
II. If the first letter of the name is ‘B’ or ‘b’: Print “Barney Stinson” !
III. If the first letter of the name is ‘P’ or ‘p’: Print “Parakh?”!
IV. If anything else: Print the name entered by user!
6) After the switch case. Print “Suit up” and the name guessed. Example “Suit up
Aditya Parakh” or “Suit Up Lion Tiger” !
7) Print the number of characters in the first word of the name: !
8) Use a loop to ask the user for an awesome count (double) that is !
1) Greater than AWESOMEMIN!
2) Smaller than AWESOMEMAX!
9) It should look like this “What is your awesome count?:”!
10) TESTING FOR DOUBLE!
1) Check to make sure the user has entered a double.!
2) If the user fails to enter a double (enters a string or int):!
1) Print “Enter a double:”!
2) Scan the user input and store it in a String variable of Garbage.!
11) Assuming user has entered a double. If the double entered is less than
AWESOMEMIN: Print “AWESOME COUNT TOO LOW. PLEASE ENTER NUM
BIGGER THAN” and put in the AWESOMEMIN count after that. !
12) If the double entered is bigger than AWESOMEMAX. Print “AWESOME COUNT
TOO HIGH. PLEASE ENTER NUM SMALLER THAN” and put in AWESOMEMAX
count after that. !
13) If the num entered is between AWESOMEMIN AND AWESOMEMAX. Print “The
amount of awesomeness is” and then display AWESOMEMAX. !