Colorado State University

CS160: Foundations in Programming

Command-line arguments, methods


The purpose of this lab is to gain more experience in working with command-line arguments, strings, and methods.

Instructions

Remember the Caesar Cipher? In this lab, you will write a command-line version of that. Your program will take, as command-line arguments:
first argument:
a number, indicating how far to rotate
all subsequent arguments:
strings to rotate
The program will take the strings, rotate them the appropriate amount, and print the result.

Sample runs

   % javac rotate.java
   % java rotate 1 Jack Applin
   Kbdl Bqqmjo
   % java rotate 13 I love CSU!
   V ybir PFH!
   % java rotate 13 pyrex
   clerk
   % java rotate 25 Uibolthjwjoh
   Thanksgiving
   % java rotate
   usage: <rotation> <strings>

Requirements

Method

To accomplish this, you must define a method called rotchar, which takes, as arguments, the rotation amount, and a character to rotate. rotchar will return the rotated character.

For extra fame & glory


Submit the printout of your program to your GTA to get credit for this lab.
© 2009 CSU