2006 ISC PRACTICAL #3 QUESTION SOLVED!

2006 ISC PRACTICAL QUESTION SOLVED!




A new advanced Operating System, incorporating the latest hi-tech features has been designed by Opera Computer System. The task of generating copy protection codes to prevent software piracy has been entrusted to the Security Department. The security department has decided to have codes containing a jumbled combination of alternate uppercase letters of the alphabet starting from A upto K (namely among A,C,E,G,I,K). The codes may or may not be in the consecutive series of alphabets.


Develop a program to input a code and its length. At the first instance of an error display “Invalid!” stating the appropriate reason. In case of no error, display the message “Valid!”

Test your program for the following data and some random data.

SAMPLE DATA
INPUT
N = 4
ABCE
OUTPUT
Invalid! Only alternate letters permitted!
INPUT
N = 4
AcIK
OUTPUT
Invalid! Only upper case letters permitted!
INPUT
N = 4
AAKE
OUTPUT
Invalid! Repetition of characters not permitted!
INPUT
N = 7
OUTPUT
Error! Length of string should not exceed 6 characters!
INPUT
N = 4
AEGIK
OUTPUT
Invalid! String length not the same as specified!
INPUT
N = 3
ACE
OUTPUT
Valid!
INPUT
N = 5
GEAIK
OUTPUT
Valid!


PROGRAM:




import java.io.*;
class codes_newApp
{
public static void main(String args[])throws IOException{
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter The Numer Of Alphabets in your KEY");
int p=Integer.parseInt(in.readLine());
if(p>6){
System.out.println("Error! Length of string should not exceed 6 characters!");
}
else{
System.out.println("Enter The Registration Key");
String a=in.readLine();
int done=0;
int len=a.length();
if(len>6){
System.out.println("Error! Length of string should not exceed 6 characters!");
}
else{
if(p!=len){
System.out.println("Invalid! String length not the same as specified!");
}
else{
String rev=a.toUpperCase();
if(a!=rev){
System.out.println("Invalid! Only upper case letters permitted!");
}
else{
for(int i=0;i<len;i++){
char ch=a.charAt(i);
char ch1=a.charAt(i+1);
if(ch==ch1){
System.out.println("Invalid! Repetition of characters not permitted!");
break;
}
else{
ch1=a.charAt(i+1);
if(ch1==++ch){
System.out.println("Invalid! Only alternate letters permitted!");
break;
}
else{
switch(len){
case 2:{
char bb1=a.charAt(0);
char bb2=a.charAt(1);
if(bb1==bb2){
System.out.println("Invalid! Repetition of characters not permitted!");
done=1;
}
break;
}
case 3:{
char bb1=a.charAt(0);
char bb2=a.charAt(1);
char bb3=a.charAt(2);
if((bb1==bb2||bb1==bb3)||(bb2==bb3)){
System.out.println("Invalid! Repetition of characters not permitted!");
done=1;
}
break;
}
case 4:{
char bb1=a.charAt(0);
char bb2=a.charAt(1);
char bb3=a.charAt(2);
char bb4=a.charAt(3);
if((bb1==bb2||bb1==bb3||bb1==bb4)||(bb2==bb3||bb2==bb4)||(bb3==bb4)){
System.out.println("Invalid! Repetition of characters not permitted!");
done=1;
}
break;
}
case 5:{
char bb1=a.charAt(0);
char bb2=a.charAt(1);
char bb3=a.charAt(2);
char bb4=a.charAt(3);
char bb5=a.charAt(4);
if((bb1==bb2||bb1==bb3||bb1==bb4||bb1==bb5)||(bb2==bb3||bb2==bb4||bb2==bb5)||(bb3==bb4||bb3==bb5)||(bb4==bb5)){
System.out.println("Invalid! Repetition of characters not permitted!");
done=1;
}
break;
}
case 6:{
char bb1=a.charAt(0);
char bb2=a.charAt(1);
char bb3=a.charAt(2);
char bb4=a.charAt(3);
char bb5=a.charAt(4);
char bb6=a.charAt(5);
if((bb1==bb2||bb1==bb3||bb1==bb4||bb1==bb5||bb1==bb6)||(bb2==bb3||bb2==bb4||bb2==bb5||bb2==bb6)||(bb3==bb4||bb3==bb5||bb3==bb6)||(bb4==bb5||bb4==bb6)||bb5==bb6){
System.out.println("Invalid! Repetition of characters not permitted!");
done=1;
}
break;
}
default: break;}}
if(done==0){
char f=a.charAt(i);
if(f=='A'||f=='C'||f=='E'||f=='G'||f=='I'||f=='K'){
System.out.println("Valid!!");
break;
}}
else
System.out.println("Out of parameters");
}
}}}}
}}}










1 comment: