Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 3.6, Problem 3.22CP
Program Plan Intro
“If…else” statement:
- The statements under the “if” block gets executed only if the “if” condition is true. Otherwise, the statements under “else” part gets executed.
- The statements inside the “if” condition or “else” condition are enclosed within the opening and closing braces.
Syntax:
//If condition
if (condition)
{
//Statements
}
//Else part
else
{
//Statements
}
“compareTo ()” method: The string class contains the method called “compareTo ()” which is used to compare two strings. This can be done inside the “if” condition. The method “compareToIgnoreCase ()” is not case sensitive.
Syntax:
//Checking if both the strings are same
if (string1.compareToIgnoreCase(string2)==0)
{
//Statements
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write and test directed testcases for the testbench. Use ModelSim or a similarsimulator to test the transactor. Hand in a copy of the code and evidence of its function.
You are to implement removeHead, and removeTail and you also have to create the following functions (for visual purposes of the detail explanation, header and trailer sentinels are described as h and t respectively): IMPORTANT NOTE: For all the methods that has the pos parameter i.e. addAt, removeAt, move, make sure to access that specified position from whichever is nearer - the head or the tail - similar to what we have done in the get method.
Example DoublyLinkedList: h <-> 10 <-> 30 <-> 40 <-> 50 <-> t
int add(int num)
This will add the element num into the last element of the linked list and return the position of the newly-added element. In the above example, having add(60) will return 5 as it is the fifth position in the list.
int remove(int num)
This will remove the first instance of the element and return the position of the removed element. In the above example, having remove(40) will return 3 as 40 was the third element in the linked list…
How could you make the execution more deterministic so that only one set of values is possible?
Chapter 3 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 3.1 - Write an if statement that assigns 0 to x when y...Ch. 3.1 - Write an if statement that multiplies payRate by...Ch. 3.1 - Write an if statement that assigns 0.2 to...Ch. 3.1 - Write an if statement that sets the variable fees...Ch. 3.1 - Write an if statement that assigns 20 to the...Ch. 3.1 - Write an if statement that assigns 0 to the...Ch. 3.1 - Write an if statement that displays Goodbye if the...Ch. 3.2 - Write an if-else statement that assigns 20 to the...Ch. 3.2 - Write an if-else statement that assigns 1 to x...Ch. 3.2 - Write an if-else statement that assigns 0.10 to...
Ch. 3.2 - Write an if-else statement that assigns 0 to the...Ch. 3.3 - Write nested if statements that perform the...Ch. 3.3 - Write code that tests the variable x to determine...Ch. 3.4 - What will the following program display? public...Ch. 3.4 - The following program is used in a bookstore to...Ch. 3.5 - Prob. 3.16CPCh. 3.5 - Assume the variables a = 2, b = 4, and c = 6....Ch. 3.5 - Write an if statement that displays the message...Ch. 3.5 - Write an if statement that displays the message...Ch. 3.6 - Assume the variable name references a String...Ch. 3.6 - Prob. 3.21CPCh. 3.6 - Prob. 3.22CPCh. 3.8 - Rewrite the following if-else statements as...Ch. 3.9 - Complete the following program skeleton by writing...Ch. 3.9 - Rewrite the following if-else-if statement as a...Ch. 3.9 - Explain why you cannot convert the following...Ch. 3.9 - What is wrong with the following switch statement?...Ch. 3.9 - What will the following code display? int funny =...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Assume the following variable declaration exists...Ch. 3.10 - Prob. 3.32CPCh. 3.10 - Prob. 3.33CPCh. 3.10 - Assume the following declaration exists in a...Ch. 3 - The if statement is an example of a __________. a....Ch. 3 - This type of expression has a value of either true...Ch. 3 - , , and = = are __________. a. relational...Ch. 3 - , | |, and ! are __________. a. relational...Ch. 3 - Prob. 5MCCh. 3 - To create a block of statements, you enclose the...Ch. 3 - This is a boolean variable that signals when some...Ch. 3 - How does the character A compare to the character...Ch. 3 - This is an if statement that appears inside...Ch. 3 - Prob. 10MCCh. 3 - When determining whether a number is inside a...Ch. 3 - Prob. 12MCCh. 3 - The conditional operator takes this many operands....Ch. 3 - This section of a switch statement is branched to...Ch. 3 - You can use this method to display formatted...Ch. 3 - True or False: The = operator and the == operator...Ch. 3 - True or False: A conditionally executed statement...Ch. 3 - Prob. 18TFCh. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: When an if statement is nested in...Ch. 3 - True or False: The scope of a variable is limited...Ch. 3 - Find the errors in the following code: 1. //...Ch. 3 - Find the errors in the following code: 2. //...Ch. 3 - Find the errors in the following code: 3. //...Ch. 3 - Prob. 4FTECh. 3 - Find the errors in the following code: 5. The...Ch. 3 - Find the errors in the following code: 6. The...Ch. 3 - The following statement should determine whether...Ch. 3 - Find the errors in the following code: 8. The...Ch. 3 - Prob. 9FTECh. 3 - Prob. 10FTECh. 3 - Write an if statement that assigns 100 to x when y...Ch. 3 - Write an if-else statement that assigns 0 to x...Ch. 3 - Using the following chart, write an if-else-if...Ch. 3 - Write an if statement that sets the variable hours...Ch. 3 - Write nested if statements that perform the...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if statement that prints the message The...Ch. 3 - Write an if-else statement that displays the...Ch. 3 - Convert the following if-else-if statement into a...Ch. 3 - Match the conditional expression with the if-else...Ch. 3 - Prob. 12AWCh. 3 - Prob. 13AWCh. 3 - Prob. 14AWCh. 3 - Explain what is meant by the phrase conditionally...Ch. 3 - Explain why a misplaced semicolon can cause an if...Ch. 3 - Why is it good advice to indent all the statements...Ch. 3 - What happens when you compare two String objects...Ch. 3 - Explain the purpose of a flag variable. Of what...Ch. 3 - What risk does a programmer take when not placing...Ch. 3 - Briefly describe how the operator works.Ch. 3 - Briefly describe how the | | operator works.Ch. 3 - Why are the relational operators called...Ch. 3 - When does a constructor execute? What is its...Ch. 3 - Roman Numerals Write a program that prompts the...Ch. 3 - Magic Dates The date June 10, 1960, is special...Ch. 3 - Body Mass Index Write a program that calculates...Ch. 3 - Test Scores and Grade Write a program that has...Ch. 3 - Mass and Weight Scientists measure an objects mass...Ch. 3 - Time Calculator Write a program that asks the user...Ch. 3 - Sorted Names Write a program that asks the user to...Ch. 3 - Software Sales A software company sells a package...Ch. 3 - Shipping Charges The Fast Freight Shipping Company...Ch. 3 - Fat Gram Calculator Write a program that asks the...Ch. 3 - Running the Race Write a program that asks for the...Ch. 3 - The Speed of Sound The following table shows the...Ch. 3 - Mobile Service Provider A mobile phone service...Ch. 3 - Mobile Service Provider, Part 2 Modify the program...Ch. 3 - Bank Charges A bank charges a base fee of 10 per...Ch. 3 - Book Club Points Serendipity Booksellers has a...Ch. 3 - Wi-Fi Diagnostic Tree Figure 3-23 shows a...Ch. 3 - Restaurant Selector You have a group of friends...
Knowledge Booster
Similar questions
- Describe an implementation of the procedure RANDOM.a; b/ that only makes callsto RANDOM.0; 1/. What is the expected running time of your procedure, as afunction of a and b?arrow_forwardCan you please show the getter and setter?arrow_forwardThe Stock of the book needs to be updated correspondingly after a customer has made an order, or a customer has cancelled an order. It can be accomplished by using trigger. You are asked to implement a trigger which needs to take following into consideration: a. The trigger needs to be fired after a new row has been inserted into table Orders, or after a row has been deleted from table Orders which indicates an order has been cancelledb. Each order may contain multiple books in ORDERTITEMS table You also need to write SQL statement or/and PL/SQL code to demonstrate that the implemented trigger accomplishes the business logicarrow_forward
- Your task: Remove any word that does not start with a capital letter. For instance, for the input text of "Hello, 2022 world!", we should get "Hello, 2022 !".arrow_forwardPlease answer the question in the screenshot. The language used is Java.arrow_forwardImplement the FindText() function, which has two strings as parameters. The first parameter is the text to be found in the user provided sample text, and the second parameter is the user provided sample text. The function returns the number of instances a word or phrase is found in the string. In the PrintMenu() function, prompt the user for a word or phrase to be found and then call FindText() in the PrintMenu() function. Before the prompt, call cin.ignore() to allow the user to input a new string.Ex: Enter a word or phrase to be found: more "more" instances: 5arrow_forward
- What happens when the setValue method is called with an -illegal value? Is this a good solution? Can you think of a better solution?arrow_forwardShort answers please. 1. Given the code for emulating the MinusMinus IF statement, how would you implement the while and why? Give general terms, don't submit code 2. The execute uses the token. What does the parseEquation use to break apart the equation? 3. In parseEquation, how do you determine an operand? And operator?arrow_forwardBreakCheck Should return an error (with custom message) if the given line contains the break keyword outside of a single line comment (comments that start with //). i.e, we don't care about the word break inside comments, and only in the actual java code. Your check should only look for break specifically in all-lowercase (so occurrences of "Break" or "BReaK" outside of a single line comment should not be flagged). Note that this check is overly-simplistic in that it might flag some false uses of break such as System.out.println("break");. You do not need to handle this case specially; you should flag any use of the word break outside of a single line comment. Has error code 2arrow_forward
- Answer the given question with a proper explanation and step-by-step solution. USING JAVA: ---Sorting the Invoices via dates--- Another error that will still be showing is that there is not Comparable/compareTo() method setup on the Invoice class file. That is something you need to fix and code. Implement the use of the Comparable interface and add the compareTo() method to the Invoice class. The compareTo() method will take a little work here. We are going to compare via the date of the invoice. The dates of the Invoice class are by default saved in a MM-DD-YYYY format. So they have a dash '-' between each part of the date. So you will need to split the date of the current invoice AND split the date of the object sent to the method. We have three things to compare against here. First we need to check the year. If the years are the same then you should go another step forward and compare the months. If the months are the same then you will lastly have to compare the day. Use whatever…arrow_forwardI need help with this Java program. I got some minor error that I couldn't fix. Checker Classes You will have to implement specific checks to highlight errors found in the source files. We provided an interface Check.java that defines a single method public Optional<Error> lint(String line, int lineNumber) . All the checkers you write should implement this interface and hence, you need to implement the lint method. All of these should return an an Error when one is present with a custom message of your choosing to describe what the error means to the user. If the condition a Check is looking for is not present for a line, should return Optional.empty(). Other Classes For each file below, implement the methods and constructors defined. Error.java public Error(int code, int lineNumber, String message) Constructs an Error given the error code, line number and a message. public String toString() Returns a String representation of the error with the line number, error code and…arrow_forwardI need help with this Java program. I got some minor error that I couldn't fix. Checker Classes You will have to implement specific checks to highlight errors found in the source files. We provided an interface Check.java that defines a single method public Optional<Error> lint(String line, int lineNumber) . All the checkers you write should implement this interface and hence, you need to implement the lint method. All of these should return an an Error when one is present with a custom message of your choosing to describe what the error means to the user. If the condition a Check is looking for is not present for a line, should return Optional.empty(). Other class Error.java public Error(int code, int lineNumber, String message) Constructs an Error given the error code, line number and a message. public String toString() Returns a String representation of the error with the line number, error code and message. The representation should be formatted as (replace curly braces with…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