Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
3rd Edition
ISBN: 9780134038179
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 9.6, Problem 9.31CP
Program Plan Intro
Tokenizing Strings:
- The tokenizing of a string denotes a process of dividing a string into its components termed as tokens.
- The “split” method of “String” class could be used for tokenizing strings.
- The character that would separate tokens is termed as “delimiter”.
- The argument that is passed to “split” method denotes a regular expression.
- A regular expression is used to search for patterns in strings, files and other texts.
- To prevent leading or trailing whitespace characters in tokens, the string is been trimmed.
- The “trim” method of “String” class is been used for trimming purposes.
Wrapper class:
- The wrapper class is been provided by Java API for numeric data types.
- These classes contain methods that perform useful operations.
- It involves primitive numeric values.
- The static “toString” method converts to a string from a number.
- The method that accepts number as its argument.
- It returns a number’s string representation.
- The “toBinaryString”, “toHexString”, and “toOctalString” accepts integer as argument.
- It returns string representation of number converted into binary, hexadecimal and octal.
- The “MAX_VALUE” and “MIN_VALUE” stores maximum and minimum value for a specific data type.
- The “Autoboxing” denotes a java process for automatically boxing up a value inside an object.
- The “Unboxing” denotes a reverse process of boxing; it converts a wrapper class object into a primitive type.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
C++HurdleGame The HurdleGame class contains all the functions invoked as a result of a user action (i.e. when a user presses a key on the Hurdle Frontend, one of the functions in HurdleGame will be called. A HurdleGame object comprises a HurdleWords object (which stores all valid guesses and valid Hurdles), and a HurdleState object, which stores and tracks all the game states. Any action should update the HurdleState object.Each function in HurdleGame is called as a result of a user action on the Hurdle Frontend. To understand this, please read the Hurdle Backend API section below before implementing. You are responsible for implementing each of the functions below. LetterEntered ● Called by the Hurdle frontend when the user enters a letter. ● Hint: when a user enters a letter, how should the underlying HurdleState be modified to reflect the change resulting from that key press? WordSubmitted ● Called by the Hurdle front end when the user submits a guess by pressing enter. ● Hint: when…
/ CLASS PROVIDED: IntSet (a container class for a set of// int values)//// CONSTANT// static const int MAX_SIZE = ____// IntSet::MAX_SIZE is the highest # of elements an IntSet// can accommodate.// CONSTRUCTOR// IntSet()// Pre: (none)// Post: The invoking IntSet is initialized to an empty// IntSet (i.e., one containing no relevant elements).// CONSTANT MEMBER FUNCTIONS (ACCESSORS)// int size() const// Pre: (none)// Post: Number of elements in the invoking IntSet is returned.// bool isEmpty() const// Pre: (none)// Post: True is returned if the invoking IntSet has no relevant// relevant elements, otherwise false is returned.// bool contains(int anInt) const// Pre: (none)// Post: true is returned if the invoking IntSet has anInt as an// element, otherwise false is returned.// bool isSubsetOf(const IntSet& otherIntSet) const// Pre: (none)// Post: True is returned if all…
// volunteer.h
#include
class Volunteer {
public:
Volunteer () { }
std::string Name ()
void SetName (const
private:
std::string name_;
};
const { return name_; }
std::string& name) { name_
= name; }
Chapter 9 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
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
- class Currency { protected: int whole; int fraction; virtual std::string get_name() = 0; public: Currency() { whole = 0; fraction = 0; } Currency(double value) { if (value < 0) throw "Invalid value"; whole = int(value); fraction = std::round(100 * (value - whole)); } Currency(const Currency& curr) { whole = curr.whole; fraction = curr.fraction; } /* This algorithm gets the whole part or fractional part of the currency Pre: whole, fraction - integer numbers Post: Return: whole or fraction */ int get_whole() { return whole; } int get_fraction() { return fraction; } /* This algorithm adds an object to the same currency Pre: object (same currency) Post: Return: */ void set_whole(int w) { if (w >= 0) whole = w; } void set_fraction(int f) { if (f >= 0 && f <…arrow_forwardA struct to store a single playing card is as follows: struct card { char suit; char kind; }; The valid suits are 'S', 'H', 'D' and 'C', while the valid kinds are 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', and 'K'. A poker hand can be stored as an array of five struct cards. A flush is a hand that contains five cards, all of the same suit. Write a function that returns 1, if the poker hand passed to it has five cards of the same suit, and 0 otherwise. int isFlush(struct card hand[]); int isFlush(struct card hand[]) {arrow_forwardc++ clasess with coment plesearrow_forward
- Basic javaarrow_forwardTrue or false: The default constructor is the only constructor that may be called for objects in an array of objects.arrow_forwardC++ assigment: It's a Number Guesser assignment. It asks to write a derived class of the NumberGuesser class named RandomNumberGuesser. The derived class should override the behavior of the getCurrentGuess method. It may also add member data and its own constructor. It may also override the higher(), lower() and reset() methods as you see fit. This is the code for NumberGuesser class. It is defined entirely in-line in the following file: NumberGuesser.h // NumberGuesser.h // #ifndef NUMBERGUESSER_H #define NUMBERGUESSER_H #include <iostream> class NumberGuesser { protected: int low; int originalLow; int high; int originalHigh; public: NumberGuesser(int l, int h) { low = originalLow = l; high = originalHigh = h; } virtual int getCurrentGuess() { return (high + low) / 2; } virtual void higher() { low = getCurrentGuess() + 1; } virtual void lower() { high = getCurrentGuess() - 1; } virtual…arrow_forward
- C++ assigment: It's a Number Guesser assignment. It asks to write a derived class of the NumberGuesser class named RandomNumberGuesser. The derived class should override the behavior of the getCurrentGuess method. It may also add member data and its own constructor. It may also override the higher(), lower() and reset() methods as you see fit. This is the code for NumberGuesser class. It is defined entirely in-line in the following file: NumberGuesser.h // NumberGuesser.h // #ifndef NUMBERGUESSER_H #define NUMBERGUESSER_H #include <iostream> class NumberGuesser { protected: int low; int originalLow; int high; int originalHigh; public: NumberGuesser(int l, int h) { low = originalLow = l; high = originalHigh = h; } virtual int getCurrentGuess() { return (high + low) / 2; } virtual void higher() { low = getCurrentGuess() + 1; } virtual void lower() { high = getCurrentGuess() - 1; } virtual…arrow_forwardTerm by CodeChum Admin (JAVA CODE) Construct a class called Term. It is going to represent a term in polynomial expression. It has an integer coefficient and an exponent. In this case, there is only 1 independent variable that is 'x'. There should be two operations for the Term: public Term times(Term t) - multiplies the term with another term and returns the result public String toString() - prints the coefficient followed by "x^" and appended by the exponent. But with the following additional rules: if the coefficient is 1, then it is not printed. if the exponent is 1, then it is not printed ( the caret is not printed as well) if the exponent is 0, then only the coefficient is printed. Input The first line contains the coefficient and the exponent of the first term. The second line contains the coefficient and the exponent of the second term. 1·1 4·3 Output Display the resulting product for each of the test case. 4x^4arrow_forwardTrue or false: Objects can be passed to functions, but they cannot be returned by functions.arrow_forward
- Welcome Assignment ### welcome_assignment_answers ### Input - All eight questions given in the assignment. ### Output - The right answer for the specific question. def welcome_assignment_answers(question): # The student doesn't have to follow the skeleton for this assignment. # Another way to implement it is using "case" statements similar to C. if question == "Are encoding and encryption the same? - Yes/No": answer = "The student should type the answer here" elif question == "Is it possible to decrypt a message without a key? - Yes/No": answer = "The student should type the answer here" return (answer) # Complete all the questions. if __name__ == "__main__": # use this space to debug and verify that the program works debug_question = "Are encoding and encryption the same? - Yes/No" print(welcome_assignment_answers(debug_question)) As you can see, the first two questions are already in the skeleton code. Please follow the first two questions…arrow_forwardint class Inventory { std::vector<Item*> m_Items; static unsigned int m_ItemsMade; void CreateItem() { std::string name = "Item " + std::to_string(m_ItemsMade); m_Items.push_back(new Item(name.c_str(), 100 * m_ItemsMade)); ++m_ItemsMade; } public: Inventory() { CreateItem(); CreateItem(); CreateItem(); } void Print() const { size_t* nSize = new size_t(m_Items.size()); std::cout << "_____INVENTORY_____\n"; for (unsigned int i = 0; i < *nSize; ++i) { m_Items[i]->Print(); } } }; GetValidatedInt(const char* strMessage, int nMinimumRange = 0, int nMaximumRange = 0); This function should first display the provided message to the screen then use cin to get an int from the user. Error check and validate to ensure a legal integer was entered. If not, clear the cin buffer using clear() and ignore() and try again (Note: the buffer still needs to be cleared even if this step was successful). If a legal integer was entered, check its value to see if it is within the…arrow_forwardclass Artist{StringsArtist(const std::string& name="",int age=0):name_(name),age_(age){}std::string name()const {return name_;}void set_name(const std::string& name){name_=name;}int age()const {return age_;}void set_age(int age){age_=age;}virtual std::string perform(){return std::string("");}private:int age_;std::string name_;};class Singer : public Artist{public:Singer():Artist(){};Singer(const std::string& name,int age,int hits);int hits() const{return hits_;}void set_hits(int hit);std::string perform();int operator+(const Singer& rhs);int changeme(std::string name,int age,int hits);Singer combine(const Singer& rhs);private:int hits_=0;};int FindOldestandMostSuccess(std::vector<Singer> list); Implement the function Singer Singer::combine(const Singer& rhs):It should create a new Singer object, by calling the constructor with the following values: For name it should pass a combination of be the name of the calling object followed by a '+' and then…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage