You are hired by a college to write a Java program to use a

You are hired by a college to write a Java program to use a so-called check sum technique for catching typing errors of student ID. The college assigns a seven-digit number to each student. The seventh digit (i.e., the rightmost digit) is determined from the other digits with the use of the following formula: 7th digit = (1 *(1st digit) * 2 * (2nd digit) * ... * 6 * (6th digit)) % 10 Your program should prompt users to enter a 7-digit number as a student ID, and then display the validity of the entered ID by matching the actual 7th digit with the computed 7th digit. For example, the entered ID 1 2 3 4 5 6 7 is invalid because the computed 7th digit is 1 (= 1 + 1 + 2 + 2 + 3 + 3 + 4 + 4 + 5 + 5 + 6 + 6) 10) and is different from the actual 7th digit which is 7. However, if the entered ID is 1 2 3 4 5 6 1 your program shall display a message of acceptance. User interface specifications: Input The program prompts for a 7-digit student ID. You can assume users will enter 7 consecutive digital characters. Output Display a message to report the validity of the entered student ID. The output should be descriptive and friendly to end users.

Solution

import java.util.Scanner;

public class CheckSum
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print(\"Enter student id: \");

String studentId = sc.nextLine();

String[] nums = studentId.split(\"\");
int[] id = new int[nums.length];
for(int i = 0; i < id.length; i++)
{
id[i] = Integer.parseInt(nums[i]);
}

int checkSum = 0;
for (int i = 0; i < id.length - 1; i++)
{
checkSum = ((i+1)*id[i])%10;
}
if (checkSum != id[id.length-1])
{
System.out.println(\"Enter id: \" + studentId + \" is invalid\");
}
else
{
System.out.println(\"Enter id: \" + studentId + \" is valid\");
}
}
}

 You are hired by a college to write a Java program to use a so-called check sum technique for catching typing errors of student ID. The college assigns a seven

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site