Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
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
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++
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…
This 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 is
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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 - Prob. 21STQCh. 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...
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
- Read 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_forwardWrite a program that reads a string and checks the longest substring starting with "a" and ending with "z" included in it. Note that, the substring cannot contain another a or another z in it. For example: Ifs="bcd bbccdd badefgze tabdz", the longest substring is: 6arrow_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_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_forwardIn JAVA language, input a string that contains only digits. Swap the first and the last digit of the string and print the string in the output.arrow_forward
- Rock Paper Scissors Lizard Spock (RPSLS) is an extended version of the classical game of chance Rock Paper Scissors. This game is created by Sam Kass and Karen Bryla. In this game, the players pick one of the following variables: rock, paper, scissors, lizard, spock. The outcome of the game is determined by the rules below specifying which variable defeats the other. If both players choose the same variable, the game ends in a draw. Rules: • scissors cut paper • paper covers rock • rock captures lizard • lizard poisons spock • spock smashes scissors • scissors captures lizard • lizard eats paper • paper disproves spock • spock vaporizes rock • rock crushes scissors In this project, you will write a program that takes two strings representing the choices of the players as inputs and prints the outcome of the RPSLS game. There are three possible outcomes of this game: a tie, a win for player 1 and, a win for player 2. You are supposed to determine the outcome depending on the players'…arrow_forwardWrite a program that reads the full name of a student; and then prints it in the form: last first middle initial. Example: Input: Ali Hamad Al-Harbi Output: Al-Harbi, Ali H. Write a program that reads a string composed of three words separated by a space, and then print each word on a separate line. Input: one two three Output: One two threearrow_forwardJava with out string formarrow_forward
- Hello..Its no correct....Can you help me?arrow_forwardWrite a program that reads a text (string) and prints the letter that starts the most number ofwords in that stringarrow_forwardRead a 2-character string from input into variable userString. Declare a Boolean variable containsLowercase and assign containsLowercase with true if userString contains a lowercase letter. Otherwise, assign containsLowercase with false. Ex: If the input is vM, then containsLowercase is assigned with true, so the output is: Valid string Ex: If the input is $%, then containsLowercase is assigned with false, so the output is: Invalid 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 (containsLowercase) { cout << "Valid string" << endl; } else { cout << "Invalid string" << endl; } return 0;}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