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
Hope wants to add a third use at the end of her
Arisa [49]

Answer: Put her insertion point at the end of the item 2b.

Press the enter key.

Explanation:

6 0
2 years ago
A company has a popular gaming platform running on AWS. The application is sensitive to latency because latency can impact the u
AysviL [449]
Yetwywywywywywyyw would
8 0
2 years ago
What is the role of the digital cinematographer?
dlinn [17]
<span> is the person in charge of actually shooting the film. He is the head of the camera and lighting departments, and as such he has a big </span>role<span> in the making of any movie

</span>
3 0
3 years ago
Read 2 more answers
Why is this happening when I already uploaded files to my drive?
lara31 [8.8K]

Answer:

u have to upload it to your drive first

Explanation:

7 0
2 years ago
true or false if you type too much text on a powerpoint slide, the additional text is added to a second slide
Nady [450]
True I've had it happen alot
3 0
3 years ago
Read 2 more answers
Other questions:
  • After installing an update on her MacBook, a user contacts the technician to complain that the WiFi is not working. The WiFi ico
    14·1 answer
  • Which of the following mountain ranges stretches from Alabama to Canada?
    10·1 answer
  • Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line3 inFile &gt;&gt; x &gt;&gt; y; /
    6·1 answer
  • Which of the following dimensions of e-commerce technology involves the integration of video, audio, and text marketing messages
    11·1 answer
  • Are storage devices input devices
    8·1 answer
  • A company wants to publish Knowledge articles to its Customer Community. The articles should be organized for easy navigation by
    6·1 answer
  • Which of the following represents the biggest difference between asymmetric and symmetric cryptography?
    9·1 answer
  • Hi everyone,
    6·1 answer
  • Atheel tests a program and gets a NameError. How can this be fixed?
    13·2 answers
  • Question 1 (True/False Worth 3 points)
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!