For this lab you will write a Java program that checks UPC strings to see if they are valid. Your program should first prompt the user to enter a string of numbers as a UPC code, or enter a blank line to quit the program. If the user doesn't quit, your program should ensure that this string is exactly 12 characters in length. If the user enters a string that is not 12 characters in length, your program should print an error message and ask again for a valid string. Your program should use the algorithm below to compute the check digit and compare it to the actual value in the provided string, reporting whether the UPC is valid or invalid. If it is invalid, your program should report what the correct check digit should be for the input UPC. Your program should keep asking for new UPC codes until the user enters a blank line to quit the program. The algorithm for checking for a valid UPC is: 1. From left to right, add the digits in the odd-numbered positions (starting the count from 1 to 11) and multiply the result by 3. 2. From left to right, add the digits in the even-numbered positions to the total computed in step 1 3. Take the result from step 2 and compute the remainder when divided by 10 (result modulo 10). If the remainder is not zero, subtract this remainder from 10 to get the check digit. If the remainder is zero, then the check digit should be 0.
For this lab you will write a Java program that checks UPC strings to see if they are valid. Your program should first prompt the user to enter a string of numbers as a UPC code, or enter a blank line to quit the program. If the user doesn't quit, your program should ensure that this string is exactly 12 characters in length. If the user enters a string that is not 12 characters in length, your program should print an error message and ask again for a valid string. Your program should use the algorithm below to compute the check digit and compare it to the actual value in the provided string, reporting whether the UPC is valid or invalid. If it is invalid, your program should report what the correct check digit should be for the input UPC. Your program should keep asking for new UPC codes until the user enters a blank line to quit the program. The algorithm for checking for a valid UPC is: 1. From left to right, add the digits in the odd-numbered positions (starting the count from 1 to 11) and multiply the result by 3. 2. From left to right, add the digits in the even-numbered positions to the total computed in step 1 3. Take the result from step 2 and compute the remainder when divided by 10 (result modulo 10). If the remainder is not zero, subtract this remainder from 10 to get the check digit. If the remainder is zero, then the check digit should be 0.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
The code must be in JAVA language
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
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.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education