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
Afina-wow [57]
3 years ago
7

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. Save the application as ValidateCheckDigits.java.
Computers and Technology
1 answer:
grigory [225]3 years ago
3 0

Answer:

Explanation:

The following code is written in Java. It reads every input and checks to see if it is valid. If it is it writes it to the output file.

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

class Brainly {

           public static void main(String[] args) {

               try {

                   File myObj = new File("C:/Users/Gabriel2/AppData/Roaming/JetBrains/IdeaIC2020.2/scratches/input.txt");

                   Scanner myReader = new Scanner(myObj);

                   FileWriter myWriter = new FileWriter("C:/Users/Gabriel2/AppData/Roaming/JetBrains/IdeaIC2020.2/scratches/output.txt");

                   while (myReader.hasNextLine()) {

                       String data = myReader.nextLine();

                       int sum = 0;

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

                           sum += data.charAt(x);

                       }

                       int remainder = (sum % 10);

                       System.out.println(remainder);

                       System.out.println(data.charAt(5));

                       if (remainder == Integer.parseInt(String.valueOf(data.charAt(5)))) {

                           System.out.println("entered");

                           try {

                               myWriter.write(data + "\n");

                               System.out.println("Successfully wrote to the file.");

                           } catch (IOException e) {

                               System.out.println("An error occurred.");

                               e.printStackTrace();

                           }

                       }

                       sum = 0;

                   }

                   myWriter.close();

                   myReader.close();

               } catch (FileNotFoundException e) {

                   System.out.println("An error occurred.");

                   e.printStackTrace();

               } catch (IOException e) {

                   e.printStackTrace();

               }

           }

       }

You might be interested in
I got enough points and enough brainliests how do I move on to my next rank?
emmasim [6.3K]

Answer: what do you mean exactly?

6 0
3 years ago
Read 2 more answers
Which of the following items are typically included in a balanced budget A. The amount you earn in income
taurus [48]
D is the correct answer

8 0
3 years ago
Requests to access specific cylinders on a disk drive arrive in this order: 24, 20, 4, 40, 6, 38, and 12, and the seek arm is in
GarryVolchara [31]

Answer:

The time required to seek using First come,first served algorithm is 876 milliseconds.

The time required to seek using Shortest Seek Time First algorithm is 360 milliseconds.

The time required to seek using LOOK (initialing moving upwards) algorithm is 348 milliseconds.

Explanation:

Part a,b : First-come, first-served:

The order of the cylinders is as 10, 22, 20, 2, 40, 6, 38

10 + 12 + 2 + 18 + 38 + 34 + 32 = 146 cylinders = 876 milliseconds.

ii) Shortest Seek Time First:

The order of the cylinders is as 20, 22, 10, 6, 2, 39, 40

0 + 2 + 12 + 4 + 4 + 36 + 2 = 60 cylinders = 360 milliseconds.

iii) LOOK (initialing moving upwards):

The order of the cylinders is as 20, 22, 38, 40, 10, 6, 2

0 + 2 + 16 + 2 + 30 + 4 + 4 = 58 cylinders = 348 milliseconds.

7 0
3 years ago
python There is a reference variable office_a_c of type AirConditioner. Create a new object of type AirConditioner using the off
Kay [80]

Answer:

  1. class AirConditioner:
  2.  def __init__(self, a_c=False):
  3.    self.office_a_c = a_c  
  4. ac = AirConditioner()
  5. ac.office_a_c = True

Explanation:

Firstly, create a class and name it as AirConditioner (Line 1).

Next in the class constructor, create the reference variable office_a_c (Line 3). Please note the reference variable shall be preceded with a self keyword. Besides, the reference variable is set to False by default.

Create an AirConditioner object (Line 6) and then use the dot syntax (.) to set the object reference variable office_a_c to True.

8 0
3 years ago
How can photography allow us to view the world around us in different ways?
Nimfa-mama [501]
Photography allows us to view the world around us in different ways, by giving us the sense and feel of what others feel, Photography is art. You are able to use photography to define actions, for example happiness in a marriage or happiness in children playing at the park. Photography also allows you to explore and discover new things, and make something out of that. It makes you think a bout different ways to change the world around you, how do you define the world?
7 0
2 years ago
Read 2 more answers
Other questions:
  • Whoever helps me with these questions i will help them with the same number of questions in any subject: 1. As the operations ma
    14·1 answer
  • Sarah is entering weekly sales data for week 37 of the current year; however, when she moves down to thecells where she needs to
    8·2 answers
  • What are the coordinates of (3 comma space 8 )relative to the basis open curly brackets space (1 comma space 1 )comma space (0 c
    15·1 answer
  • The number 84 is divisible by 2,3,4 and 6. true or false
    13·2 answers
  • Write a filter that reads in a sequence of integers and prints the integers, removing repeated values that appear consecutively.
    5·2 answers
  • Which line of code will create an instance of the pet class?
    13·2 answers
  • What is considered appropriate dress for men and women in the workplace? Select all that apply.
    6·2 answers
  • Why are computer simulations useful in studying phenomena in the universe?
    15·1 answer
  • How to scan a screenshot on Brainly?
    9·2 answers
  • Please help with this question
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!