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, 22.06.2019 09:30
What are the steps involved in accepting all the changes in a document? arrange these in order click edit. click accept or reject. click changes. click accept all.
Answers: 1
question
Computers and Technology, 23.06.2019 18:30
Report all segments of identity by descent longer than 20 polymorphisms between pairs of individuals in the following cohort of 15 individuals across 49 polymorphisms: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 numeric input 2 points possible (graded) you have 2 attempts to complete the assignment below. for example if the sequence is "bcd", which occurs in "abcdef" , the starting point would be 2 (b), and the finishing point would be 4(d). individuals 7,10 between positions
Answers: 1
question
Computers and Technology, 23.06.2019 21:40
language consists of basic components, and they are called a. 3; mental images, concepts, and speech b. 2; language acquisition and linguistic relativity c. 3; heuristics, algorithms, and analogies d. 4; phonemes, morphemes, syntax, and semantics e. 2; words and grammar
Answers: 3
question
Computers and Technology, 24.06.2019 12:00
Jack is assisting his younger sibling mary with her mathematics assignment, which includes a study of the number system. jack explains to mary that whole numbers are counting numbers that could be used to record the number of fruits in a basket. which data type represents whole numbers? a.integers.b.floating-point numbers. c.strings.d.boolean
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
English, 22.07.2021 19:30
Questions on the website: 13722360