Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

[CSE 007] Lab 4: Loops and Input Validation

Date Assigned: 17 Feb 2023                                           Date Due: 23 Feb 2023 @11:59pm

Objective: The purpose of this assignment is to give you practice implementing complex program flow with nested loops and selection statements.

Submission: CheckPalindrome.java

Part 1: Checking Palindromes

Description: The purpose of this activity is to give you additional practice using loops and selection statements.

Assignment: A palindrome is a word or a phrase that is the same when read both     forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is either a String or an integer (in range 11 to  1000000, inclusive), and outputs whether or not the input is a palindrome.  Save the  program as CheckPalindrome.java

When prompting the user for input, be sure to check for an integer first. If the user     enters an integer, first validate that the number is within the range 11 to 1,000,000      (inclusive). If the integer is out of range, you should reprompt for a palindrome. You should determine whether the integer is a palindrome WITHOUT using methods from the String class (or casting the integer input as a string). Methods from other classes defined in Java API are also off limits to solve this specific part.

Hint: Use a loop to reverse the input value (see below), and compare the original input with the reverse.

If the input is not an integer, read it in as a String. Determine whether the message is a

palindrome using loops and methods from the String class to compare

character-by-character.

Sample [Separate] Runs:

Message : bob bob

Result : String bob bob is a palindrome

Message : bobby bobby

Result : String bobby bobby is NOT a palindrome

Message : 10601

Result : int 10601 is a palindrome

*Hint: Start by just handling single-word input. Once passing single-word test cases, extend the program to handle phrases. If the input is a phrase, remove or ignore spaces.

Rubric:

Part 1: CheckPalindrome.java  [+100 points]

Reasonable Code Submitted: x/25

Good Programming Practices: x/10

Header, in-line comments, indentation, descriptive var names & camelCase

Code Compiles: x/15

Program Requirements: x/10

Handles ints as numbers and everything else as Strings: x/5

Check integer palindromes using modulus (required): x/5

Input validation: x/10

■    Accept int as integer using hasNextInt()/Validate range of integer (11-100000)

■    Breakdown:

+10 points: works for both cases, checks range

●    +8 points: attempt made, but fails on either identifying integers or checking range

+5 points: attempt made for both parts,  but doesnt work

+2 pts: only checked for integer or range, not both

Program Execution: x/30

Test with: (+6 pts each)

a single word palindrome

a single word that isnt a palindrome

A phrase (with a space(s))

One integer palindrome

One integer not palindrome

Be sure to tell the student what tests fail (if any)

Input validation should be tested before program execution (separately)

Total: x/100