Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called NumberPlay.java that determines if a 6-digit number, when the digits are added together, is modularly divisible by 11. To find this

Write a program called NumberPlay.java that determines if a 6-digit number, when the digits are added together, is modularly divisible by 11. To find this out you will need to randomly generate or enter a 6-digit number. Each digit will then be added together and then modularly divided by 11, to see if its digits are evenly divided by 11.

Number Sum Formula:

d1 + d2 + d3 + d4 + d5 + d6 0 (mod 11) (where d1 is the first digit of the number, starting on the left-hand side, d2 is the next digit, and so on.)

Example 1, if the number was 674398, then you would add up:

6 + 7 + 4 + 3 + 9 + 8 = 37 % 11 = 4, so not divisible by 11.

Example 2, if the number was 103765, then you would add up:

1 + 0 + 3 + 7 + 6 + 5 = 22 % 11 = 0, so divisible by 11.

The program will first ask the user if they would like to randomly generate a number or enter it. If the user picks the randomly generated number, the program will use Math.random() to randomly generate the 6-digit number and will display the 6-digit number to the user. If the user wants to enter the number, then the program will ask the user for a 6-digit number.

The program will output whether the number is divisible by 11 or not divisible by 11. If it is, the program will display the number with a space after it and the text, is divisible by 11. If it is not, then the computer displays the number with a space after it and the text, is not divisible by 11.

The program will also be able to handle incorrect integer input. If the user does not enter a number that is expected the program will state, Incorrect input.

Here are some sample runs:

Would you like to randomly generate a number (1) or enter it yourself (2)? (Note this is one line of output)

2

Enter a 6-digit number

674398

674398 is not divisible by 11

Would you like to randomly generate a number (1) or enter it yourself (2)? (Note this is one line of output)

1

103765

103765 is divisible by 11

Would you like to randomly generate a number (1) or enter it yourself (2)? (Note this is one line of output)

25

Incorrect input

Would you like to randomly generate a number (1) or enter it yourself (2)? (Note this is one line of output)

2

Enter a 6-digit number

743

Incorrect input

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

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions