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
A special case of the non-inverting amplifier is when
Aneli [31]

Answer:

c-Either A or B

Explanation:

The non-inverting amplifier usually has the input voltage connected to the non-inverting input while the inverting input is connected to the output.

Both the unit gain amplifier and the voltage follower have an input voltage connected to the non-inverting input, and the inverting input connected to the output, so both are special cases of the non-inverting amplifier.

The correct answer is

c-Either A or B

4 0
3 years ago
Which of the following will not cause the supply of internet service to increase?
Rus_ich [418]

Answer:

c

Explanation:

5 0
2 years ago
There are___standard colors for text in a theme.
Stella [2.4K]
There are two standard colors for a text in a them
6 0
3 years ago
Describe one way that cells use water
antiseptic1488 [7]
In chemical reactions, as a carrier of materials or keeping the temperature of cells from quickly changing.
8 0
3 years ago
Amanda needs to create an informative print brochure for her local library’s fundraiser dinner. What critical detail must she ha
Charra [1.4K]

Answer: A. target audience for the brochure.

Before even starting the design of the brochure, Amanda needs to get information on who the target audience are going to be. Amanda will need to conduct a quick research on what the audience of their community likes and does not like. By understanding the target audience, Amanda will be able to get an idea of what design, colors, and format she would make that will attract the attention of their audience.

5 0
2 years ago
Other questions:
  • Write a python program to read four numbers (representing the four octets of an IP) and print the next five IP addresses. Be sur
    15·1 answer
  • Which is the best description of a computer virus?
    5·2 answers
  • What mode is generally used when delivering a presentation to an audience?
    8·2 answers
  • Which is an advantage that electronic scheduling tools have over paper calendars?
    13·2 answers
  • 1. Extract title Write a function extract_title that takes one parameter, the filename of a GenBank formatted file, and returns
    14·1 answer
  • What do you mean by GIGO (Garbage-In-Garbage-Out) in computer system?​
    6·1 answer
  • When clients connect to a web server using the _________ method, the server logs them on using the iusr account, by default?
    14·1 answer
  • Retype the paragraph with the corrections. There are 12 corrections. Look closely at the word and letter highlighted in yellow t
    9·1 answer
  • Tạo biến
    8·1 answer
  • In Python, while loops will repeat during the time the test condition is true.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!