Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 1 is already done, need help with Step 2. Step 1 is listed below. Step 1: Rewrite the starter code, GuessBirthdayStarter.java, to prompt the

Step 1 is already done, need help with Step 2. Step 1 is listed below.

Step 1: Rewrite the starter code, GuessBirthdayStarter.java, to prompt the user to enter the character Y for Yes and N for No rather than entering 1 for Yes and 0 for No.

Step 2: Rewrite the code again, but this time allow the user to enter at least 3 different characters, words, or expressions to agree to the prompt and 3 different expressions to disagree. Include a comment that lists all allowable inputs and validate your changes to the starter code

import java.util.Scanner;

public class AgreeorDisagreeKK {

public static void main(String[] args) {

String set1 =

" 1357 " +

" 9 11 13 15 " +

"17 19 21 23 " +

"25 27 29 31";

String set2 =

" 2367 " +

"10 11 14 15 " +

"18 19 22 23 " +

"26 27 30 31";

String set3 =

" 4567 " +

"12 13 14 15 " +

"20 21 22 23 " +

"28 29 30 31";

String set4 =

" 89 10 11 " +

"12 13 14 15 " +

"24 25 26 27 " +

"28 29 30 31";

String set5 =

"16 17 18 19 " +

"20 21 22 23 " +

"24 25 26 27 " +

"28 29 30 31";

int day = 0;

// Scanner

Scanner input = new Scanner(System.in);

// Prompt the user to answer questions

System.out.print("Is your birthday in Set1? ");

System.out.print(set1);

System.out.print(" Enter N for No and Y for Yes: ");

String s = input.nextLine();

char answer = s.charAt(0);

if (Character.toUpperCase(answer)== 'Y')

day += 1;

// Prompt the user to answer questions

System.out.print(" Is your birthday in Set2? ");

System.out.print(set2);

System.out.print(" Enter N for No and Y for Yes: ");

s = input.nextLine();

answer = s.charAt(0);

if (Character.toUpperCase(answer) == 'Y')

day += 2;

// Prompt the user to answer questions

System.out.print("Is your birthday in Set3? ");

System.out.print(set3);

System.out.print(" Enter N for No and Y for Yes: ");

s = input.nextLine();

answer = s.charAt(0);

if (Character.toUpperCase(answer) == 'Y')

day += 4;

// Prompt the user to answer questions

System.out.print(" Is your birthday in Set4? ");

System.out.print(set4);

System.out.print(" Enter N for No and Y for Yes: ");

s = input.nextLine();

answer = s.charAt(0);

if (Character.toUpperCase(answer) == 'Y')

day += 8;

// Prompt the user to answer questions

System.out.print(" Is your birthday in Set5? ");

System.out.print(set5);

System.out.print(" Enter N for No and Y for Yes: ");

s = input.nextLine();

answer = s.charAt (0);

if (Character.toUpperCase(answer) == 'Y')

day += 16;

System.out.println(" Your birthday is " + day + "!");

}

}

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Marketing communications quality of integration assessment profile

Answered: 1 week ago