Question

You are hired by a college to write a Java program

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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");
}
}
}

Add a comment
Know the answer?
Add Answer to:
You are hired by a college to write a Java program to use a so-called check...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 2: Exceptions Mr. Mike wants to check whether the student number and GSM number entered...

    Assignment 2: Exceptions Mr. Mike wants to check whether the student number and GSM number entered by the student to register for attending a conference is valid or not. Write a program in Java to read the Student ID and GSM Number of a student. If the Student ID does not start with the characters ST or if the Mobile Number does not contain exactly 8 digits, throw a user defined exception InvalidDetailsException. If the Mobile Number contains any character...

  • Write a program in Python to solve the following task: In this project, you will build...

    Write a program in Python to solve the following task: In this project, you will build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and...

  • java program QUESTION 2: 1. Write a do-while loop that asks the user to select a...

    java program QUESTION 2: 1. Write a do-while loop that asks the user to select a task from the following menu to continue: 1. Option 1 2. Option 2 3. Option 3 4. Option 4 5. Exit Read the selection from the keyboard then write the switch statement: For option 1, display the message "Do the option 1" For option 2, display the message "Do the option 2" For option 3, display the message "Do the option 3" For option...

  • JavaFX Write a program that displays a histogram to show the number occurrences of each number...

    JavaFX Write a program that displays a histogram to show the number occurrences of each number in an input sequence. There should be a text filed to accept users input numbers and button to show the histogram. Enter your student number (9 digit number) to generate your unique histogram. A student with ID 100013456 will give a histogram like the following one (note the text filed and button are not shown in the following histogram, BUT is required for the...

  • x= Suppose you are building a program for teaching kids' math. Write a java program the...

    x= Suppose you are building a program for teaching kids' math. Write a java program the does the following: 1. Ask the user if he/she wants to sign-up a. If yes continue to step 2 b. If no Display the message "Thank you, Have a nice Day 2. Ask the user to enter a username. 3. Ask the user to enter a password with at least 8 characters long 4. Write a method with the following header: public static Boolean...

  • You have been asked to write a program to grade several multiple-choice exams. The exam has...

    You have been asked to write a program to grade several multiple-choice exams. The exam has 20 questions, each answered with a letter in the range of ‘a’ through ‘f’. The answers key is declared in the program as constant of type string. An example of answer key is “abcdefabcdefabcdefab”. Your program should work for any other answer key. The program should first ask users for the number of students to be graded. Then it should have a while loop...

  • for java using the loop The department of History has just bought a new photocopier. Any...

    for java using the loop The department of History has just bought a new photocopier. Any person using the photocopier must enter an identification code. You have been asked to do the following: Write a program that determines whether identification codes typed by users of a photocopier are valid, and prints appropriate messages. If the identification code, which is a four-digit number, is correct your program computes the cost of copying according to the table below. Your program should prompt...

  • Java: The local Driver's License Office has asked you to write a program that grades the...

    Java: The local Driver's License Office has asked you to write a program that grades the written portion of the driver's   license exam. The exam has 20 multiple choice questions.   Here are the correct answers:    1. B  6. A  11.B  16. C    2. D  7. B  12.C  17. C    3. A   8. A  13.D  18. B    4. A  9. C  14.A  19. D    5. C  10. D  15.D  20. A    Your program should store the correct answers in an array. (Store each question's answer in an element of a String array.) The program...

  • Java Program: In this project, you will write a program called GradeCalculator that will calculate the...

    Java Program: In this project, you will write a program called GradeCalculator that will calculate the grading statistics of a desired number of students. Your program should start out by prompting the user to enter the number of students in the classroom and the number of exam scores. Your program then prompts for each student’s name and the scores for each exam. The exam scores should be entered as a sequence of numbers separated by blank space. Your program will...

  • Write In JAVA: Part 1 The use of computers in education is referred to as computer-assisted...

    Write In JAVA: Part 1 The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use a SecureRandom object to produce two positive one-digit integers (you will need to look up how to do this). The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the student’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT