Question
How to using other method to rewrite the below java code? Eg ,using different loop or different method to do the validation public void enterPlayerName()
How to using other method to rewrite the below java code?
Eg ,using different loop or different method to do the validation
public void enterPlayerName()
{
Scanner scanner = new Scanner(System.in);
String name = " ";
do
{
System.out.println("Prime Challenge game start ");
System.out.println("Please enter your name: ");
name = scanner.nextLine();
if(name.trim() == "")
System.out.println("You can not enter blank name");
else if(name.length() > 10)
System.out.println("Name cannot be exceed 10 characters");
else if(!name.matches("[a-zA-Z]*"))
System.out.println("Please enter valid name(only alphabetic characters is allowed)");
} while (name.length() > 10 || !name.matches("[a-zA-Z]*") || name.trim() == "");
player.setName(name);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Below is the rewritten Java code using a different loop and method for input validation public void ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Concepts In Federal Taxation
Authors: Kevin E. Murphy, Mark Higgins, Tonya K. Flesher
19th Edition
978-0324379556, 324379552, 978-1111579876
Students also viewed these Computer Engineering questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App