import java.util.Scanner;
class Ideone {
private static Scanner input;
public static void print
(String message
){ }
public static void main
(String[] args
) { input
= new Scanner
(System.
in); System.
out.
println("Enter course code to validate i.e. IT2249: "); //assign value to input
String code
= input.
nextLine();
// split into first letter and second letter from course code
boolean fail = false;
char firstLetter = code.charAt(0);
char secondLetter = code.charAt(1);
if(code.length() != 6){
print("Course code is incorrect, it should have 6 characters. Like - iT1234.");
fail = true;
}
else if(firstLetter != 'i' && firstLetter != 'I'){
//print("First letter should be `i` or `I`.");
fail = true;
}
else if(secondLetter != 't' && secondLetter != 'T'){
//print("Second letter should be `t` or `T`.");
fail = true;
}
else{
String lastFour
= code.
substring(2); try{
int courseCde
= Integer.
parseInt(lastFour
); }
fail = true;
//print("All last four characters of course should be numbers.");
}
}
if(!fail)
print("Right course code!");
else if(code.length() == 6){
for(int i = 0; i < 6; i++){
checkForChar(code.charAt(i), i+1);
}
print("Wrong input format!");
}
}
public static void checkForChar(char ch, int pos){
if(pos == 1 && ch != 'i' && ch != 'I')print("First letter should `i` or `I` instead of " + ch);
else if(pos == 1){print(pos + " is correct choice.");return;}
if(pos == 2 && ch != 't' && ch != 'T')print("Second letter should `t` or `T` instead of " + ch);
else if(pos == 2){print(pos + " is correct choice.");return;}
if(pos > 2){
try{
print(pos + " is correct choice.");
}
print(pos + " should be digit instead of " + ch);
}
}
}
}