340-Java Programming R 2018-Key
340-Java Programming R 2018-Key
ANSWER KEY
Page 1 of 7
JAVA PROGRAMMING
(340)
REGIONAL – 2018
Production Portion:
Your name and/or school name should not appear on work you submit for grading.
1. Create a folder on the flash drive provided using your contestant number as the name of the folder.
2. Copy your entire solution/project into this folder.
3. Submit your entire solution/project so that the graders may open your project to review the source code.
4. Ensure that the files required to run your program are present and will execute on the flash drive provided.
*Note that the flash drive letter may not be the same when the program is graded as it was when you created
the program.
* It is recommended that you use relative paths rather than absolute paths to ensure that the program will run
regardless of the flash drive letter.
The graders will not compile or alter your source code to correct for this.
Submissions that do not contain source code will not be graded.
Development Standards:
Note to Graders: The contestants have been given a file named communications.txt. You must
first delete that file from the contestant’s flash drive and run the program for Test case #1. This
should result in a message that the file was not found. Then replace the file on their flash drive
with the grader’s file with the same name and run Test case #2. You’ll run their program with a
grader’s file named communication.txt which will contain different data than the student file.
This will produce different results than the student’s file. You must copy the grader’s
communication.txt file into the folder where their program runs. Listed below are the test cases
and their results.
Test case #1 verifies that the program checks for the correct input file. The output wording does
not need to be exact.
Text case #2 processes the correct data file name and produces output. The output wording must
be exact.
Test Case #1
The input file was not found.
Test case #2
transmission 005 confirmed
BPAe>?/eovAr over
Grader’s data
5
5 00421 005 fFe t over
222 00065 002 AA over
333 00550 001 test F over
444 00713 007 fFaover
555 03333 022 check
JAVA PROGRAMMING - REGIONAL 2018
Page 4 of 7
If the program does not execute, then the remaining items in this section receive a score of zero.
The program runs and reads the input file 20 points
The program displays an error message if the file cannot be found 20 points
The program displays the 3-digit transmission number 10 points
The program displays “confirmed” if transmission passes all checks 20 points
The program displays “length error” correctly 20 points
The program displays “check total error” correctly 20 points
The program displays “incomplete transmission error” correctly 20 points
The program displays the encoded original message adding “ over” at the end 30 points
Suggested Solution
/**
* BPA Java Programming Contest : Communications
*
* @author - contestant number goes here
*
* @version January 2017
*
*/
import java.io.FileNotFoundException;
import java.io.*;
import java.util.Scanner;
// This method cleans extra spaces off the ends and removes the " over"
//and returns a cleaned messager for processing
JAVA PROGRAMMING - REGIONAL 2018
Page 6 of 7
originalMessage = originalMessage.trim();
//check to see if message ends in " over". if so remove "over"
message = "";
if(originalMessage.substring(originalMessage.length() - 5).equals(" over"))
message = originalMessage.substring(0,originalMessage.length() - 5);
else
message = originalMessage;
return message;
}
// This method verifies that the check total matches the sum of the chars in the message
//- use cleaned message
public static boolean verifyCheckTotal()
{
int sum = 0;
for(int i = 0;i < message.length(); i++)
{
sum += message.charAt(i);
}
//This method verifies the length of the message matches length transmitted
//- use cleaned message
public static boolean verifyLength() //return true if length received = input length
{
if(messageLength == message.length())
return true;
return false;
}
return originalMessage;
}