Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 9.3, Problem 9.15CP
Program Plan Intro
String class:
- The “String” class provides a number of methods that examines for a string inside of a string.
- The term “substring” refers to a string that denotes another string’s part.
- The “startsWith” method would determine whether calling string of object begins with a specific substring.
- The method returns “true” if string begins with specified substring, it returns “false” otherwise.
- The “endsWith” method would determine whether calling string would end with a specified substring.
- The method returns “true” if string ends with specified substring, it returns “false” otherwise.
- The “regionMatches” method would determine whether specified regions for two strings match.
- The first argument of this method can be “true” or “false” that indicates whether a case-insensitive comparison could be performed.
- The method “trim” denotes a built-in function that eliminates leading as well as trailing spaces in string.
Given code:
String str1 ="William ";
String str2 ="the";
String str3 ="Conqueror";
System.out.println(str1.trim() + str2.trim() +
str3. trim());
Explanation:
- The strings are been stored in variables “str1”, “str2” and “str3”.
- The strings are been trimmed using “trim()” method.
- The resultant strings are concatenated using “+” operator.
- The result of concatenation is been displayed.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
function performTask () {
var valuel;
valuel - document.getElementById ("FirstBox").value;
if (valuel == "Yes") {
document.getElementById ("paragraphl").innerHTML = "Agreed";
) else if (valuel =- "No") {
document.getElementById ("paragraphl").innerHTML = "Sorry";
) else (
alert ("Error")
Describe the purpose of the following JavaScript statements from the function
performTask ().
i. alert("Error"),
ii. value1 = document.getElementByld("FirstBox").value;
iii. document.getElementByld("paragraph1").innerHTML = "Agreed";
Scanner method --------------- reads characters until it encounters a newline character, then returns those characters as a String.
Fix the errors and find the lowest marks entered by the user
struct std{string name;int reg_no;int marks[5];}s1;getline(cin,s1.name);cin>>s1.reg_no;for(int i =0;i<5;i++)cin>>s1.marks[i]
Chapter 9 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 9.2 - Prob. 9.1CPCh. 9.2 - Write an if statement that displays the word digit...Ch. 9.2 - Prob. 9.3CPCh. 9.2 - Write a loop that asks the user, Do you want to...Ch. 9.2 - Prob. 9.5CPCh. 9.2 - Write a loop that counts the number of uppercase...Ch. 9.3 - Prob. 9.7CPCh. 9.3 - Modify the method you wrote for Checkpoint 9.7 so...Ch. 9.3 - Look at the following declaration: String cafeName...Ch. 9.3 - Prob. 9.10CP
Ch. 9.3 - Prob. 9.11CPCh. 9.3 - Prob. 9.12CPCh. 9.3 - Prob. 9.13CPCh. 9.3 - Look at the following code: String str1 = To be,...Ch. 9.3 - Prob. 9.15CPCh. 9.3 - Assume that a program has the following...Ch. 9.4 - Prob. 9.17CPCh. 9.4 - Prob. 9.18CPCh. 9.4 - Prob. 9.19CPCh. 9.4 - Prob. 9.20CPCh. 9.4 - Prob. 9.21CPCh. 9.4 - Prob. 9.22CPCh. 9.4 - Prob. 9.23CPCh. 9.4 - Prob. 9.24CPCh. 9.5 - Prob. 9.25CPCh. 9.5 - Prob. 9.26CPCh. 9.5 - Look at the following string:...Ch. 9.5 - Prob. 9.28CPCh. 9.6 - Write a statement that converts the following...Ch. 9.6 - Prob. 9.30CPCh. 9.6 - Prob. 9.31CPCh. 9 - The isDigit, isLetter, and isLetterOrDigit methods...Ch. 9 - Prob. 2MCCh. 9 - The startsWith, endsWith, and regionMatches...Ch. 9 - The indexOf and lastIndexOf methods are members of...Ch. 9 - Prob. 5MCCh. 9 - Prob. 6MCCh. 9 - Prob. 7MCCh. 9 - Prob. 8MCCh. 9 - Prob. 9MCCh. 9 - Prob. 10MCCh. 9 - To delete a specific character in a StringBuilder...Ch. 9 - Prob. 12MCCh. 9 - Prob. 13MCCh. 9 - These static final variables are members of the...Ch. 9 - Prob. 15TFCh. 9 - Prob. 16TFCh. 9 - True or False: If toLowerCase methods argument is...Ch. 9 - True or False: The startsWith and endsWith methods...Ch. 9 - True or False: There are two versions of the...Ch. 9 - Prob. 20TFCh. 9 - Prob. 21TFCh. 9 - Prob. 22TFCh. 9 - Prob. 23TFCh. 9 - int number = 99; String str; // Convert number to...Ch. 9 - Prob. 2FTECh. 9 - Prob. 3FTECh. 9 - Prob. 4FTECh. 9 - The following if statement determines whether...Ch. 9 - Write a loop that counts the number of space...Ch. 9 - Prob. 3AWCh. 9 - Prob. 4AWCh. 9 - Prob. 5AWCh. 9 - Modify the method you wrote for Algorithm...Ch. 9 - Prob. 7AWCh. 9 - Look at the following string:...Ch. 9 - Assume that d is a double variable. Write an if...Ch. 9 - Write code that displays the contents of the int...Ch. 9 - Prob. 1SACh. 9 - Prob. 2SACh. 9 - Prob. 3SACh. 9 - How can you determine the minimum and maximum...Ch. 9 - Prob. 1PCCh. 9 - Prob. 2PCCh. 9 - Prob. 3PCCh. 9 - Prob. 4PCCh. 9 - Prob. 5PCCh. 9 - Prob. 6PCCh. 9 - Check Writer Write a program that displays a...Ch. 9 - Prob. 8PCCh. 9 - Prob. 9PCCh. 9 - Word Counter Write a program that asks the user...Ch. 9 - Sales Analysis The file SalesData.txt, in this...Ch. 9 - Prob. 12PCCh. 9 - Alphabetic Telephone Number Translator Many...Ch. 9 - Word Separator Write a program that accepts as...Ch. 9 - Pig Latin Write a program that reads a sentence as...Ch. 9 - Prob. 16PCCh. 9 - Lottery Statistics To play the PowerBall lottery,...Ch. 9 - Gas Prices In the student sample program files for...
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
- . COMPLETE THE CODES.arrow_forwardStaff # name: String # id: int PartTimer + Staff() + Staff(name: String, id: int) skillLevel: int + getName (): String + getId (): int + calculatePay () : double + toString (): String hoursWorked: int + Part Timer (name: String, id: int, skillLevel: int, hoursWorked: int) + getskillLevel(): int + getHours Worked () : int + tostring () : String java.lang.Comparable compareTo (o: Object): int Figure 1: The relationship between staff, PartTimer and Comparable Skill Level / Tahap Kemahiran Pay Rate Per Hour/ Kadar Bayaran Per Jam 0 ( Basic / Asas) RM50.00 1 (Moderate / Sederhana) RM100.00 RM150.00 2 (Expert / Mahir) Table 1: Skill level and the pay rate per hour Write a complete Java program to create PartTimer class and test class based on the Figure 1, Table 1 and the following requirements: Partimer class is derived from staff and implements Comparable Interface. The calculate Pay()method from the staff class will be implemented in the subclass to calculate the employee's pay. The pay…arrow_forwardAssignment Content Write a program that lets the user enter the coordinates of the center and radius of two circles, circle 1 with center coordinates at (* Y1 and circle 2 with center coordinates at (X y,). The program then determines whether circle 2 is inside circle 1 or overlaps with circle 1. rl rl • (x1, y1) (x1, y1) (x2, y2), (x2, y2) Circle 2 is found to be inside circle 1 if distance between the centers is <=Tradius circle1 - radius cirede and circle 2 is said to overlap circle one if the distance between the two centers is <=radius circle1 + radius circle2- Test Cases: Enter center coordinates (x, y) and radius of circle 1:0.5 5.1 13 Enter center coordinates (x, y) and radius of circle 2:11.7 4.5 Circle 2 is inside of circle 1 Enter center coordinates (x, y) and radius of circle 1:3 75.5 Enter center coordinates (x, y) and radius of circle 2: 6.7 3.5 3 Circle 2 overlaps circle 1 Enter center coordinates (x, y) and radius of circle 1:3.55.5 1 Enter center coordinates (x, y) and…arrow_forward
- Word Separator Create an application that accepts as input a sentence in which all the words are run together but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRoses." would be converted to "Stop and smell the roses."arrow_forwardDirection: Insert Input Validation on this program: 1. Validation for the choices 2. Validation for the numbers of choices ........ #include<iostream> using namespace std; struct FruitType{ int shape; int color; int texture; }; FruitType inputFruit(FruitType *fruit){ cout << "Fruit Shape: "; cin >> fruit->shape; cout <<"Fruit Color: "; cin >> fruit->color; cout << "Fruit Texture: "; cin >> fruit->texture; cout << "\"; } FruitType identifyFruit(FruitType *fruit){ cout << "Fruit Type: "; if(fruit->shape == 0 && fruit->color == 2 && fruit->texture == 0){ cout << "Apple"; } else if(fruit->shape == 1 && fruit->color == 0 &&…arrow_forwardtestScore Array: Student1 = 75Student2 = 24Student3 = 73Student4 = 65Student5 = 86Student6 = 45Student7 = 56Student8 = 94 Write code in C# to process the student's result from the array(testScore) based on the condition below and display all the score that are below the passing marks onto a ListBox (lstFailList). Condition: The student is passed if the grade is more than 50.arrow_forward
- design patterns quetion public double calculatePerimeter(Shapes [] shapes) { double p = 0;for (Shape shape : shapes) { if (shape is Rectangle) { Rectangle rectangle = (Rectangle) shape; p += (rectangle.Width+rectangle.Height) * 2; } else { Circle circle = (Circle)shape; p += 2 * circle.Radius * Math.PI; } } return p; } which design principle is violated in the above code? what is the issue/ limitation of this code? rewrite the code to not violate the design principle you answered in part 1?arrow_forwardIf String str1 = new String("Final Exam");, the value of str1.indexOf('x') isarrow_forwarddef area(side1, side2): return side1 * side2s1 = 12s2 = 6Identify the statements that correctly call the area function. Select ALL that apply. Question options: area(s1,s2) answer = area(s1,s2) print(f'The area is {area(s1,s2)}') result = area(side1,side2)arrow_forward
- * CENGAGE MINDTAP Programming Exercise 8-3A Instructions CarCareChoice.java + Write an application for Cody's Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as $25, $22, $15, or $5, accordingly. Display Invalid Entry if the user enters an invalid item. An example of the program is shown below: Enter selection: oil change tire rotation battery check brake inspection battery check battery check price is $15 Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. Once you are happy with your results, click the Submit button to record your score.arrow_forwardRest of code in image / This is a bad programming style since it is using goto. // This is an spagetti code and not working.// Use function to display menu, and display game rules,// Use different color for text display.// fix it so it works any way you like./*HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE); // Write 16 lines in 16 different colors. for (int color = 0; color < 16; color++) { SetConsoleTextAttribute (screen, color); cout << " Hello World!" << endl; Sleep(400); // Pause between lines to watch them appear } // Restore the normal text color) SetConsoleTextAttribute(screen, 7);*/#include <iostream>#include <windows.h>using namespace std;int main(){ //textbackground(WHITE); //textcolor(RED); system("cls"); char ch, a[20], ch2; int num = 100, rnum, guess, count, ch1, c = 0; cout << "**********************************************************"<<endl; cout << "*…arrow_forwarddebug the codearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT