Rewrite Listing 4.3, GuessBirthday.java, to prompt the user to enter the character Y for Yes and N
Question:
Rewrite Listing 4.3, GuessBirthday.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.
Transcribed Image Text:
1 import java.util.Scanner; 2 3 public class GuessBirthday { public static void main(String[] args) { String setl = "1 3 5 7\n" + " 9 11 13 15\n" + "17 19 21 23\n" + "25 27 29 31"; 4 5 10 String set2 "2 3 6 7\n" + 11 12 13 "10 11 14 15\n" + "18 19 22 23\n" + "26 27 30 31"; 14 15 16 17 18 String set3 = " 4 5 6 7\n" + "12 13 14 15\n" + "20 21 22 23\n" + "28 29 30 31"; 19 20 21 22 23 String set4 = " 8 9 10 11\n" + "12 13 14 15\n" + "24 25 26 27\n" + "28 29 30 31"; 24 25 26 27 28 29 String set5 = "16 17 18 19\n" + "20 21 22 23\n" + "24 25 26 27\n" + "28 29 30 31"; 30 31 32 33 34 35 int day - 0; 36 // Create a Scanner Scanner input = new Scanner(System.in); 37 38 39 // Prompt the user to answer questions System.out.print ("Is your birthday in Set1?\n"); System.out.print(set1); System.out.print("\nEnter 0 for No and 1 for Yes: "); int answer = input.nextInt (); 40 41 42 43 44 45 46 if (answer == 1) day += 1; 47 48 // Prompt the user to answer questions System.out.print("\nIs your birthday in Set2?\n"); System.out.print(set2); System.out.print("\nEnter 0 for No and 1 for Yes: "); answer = input.nextInt(); 49 50 51 52 53 54 55 if (answer -- 1) 56 day += 2; 57 // Prompt the user to answer questions System.out.print("Is your birthday in Set3?\n"); System.out.print(set3); System.out.print("\nEnter 0 for No and 1 for Yes: "); answer = input.nextInt(); 58 59 60 61 62 63 64 if (answer == 1) day +- 4; 65 66 67 // Prompt the user to answer questions System.out.print("\nIs your birthday in Set4?\n"); System.out.print(set4); System.out.print("\nEnter 0 for No and 1 for Yes: "); answer = input.nextInt(); 68 69 70 71 72
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (12 reviews)
Program Plan Create a class called GuessBirthday Initialize the main method with variables sett set2 set3 set4 set5 and s as strings day as integer and answer as character Assign sett set2 seta set4 s...View the full answer
Answered By
Muhammad adeel
I am a professional Process/Mechanical engineer having a vast 7 years experience in process industry as well as in academic studies as a instructor. Also equipped with Nebosh IGC and lead auditor (certified).
Having worked at top notch engineering firms, i possess abilities such as designing process equipment, maintaining data sheets, working on projects, technical biddings, designing PFD and PID's etc.
Having worked as an instructor in different engineering institutes and have been involved in different engineering resrearch projects such as refinery equipment designing, thermodynamics, fluid dynamics, chemistry, rotary equipment etc
I can assure a good job within your budget and time deadline
4.90+
52+ Reviews
60+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
a. Write an application that accepts up to 20 Strings, or fewer if the user enters a terminating value. Store each String in one of two listsone list for short Strings that are 10 characters or fewer...
-
You modified the RentalDemo program for Sammys Seashore Supplies to accept and display data for an array of three Rental objects. Now, modify the program to use an array of eight Rental objects....
-
Rewrite Exercise 1.11 to prompt the user to enter the number of years and displays the population after that many years. Here is a sample run of the program: Enter the number of years: 5 The...
-
Jefferson Company purchased a piece of equipment on January 1, 2014. The equipment cost $60,000 and has an estimated life of 8 years and a salvage value of $8,000. What was the depreciation expense...
-
a) Use pseudocode to specify a brute-force algorithm that determines when given as input a sequence of n positive integers whether there are two distinct terms of the sequence that have as sum a...
-
A voltaic cell represented by the following cell diagram has E cell = 1.250 V. What must be [Ag + ] in the cell? 2+ Zn(s) Zn+ (1.00 M)||Ag+ (x M) Ag(s)
-
Refer to the information in Exercise 16-14. Prepare journal entries dated June 30 to record: (a) raw materials purchases, (b) direct materials usage, (c) indirect materials usage, (d) direct labor...
-
Marsh Corporation began operations on January 1, 2014. The following information is available for Marsh Corporation on December 31, 2014. Prepare an income statement, a retained earnings statement,...
-
Construct factor trees for each of these numbers. (a) 108 (b) 378 (c) 550
-
ABC Airlines first class cabins have 10 seats in each plane. ABCs overbooking policy is to sell up to 11 first class tickets, since cancellations and no-shows are always possible (and indeed are...
-
Write a program that prompts the user to enter an integer between 0 and 15 and displays its corresponding hex number. Here are some sample runs: Enter a decimal value (0 to 15): 11 The hex value is B...
-
Write a program that prompts the user to enter two characters and displays the major and status represented in the characters. The first character indicates the major and the second is number...
-
Obtain the following z-scores. a. z0.20 b. z0.06
-
What are the food security issues in our northern, indigenous and low-income communities?
-
What are test of details of balances. Explain with an example.
-
What flexibility does irrevocable and irrevocable trust offer that other trusts do not? What are its advantages and disadvantages of irrevocable and irrevocable trust?
-
In a dissolution proceeding, if the wife has moved to California and resided there for the past year, but the husband remains in the couple's residential home in Virginia, which state has...
-
Simon, a Malaysian resident was employed by KPMG Tax Services, Malaysia, as a senior manager.During basis period for YA2010, he was seconded to KPMG Tax Services in London to oversee the tax advisory...
-
Compute the missing amount in the accounting equation for each company (amounts in millions): ___________________________Assets _________ Liabilities _______ Shareholders'...
-
United Business Forms capital structure is as follows: Debt ............................................ 35% Preferred stock ........................... 15 Common equity .......................... 50...
-
Write a program that prompts the user to enter a hex number in string and displays its decimal value. Use Streams reduce method to convert a hex number to decimal.
-
Write a program that prompts the user to enter a binary number in string and displays its decimal value. Use Streams reduce method to convert a binary number to decimal.
-
Rewrite Programming Exercise 7.9 using streams. Data from Programming Exercise 7.9 Write a method that finds the smallest element in an array of double values using the following header: public...
-
Go to https://www.cvedetails.com/vulnerability-list/vendor_id-26/product_id-251/Microsoft-Sql-Server.html Links to an external site Review some of the vulnerabilities with SQL Server. Discussing at...
-
Explain job responsibilities of a SQL Server database administrator? What are some positives and negatives aspects of a career working as a SQL Server DBA?
-
Help me to compareMySQL to Microsoft SQL Server. MySQL is an open-source database that runs on almost all platforms (UNIX, Windows, and Linux).What are the basic differences between MySQL and...
Study smarter with the SolutionInn App