1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
irina [24]
3 years ago
12

Using a text editor, create a file that contains a list of at least 15 six-digit account numbers. Read in each account number an

d display whether it is valid. An account number is valid only if the last digit is equal to the remainder when the sum of the first five digits is divided by 10. For example, the number 223355 is valid because the sum of the first five digits is 15, the remainder when 15 is divided by 10 is 5, and the last digit is 5. Write only valid account numbers to an output file, each on its own line. Note that the contents of the file AcctNumsIn.txt will change when the test is run to test the program against different input. Grading Write your Java code in the area on the right. Use the Run button to compile and run the code. Clicking the Run Checks button will run pre-configured tests against your code to calculate a grade. Once you are happy with your results, click the Submit button to record your score. AcctNumsIn.txt ValidateCheckDigits.java

Computers and Technology
1 answer:
Zanzabum3 years ago
4 0

Answer:

See explaination

Explanation:

/File: ValidateCheckDigits.java

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class ValidateCheckDigits {

public static void main(String[] args) {

String fileName = "numbers.txt"; //input file name

String validFileName = "valid_numbers.txt"; // file name of the output file

//Open the input file for reading and output file for writing

try(Scanner fileScanner = new Scanner( new File(fileName));

BufferedWriter fileWriter = new BufferedWriter( new FileWriter(validFileName))) {

//Until we have lines to be read in the input file

while(fileScanner.hasNextLine()) {

//Read each line

String line = fileScanner.nextLine().trim();

//calculate the sum of first 5 digits

int sum = 0;

for(int i = 0; i < 5; i++) {

sum += Integer.parseInt( line.charAt(i) + "");

}

//Get the last digit

int lastDigit = Integer.parseInt(line.charAt(5)+"");

//Check if the remainder of the sum when divided by 10 is equal to last digit

if(sum%10 == lastDigit) {

//write the number in each line

fileWriter.write(line);

fileWriter.newLine();

System.out.println("Writing valid number to file: " + line);

}

}

System.out.println("Verifying valid numbers completed.");

} catch(IOException ex ) {

System.err.println("Error: Unable to read or write to the file. Check if the input file exists in the same directory.");

}

}

}

Check attachment for output and screenshot

You might be interested in
When would you use an omnidirectional microphone?
alina1380 [7]

Answer:

when it is a windy day and you want to reduce the sound of the wind in the recording

5 0
3 years ago
Explain the role of ICT in banks​
vladimir1956 [14]

Answer: ICT help banks improve the efficiency and effectiveness of services offered to customers, and enhances business processes, managerial decision making, and workgroup collaborations, which strengthens their competitive positions in rapidly changing and emerging economies.

Explanation: please give branliest I only need one more to make ace

7 0
2 years ago
The best time to visit a college is: A. during spring break. B. on a weekend. C. when the college is in session. D. during winte
GaryK [48]
When the college is in session
5 0
3 years ago
Read 2 more answers
The term eof represents
rewona [7]

Answer:

EOF stands for End Of File

Google explains it well: EOF is a condition in a computer operating system where no more data can be read from a data source. The data source is usually called a file or stream.

8 0
3 years ago
Read 2 more answers
What is the influence of new technology on society?
sweet [91]

Answer:

E. New technology is beneficial but can also be used in a detrimental way.

Explanation:

New technology such as cryptocurrency (powered by blockchain technology) can be regarded as a welcome development that has benefited the society in so many good ways. However, cryptocurrency as a new technology also has disadvantages it presents to the society. One of such negative influence cryptocurrency has is that it can be used for illicit activities such as money laundering, funding terrorism and so on.

So, in summary, we can conclude that:

"New technology is beneficial but can also be used in a detrimental way."

5 0
2 years ago
Other questions:
  • Suppose you are using a Mac to read your e-mail messages, and you receive an
    8·2 answers
  • What bit position in an ascii code must be complemented to change the ascii letter represented from uppercase to lowercase and v
    14·1 answer
  • This type of peripheral is used to interact with, or send data to, the computer.
    12·2 answers
  • You can use the bash shell to redirect standard output or standard error from the terminal screen using the ____ shell metachara
    15·1 answer
  • A package that includes hardware, software, and support from a single vendor is called a(n ____ package.
    6·1 answer
  • Compare and contrast CD and DVD?
    10·2 answers
  • Kara has been asked to create an employment application form for her company. Which of the following items can she use to make s
    10·1 answer
  • True or false? Resistors regulate and limit electrical current. A. True B. False
    7·2 answers
  • Money money money money
    8·2 answers
  • PLEASE HELP I mainly only need the answer for 4.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!