I have to make a program that reads a text file and checks the 8 pieces of data on each line for certain criteria. I got the program to read the text file correctly, and I've implemented a tokenizer to split up the text file data into the 8 separate tokens. I need to find a good way to test the tokens against possible errors. Any easy ways to do this? Here are the errors list.
CODE ERROR
A Invoice code is too short
B Invoice code does not have the right characters
C Invoice code digits are all zero
D Name field has fewer than two words
E Name field has more than four words
F Name field has no comma
G Name field has a bad title
H Name field has a bad initial
I Sale price has no decimal point
J Sale price has more than one decimal point
K Sale price has a leading zero
L Genre has bad symbols (contains upper case letter or contains symbols)
M Order date is not six characters
N Order date is not all digits
P Order date is not a legal date
Q Shipping date is not six characters
T Shipping date is not all digits
U Shipping date is not a legal date
V Unclassified error
Each field could have up to one error. Thus, each record could have up to six errors. Each field should be checked for errors in the order that the above errors are listed.INVOICE CODE exactly 6 characters
CUSTOMER NAME maximum 30 characters
SALE PRICE maximum 8 characters
GENRE maximum 10 characters
ORDER DATE exactly 6 characters
SHIPPING DATE exactly 6 characters
These fields are separated by a semicolon.
Invoice code is supposed to be three upper case letters followed by three digits where at least one digit is not zero.
The customer name should be in the form last name followed by a comma, then optional title, first name, and optional middle initial. Titles must be one of Mr., Mrs., Dr., Miss, or Ms. Middle initials must be an upper case letter followed by a period. The words should be delimited by a single space.
The sale price has two decimal digits to the left of the decimal point. The price should have no leading zero.
The genre should only contain lowercase letters.
The two dates should be in MMDDYY format where all six characters are digits.
The dates must be legal dates. The order date/shipping date may not be after today’s date.
Here is my full code:
package Project3;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new FileReader("movie.dat"));
String line;
String token;
String delimiter = ";";
StringTokenizer tokenizer;
while((line = in.readLine()) != null){
tokenizer = new StringTokenizer(line, delimiter);
while (tokenizer.hasMoreTokens()){
token = tokenizer.nextToken();
System.out.print("Invoice Code: "+token+" ");
if(token.length() == 6 ){
}
else{
System.out.println("A");
}
if()
token = tokenizer.nextToken();
System.out.print("Customer Name: "+token+" ");
token = tokenizer.nextToken();
System.out.print("Sale Price: "+token+" ");
token = tokenizer.nextToken();
System.out.print("Genre: "+token+" ");
token = tokenizer.nextToken();
System.out.print("Order Date: "+token+" ");
token = tokenizer.nextToken();
System.out.print("Shipping Date: "+token+" ");
}
System.out.println();
}
in.close();
}
}