Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Task: Using Java, you will read a file containing IMEI numbers, test their validity, throw and handle an exception if you encounter an invalid

JAVA

image text in transcribed

Task: Using Java, you will read a file containing IMEI numbers, test their validity, throw and handle an exception if you encounter an invalid IMEI number, and once all IMEI numbers have been read from the file, state the number of valid IMEI numbers found. (1) Create a custom exception class that, at a minimum, has a no-args constructor that passes an appropriate message to the superclass constructor. You will throw this exception when you encounter an invalid IMEI number, so be sure to give it an appropriately descriptive name. (2) Write a method that accepts a string parameter for the IMEI to validate, it does not return a value. This method should throw an exception if the given IMEI number is invalid. The IMEI numbers in the file will include their dashes, so you will need to find a wa to process the string to get only the digits. (3) In the main method, read a set of IMEI numbers from a file named imei.txt (yes the file must be named this and a sample one is attached to the dropbox). For each IMEI number, validate it using the method you wrote in (2) and remember that your method throws an exception, so you must handle it using a try-catch block. When catching the exception, simply display the exceptions default message. Keep a count of the number of IMEI numbers that are valid. When finished, print the count of valid IMEI numbers. Dont forget to close your file since youre done reading from it.

See the sample run below to get a good idea of what this means. Sample Run Given the following contents of an imei.txt file: 01-226800-577849-2 01-254200-214770-7 01-300600-575615-0 35-875405-178720-8 35-876005-749168-7 35-438506-568724-4 35-148820-154603-3 32-930400-572972-8 35-330509-615685-2 35-824005-766973-7 35-875401-578720-3 Heres the output produced by a sample application: Checking IMEI numbers from imei.txt. Please hold... Invalid IMEI found: 01-300600-575615-0 Invalid IMEI found: 35-438506-568724-4 Invalid IMEI found: 35-148820-154603-3 Invalid IMEI found: 35-824005-766973-7 7 valid IMEIs found

Every mobile device has a unique identification number known as an International Mobile Equipment Identity (IMEI). It is used by a mobile/cellular network to identify valid devices. An IMEl is a 15-digit number consisting of an 8-digit number associated with the type of a phone, a 6-digit serial number, and a check digit A check digit is a digit used for error detection on identification numbers. IMEls use Lunh's algorithm for creating or verifying the check digit. Lunh's algorithm for verification works like this Step 1: Starting at the rightmost, non-check digit and working backwards, double the value of every other digit. If the value you get when doubling is greater than 9, add the digits of the product or subtract 9 from the product Step 2: Take the sum of all the digits Step 3: Mod the total by 10. If that value is 0, then the number is valid For example, let's say you have the following IMEl number: 35-875401-578720-3 The 3 at the end is the check digit (highlighted in orange below), so the rightmost non-check digit is the0 3 0 3 The digits highlighted in blue are the digits to be doubled, here's the result of that doubling 3 Notice in this case "double" means to be added to itself (see how the 1 that was doubled is now 2?) Some of these are greater than 9, so we have to add their digits, but the easiest way, at least programmatically, is to just subtract 9, you'll get the same result with a lot less hassle. This leaves us with 0 5 8 0 3 3 8 0 3 That's the end of step 1. Now, for step 2, we sum all numbers from the end of step 1 (including the check digit) together to get 3+1 8 5 5802558 5203 60 For step 3, we mod the result that we got (i.e., the 60), from step 2 by 10. 60%10-0 so our check digit of 3 is correct

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

Students also viewed these Databases questions

Question

2. How will you handle the situation?

Answered: 1 week ago