Introduction
:key
key key key
Key keyabcdef………26
Requirement
Programming Project 1 - Due: Monday, February 20 at 11:59 PM
Note: Submission of this project with a passing score is a requisite for continuing with the course.
There is no grace period for this project. Please submit by the deadline.
Having heard you are studying Computer Science, your boss has come to ask for your help with
a simple task. She would like you to write a simple program that encodes and decodes “secret
messages” which she plans to demonstrate to elementary school students to kindle their interest in CS.
The students have long been asking for a program to use to encrypt their IMs so this is a great
opportunity to put your skills to use.
The encoding/decoding scheme is very simple. Each letter is substituted by some other letter
according to a given mapping such as the one shown below.
abcdefghijklmnopqrstuvwxyz
kngcadsxbvfhjtiumylzqropwe
For example, with the mapping above, every ‘a’ becomes a ‘k’ when encoding a text, and every
‘k’ becomes an ‘a’ when decoding.
You will write a program, Project1.java, which asks the user to enter a key string like above. If
the key is valid, the program asks the user to enter the name of the file which they would like to encode
with the given key. The program will then read the file and output to the console its encoded contents.
If the key supplied is not valid (the mapping should be complete and each letter should map to a unique
letter; e.g. a->k and f->k is not valid), the program rejects the key and asks for another key until a valid
key is entered.
Capital letters are mapped the same way as the lower case letters above, but remain capitalized.
For example, with the key above, every ‘A’ becomes a ‘K’ when encoding a text. Numbers and other
characters are not encoded and remain the same.
Below are two separate runs of the program:
Run 1:
Enter encoding key: maxnrslkbpwfzjidouetchgvyq
Enter the file name: sampleInput.txt
** Encoded Contents **
Grfxizr ti XE 20A!
Xizdctrue mur liin mt siffigbjl bjetucxtbije, act jit mt urmnbjl yicu zbjn.
Bs yic mctizmtr m zree, yic lrt mj mctizmtrn zree.
**
Good Bye!
Run 2:
Enter encoding key: key
Key is not valid.
Enter encoding key: sjwkvputqhoe
Key is not valid.
Enter encoding key: s5wkvputqhoenzlyrabxigmdcf
Key is not valid.
Enter encoding key: jjwkvputqhoenzlyrabxigmdcf
Key is not valid.
Enter encoding key: sjwkvputqhoenzlyrabxigmdcf
Enter the file name: sampleInput.txt
** Encoded Contents **
Mvewlnv xl WB 20J!
Wlnyixvab sav ullk sx pleelmqzu qzbxaiwxqlzb, jix zlx sx avskqzu clia nqzk.
Qp cli sixlnsxv s nvbb, cli uvx sz sixlnsxvk nvbb.
**
Good Bye!
Hints:
– This program is really simple and is meant as a warm up exercise and to ensure we are all on
the same page before we get started with the course.
– Think about breaking down the problem into simple methods that perform. one task only.
– Figure out a simple way to test whether a character is between a and z or between A and Z and
ignore any other characters.
– To find the mapping for a letter (e.g. ‘a’ and ‘A’ go to index 0, ‘b’ and ‘B’ to index 1, etc.)
recognize that you can treat a char as a number and do math with it (e.g. ‘a’ – ‘a’ = 0)
– Use the Scanner class to get input from the user or from the file. E.g.:
import java.util.Scanner;
…
Scanner scanner = new Scanner(System.in);
// Scanner scanner = new Scanner(new File(filename));
System.out .println(“Enter a line of text”);
String text = scanner.nextLine();
System.out .println(“You entered “ + text);
…
scanner.close();
Deliverables:
You should submit a zip file named project1_first_last.zip (where first and last are your first
and last name) containing ONLY the 2 files below.
Project1.java
report.txt (a text file please, no .doc, .jpeg, …) containing:
1- a 1 to 10 lines paragraph from you saying “I have tested this program and there are no
known issues.” if you believe that to be the case, or a brief description of known issues
in case your program has known problems or you could not fully implement it.
2- the output of your program with two invalid keys and then the valid key
bcigjqdrnwvflhapxkyeosztmu and the given sampleInput.txt file.
How you get points:
- Functionally correct solution 80 points
- Clear program decomposition, comments
and good programming style. 20 points
Solutions that are mostly hardcoded (e.g.: if you use a 26 way if/else if statement like “if
‘a’ then …, else if ‘b’ then …, else if …” or similar code) will not be accepted.
How you lose points:
– If your program is not broken down into methods, each one performing a clear task.
– If your program’s output is not the same as the samples given above. Your program should
output an exact replica of the output above when given the same input.
– If any of your code prints anything at all on the console except for the required output. Remove
all your print outs, debug statements, etc. Clean up your code and do not leave clutter
behind.
– If your code has no comments where needed. Comment your code appropriately. Brief and
to the point.
– If you submit your whole workspace or executable files. Submit only the .java file the project
asks for.