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.30CP
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 to tokenize strings.
- The character that would separate tokens is termed as “delimiter”.
- The argument 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.
Program Plan Intro
Tokenizing Strings:
- The tokenizing of a string denotes a process of breaking a string down into its components termed as tokens.
- The “split” method of “String” class could be used to tokenize strings.
- The character that separates tokens is termed as “delimiter”.
- The argument 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
Search for textbooks, step-by-step expl
= bartleby
e Q&A Library
Design a class nam
Start your trial
Design a class named MyPoint to represent a point with
X-and y-coordinates. The class contains:
The data fields x and y that represent the coordinates with getter methods.
A no-arg constructor that creates a point (0, 0).
A constructor that constructs a point with specified coordinates.
A method named distance that returns the distance from this point to a
specified point of the MyPoint type.
A method named distance that returns the distance from this point to
another point with specified x- and y-coordinates.
A static method named distance that returns the distance from two MyPoint
objects.
Draw the UML diagram for the class then implement the class. Write a test
program that creates the two points (0, 0) and (10, 30.5) and displays the distance
between them.
O16
W
MacR eok
Object Oriented Programming: 213COMP, 214COMP (Feb-2022)
Assignment- I [10 marks]
Academic honesty:
O Only pdf file accepted & student ID, will be your upload file.
O Student who submit copied work will obtain a mark of zero.
O Late work or attach file by email message not allowed.
Q1: Write the signature for a method that has one parameter of type String, and does
not return a value.
Q2: Write the signature for a method that has two parameters, both of type Student,
and returns an int value.
Q3: Write the constructor's headers of the followings?
new Student (202101156, “Ahmed");
new Address(51, "jazan university","CS&IT" );
new Grade(true, 505235600, 4.5);
Q4:
a) Write a class Student that define the following information:
name, stid , age.
b) Explain a mutators (setters) and accessors(getters) methods for each
attributes(fields).
c) Add three constructors:
• with empty constructor.
one parameter constructor (name of student)
two parameters constructor (name and stid)
d) Create two…
Method Overloading is a feature that allows a class to have two or more methods having
same name, if their argument lists are different. Argument lists could differ in:
1. Number of parameters.
2. Data type of parameters.
3. Sequence of Data type of parameters.
Write different version of method sum() that display the sum of the values received as
parameter according to the following main method content:
public static void main(String[] args)
{
sum ( 10, 10 );
sum ( 10, 10, 10 );
sum ( 10.0, 10.0 );
sum ( 10, 10.0 );
sum ( 10.0, 10);
}
You have to define five functions with the specified types. Then, demonstrate the Argument
Promotion concept by reducing the number of method to two.
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
- private float c; private void method2(double y) { c = y; } in another class we created an object of the first class then within in it : tester.method2 (10.0f); are there any errors ? how many errors if there are any and with explanation please.arrow_forwardWrite in python language thank youarrow_forwardcompareTo and equals methods for a 24 hour clock program in Javaarrow_forward
- JAVA Practice Question for Midterm Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program by invoking the methods that return the number of vowels and consonants. Print the counts returned. Imagine you are developing a software package for an online shopping site that requires users to enter their own passwords. Your software requires that users’ passwords meet the following criteria: The password should be at least six characters long. The password should contain at least one uppercase and at least one lowercase letter. The password should have at least one digit. a program that asks the user to enter a password, then displays a message indicating whether it is valid or not.arrow_forwardHow does a method handle accepting arguments of both primitive and reference types?arrow_forwardpython programming Implement a constructor for the Person class Implement a constructor for the Student class Create a student with name; Albert Einstein, ramq: 14031879-1235, address: 112 Mercer Street, Princeton, courses: (1)Physics & (2)Relativity where the grades were b and a respectively and with enrollment date: 1895 partial solution attached in the imagearrow_forward
- USING C++ Random Number Guesser 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. I have written a NumberGuesser class to make things easier. // 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 void reset() { low = originalLow; high = originalHigh;…arrow_forwardHow is a value-returning method like a void method? How is it different?arrow_forwardJAVA PROGRAM FLAMES GAME (SEE ATTACHED PHOTO FOR THE PROBLEM AND EXAMPLE) Implement the method interface Flames in has the following methods: public int countLetters(String name1, String name2); - this method returns the total leftover letters between name1 and name2 public char flames(int numLetters); - this method returns the letter equivalent to the numLetters - example if numLetters is 10 is will return the letter 'M' public String letterEquivalent(char flames); -returns the String equivalent of variable flames. Below is the reference for the variable flames F - Friends L - Lovers A - Affectionate M - Marriage E - Enemies S - Sweetheartsarrow_forward
- //Todo write test cases for SimpleCalculator Class // No need to implement the actual Calculator class just write Test cases as per TDD. // you need to just write test cases no mocking // test should cover all methods from calculator and all scenarios, so a minimum of 5 test // 1 for add, 1 for subtract, 1 for multiply, 2 for divide (1 for normal division, 1 for division by 0) // make sure all these test cases fail public class CalculatorTest { //Declare variable here private Calculator calculator; //Add before each here //write test cases here }arrow_forwardAg 1- Random Prime Generator Add a new method to the Primes class called genRandPrime. It should take as input two int values: 1owerBound and upperBound. It should return a random prime number in between TowerBound (inclusive) and upperBound (exclusive) values. Test the functionality inside the main method. Implementation steps: a) Start by adding the method header. Remember to start with public static keywords, then the return type, method name, formal parameter list in parenthesis, and open brace. The return type will be int. We will have two formal parameters, so separate those by a comma. b) Now, add the method body code that generates a random prime number in the specified range. The simplest way to do this is to just keep trying different random numbers in the range, until we get one that is a prime. So, generate a random int using: int randNum = lowerBound + gen.nextInt(upperBound); Then enter put a while loop that will keep going while randNum is not a prime number - you can…arrow_forwardExplain how primitive types and reference types are passed to a methodarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,