Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help: Your program should ask ten users if they want to play. If the user answers y, ask their name. If the user answers

Need help:

Your program should ask ten users if they want to play. If the user answers y, ask their name. If the user answers n, move on to the next user.

Modify your Java program from last week in jGrasp to include:

an array that has 10 rows initialize each element of the array to 5 spaces in the existing loop when the user says they want to play, store their name in that row of the array (1-10) in another loop, display the content of the array and remove displaying the name when the user enters it

import java.util.Scanner;

public class inputVal { //Input: user enters y, Y, n, or N //Process: validate input and if playing ask for user's name //Output: if playing, display the user's name public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

// run the game for 10 times using a for loop for (int run = 1; run <= 10; run++) {

String isPlaying = "n"; String name = "";

// keep looping until user enter either y or n or Y or N do { System.out.print("Do you want to play? "); isPlaying = keyboard.nextLine().toLowerCase(); if ((!isPlaying.equals("n")) && (!isPlaying.equals("y"))) { System.out.println("Please enter Y or N."); } //end if } while (!isPlaying.equals("n") && !isPlaying.equals("y"));

if (isPlaying.equals("y")) { System.out.print("What is your first name? "); name = keyboard.nextLine(); System.out.println("Your first name is " + name + "."); } // end if else { // break out of for loop if user enter N or n break; } } } //end main } // end class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

3. Are our bosses always right? If not, what should we do?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago