$30
1
C S 272/463 Introduction to Data Structures
Lab 1: Eclipse Tutorial and Java File Operations
In this Lab, the students will get familiar with Java file operations and learn how to use Eclipse IDE. If you did
not take any prerequisite courses on Java, you may want to read JavaOverview.pdf on Canvas for an
overview of Java. Please download Lab1.zip from Canvas that contain all files mentioned in this lab
instruction.
1. Task 1 (40 points)
For this Task, create a file named eclipse_test.txt to store the output results. Follow the steps in
the Eclipse tutorial (EclipseTutorial.pdf on Canvas) to create a Java project named Lab1 and do
the following steps:
a) (10 points) Create a Java class Welcome with a main method that prints out "Welcome to
Java"
b) (10 points) Add one line to the main method to print out the current system time. The function
for getting the current system time is System.currentTimeMillis(). Copy the running
results to eclipse_test.txt.
c) (20 points) In class Welcome, create a static method named sum(). This method will read from
the keyboard a line of integers that are separated by a space. You will parse the input to get the
integers, compute the sum of all integers, and print the output result on the computer screen.
Call sum() method in main to test it. Copy the running results to eclipse_test.txt. For this
question, you can use BufferedReader br = new BufferedReader(new
InputStreamReader(System.in)) to read a line from the keyboard. Please check
intro.pptx to know how to parse a line. You may also need to use
Integer.parseInt(String s).
2. Task 2 (60 points)
You are given a text file named pg100.txt. Create a Java file named WordCount.java. In this Java
file:
a) (25 points) Create a read function to read in the text file and count the number of occurrences of
each unique word (case-insensitive) in the text file.
b) (25 points) Create a write function to write all word counts to a file named WordCount.csv. In
this file, each line contains a word and an integer (separated by a space) that is the number of
occurrences of that word.
c) (10 points) Create a main function to properly call the read and write functions that you created.
Please check MyTokenizer.java for an example on how to tokenize text into an array of words. To
run MyTokenizer, make sure that you have the file test_doc.txt. All these files are in the
Lab1.zip on Canvas.
3. Submission instructions
Submit through canvas a zip file consisting of Welcome.java, eclipse_test.txt,
WordCount.java, and WordCount.csv. Please do NOT submit the .class files.
2
4. Grading criteria
a. The score allocation is already put in the questions.
b. Please make sure that you test your code thoroughly by considering all possible test cases.
c. 5 points will be deducted if submitted files (including file types, file names, etc.) do not follow the
instructions.
d. At least 20 points will be deducted if your code cannot be run on CS servers.