subject

Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.
Notes:
• Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
• Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
• In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
Question 2 – Methods and Control Structures
Allotted time: 15 minutes (plus 5 minutes to submit)
This question involves the use of check digits, which can be used to help detect if an error has occurred when a number is entered or transmitted electronically.
The CheckDigit class is shown below. You will write one method of the CheckDigit class.
public class CheckDigit
{
/** Returns the check digit for num
* Precondition: The number of digits in num is between one and
six, inclusive.
* num >= 0
*/
public static int getCheck(int num)
{ /* implementation not shown */ }
/** Returns true if numWithCheckDigit is valid, or false
otherwise,
* as described in part (a)
* Precondition: The number of digits in numWithCheckDigit
is
* between two and seven, inclusive.
* numWithCheckDigit >= 0
*/
public static boolean
isValid(int numWithCheckDigit)
{ /* to be implemented in part (a) */ }
// There may be variables and methods not shown.
}
(a) Write the isValid method. The method returns true if its parameter numWithCheckDigit, which represents a number containing a check digit, is valid, and false otherwise. The check digit is always the rightmost digit of numWithCheckDigit.
The following table shows some examples of the use of isValid.
Method Call Return
Value Explanation
getCheck(159) 2 The check digit for 159 is 2.
isValid(1592) true

The number 1592 is a valid
combination of a number (159) and its
check digit (2).
isValid(1593) false
The number 1593 is not a valid
combination of a number (159) and its
check digit (3) because 2 is the check
digit for 159.Complete method isValid below. You must use getCheck appropriately
to receive full credit.
/** Returns true if numWithCheckDigit is valid, or false
* otherwise, as described in part (a)
* Precondition: The number of digits in numWithCheckDigit is
* between two and seven, inclusive.
* numWithCheckDigit >= 0
*/
public static boolean isValid(int numWithCheckDigit)
(b) A programmer wants to modify the CheckDigit class to keep track
of how many times a call to isValid is made with an incorrect check
digit. Any time a call to isValid is made with an incorrect check
digit, the count should be increased by one. The programmer would like
to implement this change without making any changes to the signature of
the isValid method or overloading isValid.
Write a description of how you would change the CheckDigit class
in order to support this modification. Do not write the program code
for this change

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 14:00
Need ! will choose brainliest! discuss the role of abstraction in the history of computer software.
Answers: 1
question
Computers and Technology, 24.06.2019 09:50
Suppose you are an ad-serving company and you maintain a log of cookie data for ads you serve to the web pages for a particular vendor (say amazon). a. how can you use this data to determine which are the best ads? b. how can you use this data to determine which are the best ad formats? c. how could you records of past ads and ad clicks to determine which ads to send to a given ip address? d. how could you use this data to determine how well the technique you used in your answer to part c was working? e. how could you use this data to determine that a given ip address is used by more than one person? f. how does having this data give you a competitive advantage vis-à-vis other ad-serving companies?
Answers: 2
question
Computers and Technology, 24.06.2019 22:10
How many different ways are there to order the eight jobs in the queue so that job usu comes somewhere before cdp in the queue (although not necessarily immediately before) and cdp comes somewhere before bbd (again, not necessarily immediately before)?
Answers: 1
question
Computers and Technology, 25.06.2019 04:30
He 98 pointsss how has computers changed over the years? how can they be used now? give details and such!
Answers: 1
You know the right answer?
Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.
No...
Questions
question
Mathematics, 09.05.2021 02:50
question
Mathematics, 09.05.2021 02:50
question
Computers and Technology, 09.05.2021 02:50
question
Mathematics, 09.05.2021 02:50
question
Mathematics, 09.05.2021 02:50
Questions on the website: 13722363