Question

In: Computer Science

A checksum is a value that is computed based upon some information. It is functional in...

A checksum is a value that is computed based upon some information. It is functional in the sense that given the same information, the exact same value will be computed. Checksums are often used when information is being transmitted over a network.

This lets the receiving end know if the information was transmitted accurately. All published books have a unique 10 and 13 digit ISBN number. This stands for International Standard Book Number.

Your textbook in this class has an ISBN-10 number. The first 9 digits (which may include leading zeros) are the information part of the ISBN-10 number. The 10th digit is a checksum which is calculated from the other 9 digits using the following formula where d1 is the first digit beginning on the left, d2 is the second digit, etc.: ( (1* d1) + (2 * d2) + (3 * d3) + (4 * d4) + (5 * d5) + (6 * d6) + (7 * d7) + (8 * d8) + (9 * d9) ) % 11 Because the large sum then uses modulus 11 arithmetic, the possible values for the checksum are the numbers 0 through 10.

According to the ISBN-10 convention, the checksum can only be a single character (digit) so if the checksum is 10 the last character is denoted as X (Roman numeral for 10) . Write a program that loops, prompting the user to enter the first 9 digits into an input dialog box. You must parse the input value as a single integer. Compute the checksum digit and output the complete 10 digit ISBN number using a Confirm Dialog asking if the user wants to enter another 9 digit number. If the user selects the YES button, then loop. If NO is selected, the program will end. An example of this program in action (without dialog boxes) is: Enter the first 9 digits of an ISBN number: 013601267 The ISBN-10 number is: 0136012671 Do you want to enter another? Enter the first 9 digits of an ISBN number: 013031997 The ISBN-10 number is: 013031997X Do you want to enter another? Extracting the Digits from the Integer The algorithm to compute the checksum is relatively simple, so the interesting part of this program is figuring out how to extract each of the 9 digits from the integer. Hint: Section 3.13 (9th Edition) Case Study: Lottery shows you how to extract the digits from a 2-digit number. Remember, I am forcing you to turn the String from the dialog box into an integer. I will not accept a solution that doesn't do this. When the ISBN number has leading zeros, it makes the problem more complex because you must go from a String to an int and back to a String again.

java code please

Solutions

Expert Solution

Hi,

Hope you are doing fine. I have coded the above program in java keeping all the given conditions in mind. The program has been explained clearly using the comment lines that have been highlighted in bold. Since, there is no specific design of the dialog boxes given, I have used the default frames. You may change the design as per your requirement, the logic would remain the same.

Program:

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class Isbn {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       //JFrame is used for displaying the dialog boxes
       JFrame f;
       f=new JFrame();
       //sum stores the total sum of products of each digit with i+1.
       //digit is used to store the integer conversion of each character of 9 digit string
       //checksum is used to store the checksum
       //choice stores the option clicked by the user to continue

       int sum=0,i=0,digit=0,checksum=0,choice=0;
       //do while loop is used for repeated execution. It breaks when user clicks No i.e choice value is 1
       do {
       //Input dialog
       String input=JOptionPane.showInputDialog(f,"Enter the first 9 digits of an ISBN number:");
       //Traversing through the characters of input string
       for (i=0;i<9;i++)
       {
           //Each character of string are converted to integer and multiplied with i+1. Their sum is stored in sum
           digit=Character.getNumericValue(input.charAt(i));
           sum=sum+((i+1)*digit);
       }
       //calculating checksum
       checksum=sum%11;
       //if the modulus is 10 then we append "X" to the input string
       if(checksum==10)
           input=input+"X";
       else
         //else if it is not 10, then we convert checksum to string and append it at the end of input
           input=input+Integer.toString(checksum);
       //The dialog shows the ISBN 10-digit number and asks if the user wants to enter another number.
       //if user clicks "Yes" then value of choice is 0 else it is 1

       choice=JOptionPane.showConfirmDialog(f,"The ISBN-10 number is: "+input+ " \nDo you want to enter another? ","Result",JOptionPane.YES_NO_OPTION);
   }while(choice==0);
   }

}

Executable code snippet of the program from eclipse:

Output:

Click OK

Click on Yes

Click on OK

Click on No and the execution stops


Related Solutions

A checksum is a value that is computed based upon some information. It is functional in...
A checksum is a value that is computed based upon some information. It is functional in the sense that given the same information, the exact same value will be computed. Checksums are often used when information is being transmitted over a network. This lets the receiving end know if the information was transmitted accurately. All published books have a unique 10 and 13 digit ISBN number. This stands for International Standard Book Number. Your textbook in this class has an...
A checksum is a value that is computed based upon some information. It is functional in...
A checksum is a value that is computed based upon some information. It is functional in the sense that given the same information, the exact same value will be computed.   Checksums are often used when information is being transmitted over a network. This lets the receiving end know if the information was transmitted accurately. All published books have a unique 10 and 13 digit ISBN number. This stands for International Standard Book Number. Your textbook in this class has an...
The following items (partial list) are associated with a functional-based cost accounting information system, an activity-based...
The following items (partial list) are associated with a functional-based cost accounting information system, an activity-based cost accounting information system, or both: ? a. materials purchasing cost incurrence b. assignment of purchasing cost to products using direct labor hours c. assignment of purchasing cost using number of purchase orders d. usage of direct materials e. direct materials cost assigned to products using direct tracing f. materials handling cost incurrence g. materials handling cost assigned using direct labor hours h. materials...
According to ASC Topic 820, the fair value of an asset should be based upon
17. According to ASC Topic 820, the fair value of an asset should be based upona. The price that would be paid to acquire the asset.b. The price that would be paid to replace the asset.c. The price that would be received to sell the asset.d. The price that the item is appraised at balance sheet date.18. Which of the following items does not require measurement at fair value on the balance sheet?a. Asset impairments.b. Treasury stock.c. Business combinations.d. Goodwill.
Prepare an ANOVA table based upon the following information. The SS Total, or Sum of the...
Prepare an ANOVA table based upon the following information. The SS Total, or Sum of the Squared Differences, is 95. The SST, or the Sum of the Squares Due to the Treatments, is 85.5. The total degrees of freedom is 14, while the treatments degrees of freedom is 3.
1. What are executive orders and upon what powers are they based? Why are some executive...
1. What are executive orders and upon what powers are they based? Why are some executive orders controversial?
The latest theories in product/service development deal with creating a value proposition. These are based upon...
The latest theories in product/service development deal with creating a value proposition. These are based upon the pains, gains, and tasks of the customer. Review the resources provided. Consider a hospital cancer center and how it could use the value proposition canvas to create value for the patients of the center.
Calculate the NOI of a property based upon the information provided below: Building area:                         10,500...
Calculate the NOI of a property based upon the information provided below: Building area:                         10,500 sqft Average base rents:                $26.00 psf NNN recoveries:                      $3.50 psf Vacancy rate:                          5.0% Operating expenses                $4.25 psf Percentage rent                      $4,000 per year Concessions                             3.0% Annual debt service                $188,400 per year
Research the Best Buy current situation. Based upon the information provided in the case and what...
Research the Best Buy current situation. Based upon the information provided in the case and what you find out from your research, what would you recommend Best Buy do? What would a CLV perspective suggest they do? How well do you think Best Buy will do in this market? Explain your rationale.
This simulation question available sources is based upon a true set of facts. The information contained...
This simulation question available sources is based upon a true set of facts. The information contained in the simulation question was What is the Relationship Between the Fraud Triangle and Financial Statement Fraud? - Required First, search the Internet or refer to textbooks to learn as much as you can about the Fraud Triangle. Then, answer the following: 2. How can the Fraud Triangle detect/prevent financial statement fraud? Discuss how each of the three elements of the Fraud Triangle can...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT