Question

In: Computer Science

This week we really want to learn about a file I/O in Java. In Java: 1)...

This week we really want to learn about a file I/O in Java.

In Java:

1) Create a plain empty text file named contacts.

2) Populate the text file with a person's name and account number on each line(Joe Doe 123456789). Create 10 accounts.

3) Store that file in the same location as your project

4) Write a program that will find that file and load it into the computers memory.

5) Read each line of the file and print the associated name but NOT the account number (remember the account number is 9 characters fixed)

Solutions

Expert Solution

Java Code:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {

   public static void main(String[] args) throws FileNotFoundException {
       //creating a scanner
       Scanner sc = new Scanner(new File("contacts.txt"));
       //while there is lines in the file
       while(sc.hasNext()) {
           //get the line
           String line = sc.nextLine();
           //print the part of the line that has the name
           System.out.println(line.substring(0, line.length()-9));
       }

   }

}

Sample Output:

Joe Doe
Test1
Test2
Test3
Test4 LastName
Test5
Test6
Test7
Test8
Test9

contacts.txt

Joe Doe 123456789
Test1 546738219
Test2 673821123
Test3 821123456
Test4 LastName 123456175
Test5 456175895
Test6 175895164
Test7 895164841
Test8 164841724
Test9 841724473


Related Solutions

This week we will learn about the "They Say I Say" thesis statement. You will use...
This week we will learn about the "They Say I Say" thesis statement. You will use this type of thesis statement in your essay writing. This type of statement allows you to establish a place within the conversation of the subject rather then simply just present your view. It requires that you combine your prior knowledge with other's views and can established a thoughtful, educated and credible argument. You have been preparing for this with your prior active reading and...
This week, we learn about regression analysis and regression “models’.
This week, we learn about regression analysis and regression “models’. Discuss the role of regression analysis in business by using examples of how these models might work to make predictions. In your discussion, consider the various components of the output and how it might be of value to understanding the data.
From the reading this week, you will learn about the basic model that we use to...
From the reading this week, you will learn about the basic model that we use to explain the entire economy, aggregate demand-aggregate supply. All of the macroeconomic material is related to this model: GDP, inflation, unemployment. In chapter 12, you’ll read about how fiscal policy can affect the economy. The fiscal policy tools that you read about in this chapter are meant to adjust the aggregate demand side of the economy. But there is a debate about whether this is...
Question 1: As an Agile Professional, I want to learn the purpose of Iteration, so that I...
Question 1: As an Agile Professional, I want to learn the purpose of Iteration, so that I can help prepare my team to begin building our product.  Question 2:  As an Agile Professional, I want to learn the practice of requirements elaboration so that I can better specify acceptance criteria for stories.  Question 3: As an Agile Professional, I want to learn the practice of backlog grooming so that I can help my team to maintain and prioritize our story backlog.  Question 4:...
In our chapter reading this week, we learn more about setting up a sample company in...
In our chapter reading this week, we learn more about setting up a sample company in QuickBooks Online. We explore how to customize a chart of accounts, explore lists, and navigate the various areas for customers, vendors and employees. Which feature do you like most so far in your navigation of QuickBooks Online?
This week we learn about the Statement of Cash Flows (Chapter 14). This week's discussion questions...
This week we learn about the Statement of Cash Flows (Chapter 14). This week's discussion questions are as follows: 1). What is the reporting purpose of the statement of cash flows? Why is this important to investors? 2). Summarize the three types of cash flow activities, and describe at least 2 types of cash flows in EACH type of activity 3). Is depreciation a source of cash flow? Why or why not?
I want to learn about increasing and decreasing, who have higher and who have less if...
I want to learn about increasing and decreasing, who have higher and who have less if we have four choices. Please show like what to do for this type of questions. Electronegativity Size of atom Which molecules are polar and non-polar Atomic radius Ionization energy
Pick one of the major psychological disorders we learn about this week (Mood Disorders, Anxiety Disorders,...
Pick one of the major psychological disorders we learn about this week (Mood Disorders, Anxiety Disorders, Posttraumatic Stress Disorder, Dissociative Disorders, Personality Disorders). Given what we know about the different types of therapy, how would you go about treating the disorder? Please be sure to explain your reasoning. Do you feel this type of therapy is generally the best? Why?
We start the week by introducing polynomials. We will learn how to identify and simplify polynomials....
We start the week by introducing polynomials. We will learn how to identify and simplify polynomials. We will also learn how to find the greatest common factor (GCF) among them. As our knowledge of polynomials grows, we will then move on to factoring trinomials. For your first post, search online for an article or video that describes how polynomials can be used in the real world. Provide a one paragraph summary of the article or video in your own words.
1)I want essay about mood disorders and suicide.? 2) I want essay about substance related and...
1)I want essay about mood disorders and suicide.? 2) I want essay about substance related and addictive disorders? 3)I want essay about somatic symptom and related disorders? please send typing answer because I don't understand handwriting.Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT