How to using other method to rewrite the below java code? Eg ,using different loop or different
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()
{
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);
Concepts in Federal Taxation
ISBN: 9780324379556
19th Edition
Authors: Kevin E. Murphy, Mark Higgins, Tonya K. Flesher