CSE 2010: Asgn #1, Excel-lent

Due: Monday, 18 May 2009 (midnight)

The Task

A certain spreadsheet program labels the columns of a spreadsheet using letters. Column 1 is labeled as "A", column 2 as "B", ..., column 26 as "Z". When the number of columns is greater than 26, another letter is used. For example, column 27 is "AA", column 28 is "AB" and column 52 is "AZ". It follows that column 53 would be "BA" and so on. Similarly, when column "ZZ" is reached, the next column would be "AAA", then "AAB" and so on. The rows in the spreadsheet are labeled using the row number. Rows start at 1. The designation for a particular cell within the spreadsheet is created by combining the column label with the row label. For example, the upper-left most cell would be "A1". The cell at column 55 row 23 would be "BC23". You will write a simple program, Excel.java, which converts numeric row and column values into the spreadsheet designation. Input. Input consists of lines of the form: RnCm. n represents the row number, 1≤ n < 300,000,000; and m represents the column number, 1 ≤ m < 300,000,000. The values n and m define a single cell on the spreadsheet. Input terminates with the line: R0C0 (that is, n and m are 0). There will be no leading zeroes or extra spaces in the input. Output. For each line of input (except the terminating line), you will print out the spreadsheet designation for the specified cell as described above. Here is some sample input:
R1C1
R3C1
R1C3
R299999999C26
R52C52
R53C17576
R53C17602
R0C0
The corresponding output for the sample input above is:
A1
A3
C1
Z299999999
AZ52
YYZ53
YZZ53

Standard Input/Output

The standard input is the stream of characters that the Java program finds in the InputStream called System.in. The standard input is associated with keyboard by default, but can be associated with the file as in
java Excel < data
Now the characters found in the standard input come from the file named data. When the standard input comes from the keyboard a signal of some kind is needed to indicate from the interactive user when the end-of-file is reached because the length of the "file" cannot be known in advance. This signal is understood by the operating system which then passes it to the program. Different operating systems provide different mechanisms for doing this. In Unix the usual signal is typing control-D (in Dos, control-Z) on a line by itself. (Typing control-D in the middle of the line may have the effect of putting the u0004 character in the input stream instead of signaling end-of-file.)

The standard output is the stream of characters that the Java program writes to the PrintStream called System.out. The standard output is associated with the computer display by default, but can be associated with the file as in

java Excel > output
Now the output is collected in the file named output. Since keystrokes are echoed on the display, it is sometimes hard for the user to distinguish which characters on the display correspond to the standard input and which characters to the standard output. From the point of view of the program no such confusion exists.

Using standard input and standard output for IO is very flexible. The user of the program (instead of the program writer) can decide whether to type in the input or put the input in a some file. If the program was written to take input from a particular file, the user of the program has no choice.

Java Input

Here is a program fragment to read the standard input and write it to the standard output.
final Scanner s = new Scanner (new BufferedInputStream (System.in));

while (s.hasNextLine()) {
   final String line = s.nextLine();
   System.out.println (line);
}
It will be necessary to include:
import java.util.Scanner;
import java.io.BufferedInputStream;

To read a number of integers (delimited by white space) do:

final Scanner s = new Scanner (new BufferedInputStream (System.in));

while (s.hasNextInt()) {
   final int n = s.nextInt();
   System.out.println (n);
}
If the input has a sentenal value do:
final Scanner s = new Scanner (new BufferedInputStream (System.in));

for (;;) {
   final int n = s.nextInt();
   if (n==0) break;
   System.out.println (n);
}

Using regular expressions it is possible to change the delimiters used by the scanner class:

final Scanner s = new Scanner (new BufferedInputStream (System.in).useDelimiter ("[RC\\s]+");
This makes any sequence of white space characters, R's, or C's, a delimiter.

Helpful Stuff

Turning it in

Turn in the Java source code for the program using the submission server. The file name should be Excel.java and the project is asgn01. Be sure your name is in comments at the beginning of your program as required in the standard header for this class. For your convenience, here is a submission form for this assignment.

File 1
Control code:
Course=cse2010
Project=asgn01


Ryan Stansifer <ryan@cs.fit.edu>
Last modified: Mon May 18 17:39:38 EDT 2009