Algorithms and OOD (CSC 207 2013F) : Labs
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Summary: In this laboratory, you will explore the basics of input and output in Java.
Classes Used:a. Review The reading on simple input and output.
b. Create a new project for this lab.
c. Create a new package for this lab.
Write and test a main class called Greet
that prompts the
user for a name, reads a name from the keyboard, and prints a greeting
to the screen. Your output should resemble the following:
What is your name? Sam Have a nice day Sam!
To type a response, you may need to click in the console area of the Eclipse window.
a. Write and test a main class called DumpInfo
that
prints the following three lines to the screen.
b. Update DumpInfo
so that it instead creates a file
and dumps the information to that file.
c. Predict what will happen when you have DumpInfo.java
write to a file that already exists. (For example, if you run it a
second time.)
d. Check your prediction experimentally.
e. Predict what will happen when you modify DumpInfo.java
to write to a file in a classmate's directory.
f. Check your prediction experimentally.
a. Write and test a main class called ShowInfo
that reads a file
of three lines named info
and prints each line preceeded
by a category prompt (Name, Email, Color). For example, if the file contains
J. Doe doej@gmail.com plaid
the output on the screen should be
Name: J. Doe Email: doej@gmail.com Fave Color: plaid
b. Modify info
using gedit and verify that
ShowInfo
continues to work correctly.
a. What do you expect to happen when you run ShowInfo
if info
contains only two lines (e.g., doesn't contain a color)?
b. Check your answer experimentally.
c. What do you expect to happen when you run ShowInfo
if info
does not exist?
d. Check your answer experimentally.
e. What do you expect to happen when you run ShowInfo
using a file in a classmate's directory?
f. Check your answer experimentally.
Write and test a main class, CopyTwoLines
, that copies
the first two lines from a file named source
and places
them in a file named destination
.
Write a test a main class, NewCopier
, that prompts the
user for the name of two files and copies the first two lines from the
first file to the second file.
Write a short main class, ReadTwice
, that prompts
the user for a file, builds a BufferedReader
for the
file, sets a mark, reads the first line from the file, resets the
BufferedReader
, and reads again.
If you finish the lab early, you may want to try some or all of the following.
Determine whether you can use mark
and reset
for input taken from the keyboard in addition to input taken from a
file.
Determine whether you can place more than one mark in a file.
Determine what happens if you read more than readAheadLimit
characters between calls to mark
and reset
. Does
the size of readAheadLimit
make a difference (e.g., do you
get the same behavior for small and large readAheadLimit
if
you read only two characters beyond that limit)?
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013 Samuel A. Rebelsky.
This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.