Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 3, Problem 3E
Suppose you are writing a
- a. If response is yes or y, set the boolean variable accept to true; otherwise, set it to false.
- b. How would you change the code so that it will also accept Yes and Y?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Exercise 1: Ask the user to type a string. Count and display the number of vowels (a,e,i,o,u). Print the string with all the vowels removed.
Exercise 2: Cows cost $10 each, sheep cost $1 each and 8 hens can be bought for $1. Write a program which will buy exactly 100 animals for exactly $100 containing all three types (not just 100 sheep!)
. Write a program to display the grade and grade point for a subject when the user key in
their mark using if..else if statement. Your program should allow the user to repeat this
grading for another mark of subject.
TABLE
Marks
Grade
Point
80
100
A
4.0
75
79
A-
3.7
70
74
B+
3.3
65
69
B
3.0
60
64
B-
2.7
55
59
C+
2.3
50
54
C
2.0
47
49
C-
1.7
44
46
D+
1.3
40
43
D
1.0
00 - 39
E
Write a program to:
Store the following message into a string (DO include periods!):I am the door of the sheep. All who came before me are thieves and robbers, I am the door.
Insert the following message after the comma in the string.but the sheep did not listen to them.
Output the string to the screen with a new line at the end.
Replace the following words in the string.a. “I” and "me" with “Jesus”b. “am” with “is”Note: Make sure you only replace the word “ am“ and not the letters “am" that might appear in that sequence in another word
Output the string with a new line at the end.
The final output should be as follows:
Jesus is the door of the sheep. All who came before Jesus are thieves and robbers, but the sheep did not listen to them. Jesus is the door.
Write in C++
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 3.1 - Suppose goals is a variable of type int. Write an...Ch. 3.1 - Suppose goals and errors are variables of type...Ch. 3.1 - Suppose salary and deductions are variables of...Ch. 3.1 - Suppose speed and visibility are variables of type...Ch. 3.1 - Suppose salary and bonus are variables of type...Ch. 3.1 - Assume that nextWord is a string variable that has...Ch. 3.1 - Prob. 7STQCh. 3.1 - What output is produced by the following code? int...Ch. 3.1 - Suppose you change the code in the previous...Ch. 3.1 - What output is produced by the following code? int...
Ch. 3.2 - Suppose number is a variable of type int that has...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.2 - What output is produced by the following...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the code in the previous...Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - What output is produced by the following code?Ch. 3.3 - Suppose you change the first line of the code in...Ch. 3.3 - Prob. 20STQCh. 3.4 - Suppose you change the order of the drawing...Ch. 3.4 - Prob. 22STQCh. 3.4 - Write code for a JOptionPane dialog that will ask...Ch. 3 - Write a fragment of code that will test whether an...Ch. 3 - Write a fragment of code that will change the...Ch. 3 - Suppose you are writing a program that asks the...Ch. 3 - Prob. 4ECh. 3 - Consider the following fragment of code: What is...Ch. 3 - We would like to assess a service charge for...Ch. 3 - What is the value of each of the following boolean...Ch. 3 - The following code fragment will not compile. Why?...Ch. 3 - Prob. 9ECh. 3 - Consider the boolean expression (2 5) (x 100))....Ch. 3 - Write a switch statement to convert a letter grade...Ch. 3 - Consider the previous question, but include + or ...Ch. 3 - Imagine a program that displays a menu of five...Ch. 3 - Repeat the previous exercise, but define an...Ch. 3 - Repeat Exercise 13, but use a multibranch if-else...Ch. 3 - Given that the int variable temp contains a...Ch. 3 - Write Java statements that create a yes-or-no...Ch. 3 - A number x is divisible by y if the remainder...Ch. 3 - Write a program to read in three nonnegative...Ch. 3 - Write a program that reads three strings from the...Ch. 3 - Write a program that reads a one-line sentence as...Ch. 3 - Write a program that allows the user to convert a...Ch. 3 - Write a program that inputs an integer. If the...Ch. 3 - Prob. 7PCh. 3 - Repeat Programming Project 5 of Chapter 2, but...Ch. 3 - Repeat any of the previous Practice Programs using...Ch. 3 - Suppose that we are working for an online service...Ch. 3 - Write a program that reads a string from the...Ch. 3 - Repeat the calorie-counting program described in...Ch. 3 - Repeat Programming Project 5 but in addition ask...Ch. 3 - Repeat Programming Project 11 in Chapter 2, but if...Ch. 3 - Write a program to play the rock-paper-scissor...Ch. 3 - Prob. 9PPCh. 3 - Repeat Programming Project 8 in Chapter 1, but add...Ch. 3 - Write a program that inputs two strings that...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Name the steps in the programming process.
Digital Fundamentals (11th Edition)
Scientists estimate that roughly 10 grams of caffeine consumed at one time is a lethal overdose. Write a progra...
Absolute Java (6th Edition)
Write a for loop that repeats seven times, asking the user to enter a number. The loop should also calculate th...
Starting Out with Java: Early Objects (6th Edition)
Write a function called c that takes as its argument a d structure as defined in this chapter. The function sho...
Programming in C
What determines an objects appearance and other characteristics?
Starting out with Visual C# (4th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a program that prompts the user for a sentence and display in new words. Your program should behave as follow: 1. Display a welcome message. 2. Ask the user for prompting a string with 3 words and 1 punctuation without any spaces. 3. Display the length of the string sentence. 4. Separate the words in the phrase a. Prompt user for the length of each word b. Display the complete sentence with the punctuation in the end. 5. Display a farewell message, so that the user knows that the program has terminated normally. Restrictions: No looping statements allowed (or needed). This question requires the use of the functions: length(), substr() to generate the complete sentence. Following are the sample screen shots to illustrate the expected behavior of your program. User input at the keyboard is marked with a red circle. Your program should work with any sentence with 3 words entered by the user. Assume a perfect user who will always enter correct info. Note: Your program must display…arrow_forwardThis is the question: The program will prompt for and accept two strings from the user: one which is the target string we are looking for and the other string is the source string in which we are searching for the target string Example Dialog: Enter target string: the Enter source string: Now is the time for all good men to come to the aid of their party. The string 'the' occurs 3 times in the string 'Now is the time for all good men to come to the aid of their party.' The target and source strings are case-sensitive. That is, 'the' will NOT match 'The' in the source string. You may not use the count method, split method, or lists in your solution. so far all i have isarrow_forwardHow do I create a wordle like game using C++? Instructions are to create a “target word” by assigning a five-letter word to a string variable. Remember the user’s guess must be: exactly 5 letters long and contain only lowercase letters from a to z. have 6 guesses to get the word Don’t worry about whether it is a valid 5-letter word at this point. Just compare it to the “target word” and report whether it is a match.arrow_forward
- In Programming When you work with text, sometimes you need to determine if a given string starts with or ends with certain characters. You can use two string methods to solve this problem: .startswith() and .endswith()?arrow_forwardCreate a program that will ask the user to enter a string. If the string input is the same with the magic word, display "You got it right...", "Try again later…” otherwise. Magic word is "ITE001A-WeGotABET".arrow_forwardRead a 2-character string from input into variable userString. Declare a Boolean variable isValid and assign isValid with true if userString does not contain any uppercase letters. Otherwise, assign isValid with false. Ex: If the input is 86, then isValid is assigned with true, so the output is: Good string Ex: If the input is BQ, then isValid is assigned with false, so the output is: Bad string Note: Use getline(cin, userString) to read the entire line from input into userString. #include <iostream>#include <string>#include <cctype>using namespace std; int main() { string userString; /* Your code goes here */ if (isValid) { cout << "Good string" << endl; } else { cout << "Bad string" << endl; } return 0;}arrow_forward
- Write a method isPalidrome(String arg) that determines if a String is palindrome or not. Palindrome is when a String remains the same after reversing. The method should return boolean typeWrite a method isPalidrome(String arg) that determines if a String is palindrome or not. Palindrome is when a String remains the same after reversing. The method should return boolean typearrow_forwardWhat is a palindrome? A palindrome is a string that is the same when read left to right as when read right to left. Let's write a program that determines if an arbitrary string is a palindrome. Assume that the string can have blanks, punctuation, capital letters and lower case. Palindrome Examples: A man, a plan, a canal, Panama. Able was I 'ere I saw Elba. Madam, I'm Adam. Racecar Sample Program Output: Enter your palindrome or type quit:A man, a plan, a canal, Panama.Enter your palindrome or type quit:Be at a time I emit a beatEnter your palindrome or type quit:RacecarEnter your palindrome or type quit:A lad named E. MandalaEnter your palindrome or type quit:A Toyota's a ToyotaEnter your palindrome or type quit:Race and tell a dancerEnter your palindrome or type quit:quitPalindromes: A man, a plan, a canal, Panama. Racecar A lad named E. Mandala A Toyota's a ToyotaNOT Palindromes: Be at a time I emit a beat Race and tell a dancer *…arrow_forwardWrite a program that prompts the user to enter a string and replaces all spaces in it with underscores.arrow_forward
- Write a program for an coffee shop. The user will need to choose what type of roast and what type of flavor. You should have at least 3 choices, but you may use more. Use 2 switch statements. 1 for setting the roast and and 1 for setting the flavor and then let your user know what you made for them. Rather than having print statements within your switch statements, you'll want to set values to Strings. You declare and initialize a String variable the same way you do a primitive data type. String coffeeRoast = "dark"; or initialize to an empty String like this String coffeeRoast = ""; Depending on what the user enters, you can assign a value to a String and then use your String variables in your print statement in Javaarrow_forwardA string is a palindrome if it reads the same from front to back as it does from back to front (e.g. "kayak", "rotator" and "noon" are palindromes). When determining whether an alphanumeric string is a palindrome, we often ignore spaces, punctuation and case in the string (e.g. "A man, a plan, a canal --Panama!" is also considered a palindrome). Write a complete C program to read a string, echo it to the screen, determine whether it is a palindrome, and write a message indicating whether it is or isn't. Your main function should prompt for the string, read the string, print it, call the clean function (to remove all spaces, punctuation, and turn uppercase letters into lowercase letters), print the new string, then call the reverse function (to place the characters into reverse order) and print the new string resulting. In the final step, you will compare the result of the reverse function with the original string and print a message if the string is a palindrome or not. The clean…arrow_forwardf. A laborant in a laboratory does a number of antigen tests in one day. Write a program that simulates the number of antigen tests done in a day in a laboratory, displays the number of positives and negatives, and calculates the % of positives in one day. Your program needs to first generate a random number that will show the number of tests done in a day. One laboratory in a day cannot do more than 100 tests and less than 1 (they do at least one). Then for each of the tests, your program needs to generate a random number to show whether they are positive or negative. In order to write this program, you need to have the following three functions used by the main function: test result (void): This function generates a test result. It should randomly return either one or zero. 1 means positive test result and 0 means negative test result. float positive percentage (int,int) : This function takes the total number of positives and the total number of tests and returns the % of positives.…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Constants, Variables, Data types, Keywords in C Programming Language Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=d7tdL-ZEWdE;License: Standard YouTube License, CC-BY