In this activity, you will practice a fundamental programming skill: reading data from a file using Java. You will learn how to:
Scanner class to read information from that filefor loop to repeat actionsThese skills are essential for many larger programming tasks you will complete later in the course.
Program Name: DryRun.java
Language: Java
Input File: dryrun.dat
In this program, you will help the emperor create new names for Sith lords. You are given a list of words, and for each one, you must print the word with the title "Darth" in front of it.
Example:
Input word → Vader
Output → Darth Vader
The input file dryrun.dat will contain:
Words may include underscores or hyphens (for example: Jar_Jar, K-Rish).
dryrun.dat):5 Vader Maul Tyranus Jar_Jar K-Rish
Your program should:
dryrun.dat."Darth " + word.For each input word, output a line in this exact format:
Darth <word>
There should be exactly one space between Darth and the word.
Darth Vader Darth Maul Darth Tyranus Darth Jar_Jar Darth K-Rish
n is a positive number.n words.dryrun.dat is in the same folder as DryRun.java when you compile and run the program.If you need help, ask Mr. Cusack.
BEGIN
OPEN the file "dryrun.dat" for input
READ integer n from the file // number of words
REPEAT n times:
READ word from the file
SET sithName = "Darth " + word
OUTPUT sithName to the screen
CLOSE the input file
END
Upload the following four files to your Google Drive (in your class folder) and to Google Classroom:
PX_lastname_dryrunCyWoods.java
PX_lastname_dryrunCyWoods.txt
PX_lastname_dryrunCyWoods.png
PX_lastname_dryrunCyWoods.mp4
Make sure the final output is clearly visible in both the screenshot and the video.
If you get stuck, confused, or see errors—don’t sit quietly. Ask Mr. Cusack for help.