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]
4 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:
Zanzabum4 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
software that instructs the computer how to run applications and controls the display/keyboard is known as the what?
Tomtit [17]
<span>The software that instructs the computer how to run applications and controls the display /keyboard is known as DRIVERS software, A driver is a software program that enables a specific hardware device to work with a computers operating system. Drivers may be required for internal components such as video cards and optical media drives.</span>
7 0
3 years ago
You are a network administrator at your company. A user attempts to start a computer and receives the following error message: "
katen-ka-za [31]

Answer:

bootrec/rebuildbcd

Explanation:

Several reason could have caused this, ranging from failed updates or installations to boot sector virsues etc

To fix this, you will need to restart the computer (Alt+Ctrl+Del) into recovery mode, Write the bootrec/rebuildbcd command and press enter or bootrec/fixboot.

If the task is successful, you will get a message "The operation completed successfully."

Then you are free restart your computer

5 0
3 years ago
JAVA
Svetach [21]

public class JavaApplication65 {

   

   public static void main(String[] args) {

       for (int i = 1; i <= 50; i++){

           if (i % 2 == 0){

               System.out.println(i);

           }

       }

   }

   

}

I hope this helps!

6 0
3 years ago
Write a simple BASIC program that
Jet001 [13]

Answer:

I think its B hope it helps ! Good luck

Explanation:

4 0
4 years ago
Suppose you create a class Square to be a subclass of GeometricObject. Analyze the following code:
Lemur [1.5K]

Answer:

B. The program has a compile error because you attempted to invoke the GeometricObject class's constructor illegally.

Explanation:

To call a superclass constructor, the user must use super(). This is necessary unless default constructors are used. Also, it is vital to make sure if their are appropriate argument to be used while invoking the superclass constructor.

3 0
4 years ago
Other questions:
  • Is a program that allows you to view images and animations, listen to audio, and watch video files on your computer or mobile de
    11·1 answer
  • I Need an experienced or inspired game developer to answer these questions
    6·1 answer
  • It is possible to make the document larger for viewing small text. <br> True or False
    13·2 answers
  • HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol inclu
    11·1 answer
  • Write code to complete PrintFactorial()'s recursive case. Sample output if userVal is 5:5! = 5 * 4 * 3 * 2 * 1 = 120
    11·1 answer
  • GAMER OYUNCU KOLTUĞU % YERLİ
    6·1 answer
  • What is digital scavenger hunting? A. An application that locates addresses B. A scavenger hunt where players use GPS and digita
    5·1 answer
  • 3. List three common vector image file types.
    7·1 answer
  • What defines the scope of a project?
    5·1 answer
  • A(n) ____________ calculator is a device that assists in the process of numeric calculations but requires the human operator to
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!