Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that determines whether identification numbers typed by users of a photocopier are valid, and prints the appropriate messages shown in the sample

  1. Write a program that determines whether identification numbers typed by users of a photocopier are valid, and prints the appropriate messages shown in the sample runs below. 
  2. The program should prompt the user for a four-digit identification number, read the number, and determine whether it is valid. The input is a single integer, not a string, and not multiple integers.   Valid numbers must be 4 digits with a correct "check digit."  The check digit for an identification number is its rightmost digit; a correct check digit is equal to the remainder of the sum of the three left most digits divided by 7.   
  3.  
  4. For example, to determine if the ID 5731 is valid, we compute the sum of the three left most digits (5 + 7 + 3 = 15) and then compute the remainder of the sum divided by 7. Since the remainder is 1 and is equal to the check-digit, which is also 1, the ID 5731 is a valid ID. 
  5.  
  6. The program will print an error message if the number has less than 3 or more than 4 digits or if it has 4 digits but does not have a correct "check digit."  The program quits if the user enters a negative 1. 
  7.  
  8. Use / and % operators to extract the individual digit.  For example, to extract the first digit from 5731, divide 5731 by 1000 will give you 5.  This is an integer division, so the result is the integer 5.   To extract the 7, divide the remainder of 5731 by 1000.  That should give you 7.  The logic for extracting the rest of the digits is similar. 
  9.  
  10. Submission: Upload your .java file for Program 1 to Blackboard. 
  11.  
  12. Sample runs 
  13.  
  14. run: 
  15. Please enter a four-digit identification number (-1 to end): 123 ***Invalid ID number.  Too few digits.  Goodbye! 
  16. BUILD SUCCESSFUL (total time: 19 seconds) 
  17.  
  18. run: 
  19. Please enter a four-digit identification number (-1 to end): 12345 ***Invalid ID number.  Too many digits.  Goodbye! 
  20. BUILD SUCCESSFUL (total time: 19 seconds) 
  21.  
  22. run: 
  23. Please enter a four-digit identification number (-1 to end): 1234 
  24. ***Invalid ID.  Check digit doesn't match the sum.  Good bye! 
  25. BUILD SUCCESSFUL (total time: 19 seconds) 
  26.  
  27. run: 
  28. Please enter a four-digit identification number (-1 to end): 5731 ***Your ID is valid.  You are authorized to use this copier. 
  29. BUILD SUCCESSFUL (total time: 19 seconds) 
  30.  
  31. run: 
  32. Please enter a four-digit identification number (-1 to end): -1 Goodbye! 
  33. BUILD SUCCESSFUL (total time: 19 seconds) 
  34.  

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Matlab An Introduction with Applications

Authors: Amos Gilat

5th edition

1118629868, 978-1118801802, 1118801806, 978-1118629864

More Books

Students also viewed these Databases questions