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% (14 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 2002 thesis proposed by Stephen Wolfram, chief executive of Mathematica, was that all knowledge could be described as an algorithm. How far do you agree with such a proposition and is the end goal...
-
Anteater Plc (continued) Required: From the above accounts prepare the following ratios: (a) Profitability ratios (b) Efficiency ratios (c) Liquidity ratios (d) Gearing ratio (e) Investment ratios.
-
The following data are for Montgomery Retail Outlet Stores. The account balances (in thousands) are for 2011. Marketing and advertising costs $ 24,000 Merchandise inventory, January 1, 2011 45,000...
-
In 2021, Elaine paid $2,800 of tuition and $600 for books for her dependent son to attend State University this past fall as a freshman. Elaine files a joint return with her husband. What is the...
-
Write and test a program to simulate the flow diagram of CSMA/CD in Figure 12.13. Figure 12.13 Flow diagram for the CSMA/CD Station has a frame to send K= 0 Legend T Frame average transmission time...
-
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...
-
The pilot of a 90,000-lb airplane which is originally flying horizontally at a speed of 400 mi/hr cuts off all engine power and enters a 5 glide path as shown. After 120 seconds the airspeed is 360...
-
An aircraft \(P\) takes off at \(A\) with a velocity \(v_{0}\) of \(250 \mathrm{~km} / \mathrm{h}\) and climbs in the vertical \(y^{\prime}-z^{\prime}\) plane at the constant \(15^{\circ}\) angle...
-
If each resistor in Figure P31.75 has resistance \(R=5.0 \Omega\), what is the equivalent resistance of the combination? Data from Figure P31.75 wwwwww wwwww www www wwwww
-
Identify the proper point to recognize expense for each of the following transactions. a. Kat Inc. purchases on credit six custom sofas for \(\$ 800\) each in June. Two of the sofas are sold for \(\$...
-
In the circuit of Fig. 4-51 write two loop equations using I 1 and I 2 . Then find the currents and node voltages. A 3A ( 4 3 V 792 B +1 D w 392 12 C
-
The capacitor in the circuit shown in Fig. 7-37 has initial charge Q 0 = 800 C, with polarity as indicated. If the switch is closed at t = 0, obtain the current and charge, for t > 0. 100 V (+ 10 4 F
-
What is the purpose of breach-of-promise lawsuits?
-
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...
-
Explain the role of secondary markets in trading securities and describe how exchanges, such as the New York Stock Exchange, help facilitate the process. 150 words or more so I can better understand!
-
Cyber professionals often advise that one of the best ways to deter fraud is to set your emails for automatic out of office replies so that everyone knows you are out of the office and cybercriminals...
-
Suppose B=(2,2,1). Suppose Also That B Makes An Angle Of 30 Degrees With A And AxB=6. Find A
Study smarter with the SolutionInn App