When submitting this lab, submit a .java file called FormLetter, and create the following structure in Eclipse: Package Name: week13 Class Name: FormLetter Write a program that will read a CSV file containing scores for student assignments, and create a letter saved to a file for each student who has one or more scores of 0, and then print out messages to the console indicating which students have letters written (as show in the example run). In this program you will combine data from the CSV file and the TXT file to create a letter to each student in the class who is missing one or more assignments. The letter must have the following format: , Each letter file must be saved with the following naming format: Warning letter to student - .txt Downloads For this lab you will need to download the file Student Assignment Scores.csv. This file contains a list of students and the scores they received for 6 class assignments. Place this file in your PROJECT directory. You will also need to download the file Warning Letter to Students -.txt. This file contains the body of a form letter to students who are missing assignments. Place this file in your PROJECT directory. Steps Use techniques acquired in previous labs to create two Scanner objects. One Scanner will point to the "Student Assignment Grades.csv" file One Scanner will point to the "Warning Letter to Student - .txt" file Read the full text of the "Warning Letter to Student - .txt" file and store it in a String variable. Read in the text from the "Student Assignment Grades.csv" file, one line at a time and store it in an array using split() For each student: Use methods you have learned in other labs to determine if a student has any assignments with a grade of "0" If a student has at least 1 grade of "0": Use PrintWriter to create a new text file for them (or any other method of file creation you prefer). Make sure the name of the file is in the format described above. Print the first line of the file using text and the student's name as shown in the Example Run. Print the rest of the letter. Remember it is already stored in a single string. Use a for loop to evaluate each grade for the student. If the grade is "0", print text to the file indicating the Assignment number as shown in the Example Run. Close the PrintWriter. Reading an entire file into a String Variable The Scanner has several different methods you are not fully familiar with. .next() - The .next() method retrieves the next 'token' from the scanner input. But what is a token? A token is the next segment of text that comes from the Scanner before the next delimiter. But what is a delimiter? A delimiter is a String or pattern what defines how tokens are broken up in an input stream. By default, a Scanner's delimiter is white space. Therefore, the .next() method will read in all the characters from the input stream until it reaches the next white space where it will stop. .useDelimiter() - The .useDelimiter() method can be used to change the delimiter for the scanner. For example, calling .useDelimiter(",") will change the behavior of .next(). After setting the delimiter to "," the .next() method will read in all characters from the input stream until it reaches the next "," where it will stop. By setting the delimiter to a value you know is not found anywhere in an input file, and then calling .next(), you can successfully read the entire contents of a file into a String variable. Example: Scanner letter = new Scanner(letterFile); //Create a new Scanner object (letter) that points to a File. letter.useDelimiter("\\Z"); //Change the delimiter of the letter Scanner object to "\\Z" since you know that the string "\\Z" is not found anywhere in your .txt file. String letterBody = letter.next(); // .next() will read the entire contents of the file since the delimiter "\\Z" is not found in the .txt file. The String letterBody now contains the entire contents of the file. Example Run Your program output should look like this: Creating letters for: Garrett Wang Ethan Phillips Roxann Dawson Robert Beltran Robert McNeil Armin Shimerman Dominic Keating John Billings Before you run your program, your directory should look like this: Form Letter Creation - Befor.jpg After you run your program, your directory should look like this: Form Letter Creation - After.jpg Opening one of the sample letter files in a document editor should look like this: Letter.jpg
When submitting this lab, submit a .java file called FormLetter, and create the following structure in Eclipse: Package Name: week13 Class Name: FormLetter Write a program that will read a CSV file containing scores for student assignments, and create a letter saved to a file for each student who has one or more scores of 0, and then print out messages to the console indicating which students have letters written (as show in the example run). In this program you will combine data from the CSV file and the TXT file to create a letter to each student in the class who is missing one or more assignments. The letter must have the following format: , Each letter file must be saved with the following naming format: Warning letter to student - .txt Downloads For this lab you will need to download the file Student Assignment Scores.csv. This file contains a list of students and the scores they received for 6 class assignments. Place this file in your PROJECT directory. You will also need to download the file Warning Letter to Students -.txt. This file contains the body of a form letter to students who are missing assignments. Place this file in your PROJECT directory. Steps Use techniques acquired in previous labs to create two Scanner objects. One Scanner will point to the "Student Assignment Grades.csv" file One Scanner will point to the "Warning Letter to Student - .txt" file Read the full text of the "Warning Letter to Student - .txt" file and store it in a String variable. Read in the text from the "Student Assignment Grades.csv" file, one line at a time and store it in an array using split() For each student: Use methods you have learned in other labs to determine if a student has any assignments with a grade of "0" If a student has at least 1 grade of "0": Use PrintWriter to create a new text file for them (or any other method of file creation you prefer). Make sure the name of the file is in the format described above. Print the first line of the file using text and the student's name as shown in the Example Run. Print the rest of the letter. Remember it is already stored in a single string. Use a for loop to evaluate each grade for the student. If the grade is "0", print text to the file indicating the Assignment number as shown in the Example Run. Close the PrintWriter. Reading an entire file into a String Variable The Scanner has several different methods you are not fully familiar with. .next() - The .next() method retrieves the next 'token' from the scanner input. But what is a token? A token is the next segment of text that comes from the Scanner before the next delimiter. But what is a delimiter? A delimiter is a String or pattern what defines how tokens are broken up in an input stream. By default, a Scanner's delimiter is white space. Therefore, the .next() method will read in all the characters from the input stream until it reaches the next white space where it will stop. .useDelimiter() - The .useDelimiter() method can be used to change the delimiter for the scanner. For example, calling .useDelimiter(",") will change the behavior of .next(). After setting the delimiter to "," the .next() method will read in all characters from the input stream until it reaches the next "," where it will stop. By setting the delimiter to a value you know is not found anywhere in an input file, and then calling .next(), you can successfully read the entire contents of a file into a String variable. Example: Scanner letter = new Scanner(letterFile); //Create a new Scanner object (letter) that points to a File. letter.useDelimiter("\\Z"); //Change the delimiter of the letter Scanner object to "\\Z" since you know that the string "\\Z" is not found anywhere in your .txt file. String letterBody = letter.next(); // .next() will read the entire contents of the file since the delimiter "\\Z" is not found in the .txt file. The String letterBody now contains the entire contents of the file. Example Run Your program output should look like this: Creating letters for: Garrett Wang Ethan Phillips Roxann Dawson Robert Beltran Robert McNeil Armin Shimerman Dominic Keating John Billings Before you run your program, your directory should look like this: Form Letter Creation - Befor.jpg After you run your program, your directory should look like this: Form Letter Creation - After.jpg Opening one of the sample letter files in a document editor should look like this: Letter.jpg
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
When submitting this lab, submit a .java file called FormLetter, and create the following structure in Eclipse:
Package Name: week13
Class Name: FormLetter
Write a program that will read a CSV file containing scores for student assignments, and create a letter saved to a file for each student who has one or more scores of 0, and then print out messages to the console indicating which students have letters written (as show in the example run). In this program you will combine data from the CSV file and the TXT file to create a letter to each student in the class who is missing one or more assignments. The letter must have the following format:
,
Each letter file must be saved with the following naming format:
Warning letter to student - .txt
Downloads
For this lab you will need to download the file Student Assignment Scores.csv. This file contains a list of students and the scores they received for 6 class assignments. Place this file in your PROJECT directory. You will also need to download the file Warning Letter to Students -.txt. This file contains the body of a form letter to students who are missing assignments. Place this file in your PROJECT directory.
Steps
Use techniques acquired in previous labs to create two Scanner objects.
One Scanner will point to the "Student Assignment Grades.csv" file
One Scanner will point to the "Warning Letter to Student - .txt" file
Read the full text of the "Warning Letter to Student - .txt" file and store it in a String variable.
Read in the text from the "Student Assignment Grades.csv" file, one line at a time and store it in an array using split()
For each student:
Use methods you have learned in other labs to determine if a student has any assignments with a grade of "0"
If a student has at least 1 grade of "0":
Use PrintWriter to create a new text file for them (or any other method of file creation you prefer).
Make sure the name of the file is in the format described above.
Print the first line of the file using text and the student's name as shown in the Example Run.
Print the rest of the letter. Remember it is already stored in a single string.
Use a for loop to evaluate each grade for the student. If the grade is "0", print text to the file indicating the Assignment number as shown in the Example Run.
Close the PrintWriter.
Reading an entire file into a String Variable
The Scanner has several different methods you are not fully familiar with.
.next() - The .next() method retrieves the next 'token' from the scanner input. But what is a token? A token is the next segment of text that comes from the Scanner before the next delimiter. But what is a delimiter? A delimiter is a String or pattern what defines how tokens are broken up in an input stream. By default, a Scanner's delimiter is white space. Therefore, the .next() method will read in all the characters from the input stream until it reaches the next white space where it will stop.
.useDelimiter() - The .useDelimiter() method can be used to change the delimiter for the scanner. For example, calling .useDelimiter(",") will change the behavior of .next(). After setting the delimiter to "," the .next() method will read in all characters from the input stream until it reaches the next "," where it will stop.
By setting the delimiter to a value you know is not found anywhere in an input file, and then calling .next(), you can successfully read the entire contents of a file into a String variable.
Example:
Scanner letter = new Scanner(letterFile); //Create a new Scanner object (letter) that points to a File.
letter.useDelimiter("\\Z"); //Change the delimiter of the letter Scanner object to "\\Z" since you know that the string "\\Z" is not found anywhere in your .txt file.
String letterBody = letter.next(); // .next() will read the entire contents of the file since the delimiter "\\Z" is not found in the .txt file. The String letterBody now contains the entire contents of the file.
Example Run
Your program output should look like this:
Creating letters for:
Garrett Wang
Ethan Phillips
Roxann Dawson
Robert Beltran
Robert McNeil
Armin Shimerman
Dominic Keating
John Billings
Before you run your program, your directory should look like this:
Form Letter Creation - Befor.jpg
After you run your program, your directory should look like this:
Form Letter Creation - After.jpg
Opening one of the sample letter files in a document editor should look like this:
Letter.jpg
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 6 steps with 4 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education