Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts In Federal Taxation

Authors: Kevin E. Murphy, Mark Higgins, Tonya K. Flesher

19th Edition

978-0324379556, 324379552, 978-1111579876

More Books

Students also viewed these Computer Engineering questions

Question

What are the advantages and disadvantages of arbitration?

Answered: 1 week ago

Question

Explain the causes of indiscipline.

Answered: 1 week ago

Question

Explain the factors influencing wage and salary administration.

Answered: 1 week ago