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
List the memory units inside and outside of the CPU, along with short descriptions of their
Vitek1552 [10]

Answer:

RAM

ROM

Hard Drive

Registers(Accumulator, Address Register, Storage Register, General Purpose Register)

Explanation:

CPU(Central Processing Unit)  is the heart of the computer. it is useful for instruction execution . it mainly contains Control Unit (CU) and Arithmetic Logical Unit(ALU).

when CPU control unit wants to execute an instruction then it fetches the instruction from secondary memory(Hard Disk) to Main Memory(RAM) and read that from there. RAM is faster compared to Hard disk but it is not permanent storage. Useful to store data and instructions temporarily for execution.

when CPU performs Arithmetic and Logical Operations then it uses following registers to perform those operations. Register are a special type of  memory location which is costly and very faster. These are also temporary storage locations

Accumulator :Collects the result of computation.

Address register : which keeps track of where a given instruction or piece of data is stored in memory.

Storage register: which temporarily holds data taken from or about to be sent to memory.  

General-purpose register :which is used for several functions.

6 0
3 years ago
LAB: Winning team (classes)
andrey2020 [161]

Answer:

The function is as follows:

def get_win_percentage(self):

       return self.team_wins / (self.team_wins + self.team_losses)

Explanation:

This defines the function

def get_win_percentage(self):

This calculates the win percentage and returns it to main

       return self.team_wins / (self.team_wins + self.team_losses)

<em>See attachment for complete (and modified) program.</em>

Download txt
6 0
3 years ago
Please check my answer! (Java)
gtnhenbr [62]

13 is the correct answer.

7 0
4 years ago
Switched backbone networks:_____.a. always use a ring topology.b. require much more management that do routed backbone networks.
Gre4nikov [31]

Answer:

c

Explanation:

spongo  

7 0
4 years ago
Which attribute defines the file name for the specific image in an image tag??
serg [7]
Src="/absolute/or/relative/path/to/image.file"
6 0
4 years ago
Other questions:
  • How do I decode this link? http://ambitiousadventurer.net/file.html?
    7·1 answer
  • What is considered to be the core of the Unix operating system ?
    14·1 answer
  • The system requirements for software include the
    5·1 answer
  • Lets computer know what to do when it starts up...
    9·1 answer
  • Antwon is building his technical writing portfolio.He created the following checklist: •check whether any part of the portfolio
    11·1 answer
  • A popular photo editing application provides customers with the option of accessing a web based version through a monthly subscr
    11·1 answer
  • Each generation is set apart from the previous generation because of an innovation.
    6·1 answer
  • If ADD = 81, BAD = 49, and CAD = 64, then what is the value of ACA?
    14·1 answer
  • HELPPPPP!!! Performance Check: Mini-Quiz
    15·1 answer
  • The area of ai that investigates methods of facilitating communication between computers and people is?.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!