Ang problema man gud ani...kinanglan ang input sa sets naa sa universal...kung dli mao ang input kinahanglan mangayo siya ug usob....
Code:import java.io.*; public class ProjectMenu{ public static void main (String[]args)throws Exception { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); int option,n1,n2,n3,x=0,y=0,flag,uni; System.out.print("\n\n\t\t\t***CS 212 PROJECT***\n"); System.out.print("\n\n\t\t\t Group 3\n"); System.out.print("\t\t\t Set of Operation\n\n"); System.out.print("\t Union, Intersection and Relative Complement\n\n"); do{ System.out.print("Enter number of elements to input in Universal:"); uni=Integer.parseInt(input.readLine()); }while((uni<1)||(uni>8)); char univer[]=new char[uni]; System.out.print("Enter elements of Universal:\n"); for(x=0;x<uni;x++) { System.out.print("Element["+x+"] "); univer[x]=(char)System.in.read(); System.in.read(); System.in.read(); } do{ System.out.print("Enter number of elements to input in Set A: "); n1=Integer.parseInt(input.readLine()); }while((n1>3)||(n1<1)); char seta[]=new char[n1]; System.out.print("Enter elements of Set A: \n"); for(x=0;x<seta.length;x++) { y=0; do{ System.out.print("Element: "); seta[x]=(char)System.in.read(); System.in.read(); System.in.read(); y++; }while(seta[x]!=univer[y]); } do{ System.out.print("\nEnter number of elements to input in Set B: "); n2=Integer.parseInt(input.readLine()); }while((n2>3)||(n2<1)); char setb[]=new char[n2]; System.out.print("Enter elements of Set B: \n"); for(x=0;x<setb.length;x++) { System.out.print("Element ["+x+"]"); setb[x]=(char)System.in.read(); System.in.read(); System.in.read(); } do{ System.out.print("\nEnter number of elements to input in Set C: "); n3=Integer.parseInt(input.readLine()); }while((n3>3)||(n3<1)); char setc[]=new char[n3]; System.out.print("Enter elements of Set B: \n"); for(x=0;x<setc.length;x++) { System.out.print("Element ["+x+"] "); setc[x]=(char)System.in.read(); System.in.read(); System.in.read(); } System.out.print("\nSet A:\t "); for(x=0;x<n1;x++) { System.out.print(seta[x]+" "); } System.out.print("\nSet B:\t "); for(x=0;x<n2;x++) { System.out.print(setb[x]+" "); } System.out.print("\nSet C:\t "); for(x=0;x<n3;x++) { System.out.print(setc[x]+" "); } while(true) { do{ System.out.print("\n\n\tMenu: "); System.out.print("\n\t[1]Union: "); System.out.print("\n\t[2]Intersection: "); System.out.print("\n\t[3]Relative Complement: "); System.out.print("\nPlease Select(1,2,3): "); option=Integer.parseInt(input.readLine()); if(option==1) union(seta,setb,setc,n1,n2,n3); else if(option==2) intersection(seta,setb,setc,n1,n2,n3); else if(option==3) relative(seta,setb,setc,n1,n2,n3); else System.out.print("invalid input"); }while((option>4)||(option<1)); } } public static void union(char seta[], char setb[], char setc[],int n1, int n2, int n3)throws Exception { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); char un1[]=new char[n1+n2]; char un2[]=new char[n1+n3]; char un3[]=new char[n2+n3]; char op; int ch1,x,y; do{ int i=0; System.out.print("\n\nU N I O N"); System.out.print("\n[1]AUB"); System.out.print("\n[2]AUC"); System.out.print("\n[3]BUC"); System.out.print("\nPlease select: "); ch1=Integer.parseInt(input.readLine()); if(ch1==1) { System.out.print("\nUnion (AUB) = { "); for(x=0;x<n1;x++) { for(y=0;y<n2;y++) { if(seta[x]!=setb[y]) { un1[i]=seta[x]; } else un1[i]=seta[x]; } i++; } for(x=0;x<n2;x++) { for(y=0;y<n1;y++) { if(setb[x]!=seta[y]) { un1[i]=setb[x]; } else { i--; break; } } i++; } for(i=0;i<un1.length;i++) { System.out.print(un1[i]); } System.out.print(" }"); } else if(ch1==2) { System.out.print("\nUnion (AUC) = { "); for(x=0;x<n1;x++) { for(y=0;y<n3;y++) { if(seta[x]!=setc[y]) { un2[i]=seta[x]; } else un2[i]=seta[x]; } i++; } for(x=0;x<n3;x++) { for(y=0;y<n1;y++) { if(setc[x]!=seta[y]) { un2[i]=setc[x]; } else { i--; break; } } i++; } for(i=0;i<un2.length;i++) { System.out.print(un2[i]); } System.out.print(" }"); } else if(ch1==3) { System.out.print("\nUnion (BUC) = { "); for(x=0;x<n2;x++) { for(y=0;y<n3;y++) { if(setb[x]!=setc[y]) { un3[i]=setb[x]; } else un3[i]=setb[x]; } i++; } for(x=0;x<n3;x++) { for(y=0;y<n2;y++) { if(setc[x]!=setb[y]) { un3[i]=setc[x]; } else { i--; break; } } i++; } for(i=0;i<un3.length;i++) { System.out.print(un3[i]); } System.out.print(" }"); } else { System.out.print("Invalid input!"); } System.out.print("\n\nBack to Union menu[Y\\N]?"); op=Character.toUpperCase((char)System.in.read()); System.in.read(); System.in.read(); }while(op=='Y'); } public static void intersection(char seta[], char setb[], char setc[],int n1, int n2, int n3)throws Exception { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); char op; int ch1=0, x, y; do{ System.out.print("\n\nI N T E R S E C T I O N"); System.out.print("\n[1]AB"); System.out.print("\n[2]AC"); System.out.print("\n[3]BC"); System.out.print("\nPlease select: "); ch1=Integer.parseInt(input.readLine()); switch(ch1){ case 1: System.out.print("\n\nIntersection (AB) =\t{ "); for(x=0;x<n1;x++) { for(y=0;y<n2;y++) { if(seta[x]==setb[y]) System.out.print(seta[x]+" "); else continue; } } System.out.print(" }"); break; case 2: System.out.print("\n\nIntersection (AC) =\t{ "); for(x=0;x<n1;x++) { for(y=0;y<n3;y++) { if(seta[x]==setc[y]) System.out.print(seta[x]+" "); else continue; } } System.out.print(" }"); break; case 3: System.out.print("\n\nIntersection (BC) =\t{ "); for(x=0;x<n2;x++) { for(y=0;y<n3;y++) { if(setb[x]==setc[y]) System.out.print(setb[x]+" "); else continue; } } System.out.print(" }"); break; default: System.out.print("Invalid input"); break; } System.out.print("\n\nBack to Intersection menu[Y\\N]?"); op=Character.toUpperCase((char)System.in.read()); System.in.read(); System.in.read(); }while((op=='y')||(op=='Y')); } public static void relative(char seta[], char setb[], char setc[],int n1, int n2, int n3)throws Exception { BufferedReader input=new BufferedReader(new InputStreamReader(System.in)); char op; int ch1, x, y; do{ ch1=0; System.out.print("\n\nR E L A T I V E"); System.out.print("\n\n[1]A-B"); System.out.print("\n[2]A-C"); System.out.print("\n[3]B-C"); System.out.print("\n[4]B-A"); System.out.print("\n[5]C-A"); System.out.print("\n[6]C-B"); System.out.print("\nPlease select: "); ch1=Integer.parseInt(input.readLine()); switch(ch1){ case 1: System.out.print("\nRelative(A-B) = { "); for(x=0;x<n1;x++) { for(y=n2-1;y>=0;y--) { if(seta[x]==setb[y]) { x=x+1; y=n2-1; } } if(x<n1) System.out.print(seta[x]); } System.out.print(" }"); break; case 2: System.out.print("\nRelative(A-C) = \t{ "); for(x=0;x<n1;x++) { for(y=n3-1;y>=0;y--) { if(seta[x]==setc[y]) { x=x+1; y=n3-1; } } if(x<n1) System.out.print(seta[x]); } System.out.print(" }"); break; case 3: System.out.print("\nRelative(B-C) = \t{ "); for(x=0;x<n2;x++) { for(y=n3-1;y>=0;y--) { if(setb[x]==setc[y]) { x=x+1; y=n3-1; } } if(x<n2) System.out.print(setb[x]); } System.out.print(" }"); break; case 4: System.out.print("\nRelative(B-A) = \t{ "); for(x=0;x<n2;x++) { for(y=n1-1;y>=0;y--) { if(setb[x]==seta[y]) { x=x+1; y=n1-1; } } if(x<n2) System.out.print(setb[x]); } System.out.print(" }"); break; case 5: System.out.print("\nRelative(C-A) = \t{ "); for(x=0;x<n3;x++) { for(y=n1-1 ;y>=0;y--) { if(setc[x]==seta[y]) { x=x+1; y=n1-1; } } if(x<n3) System.out.print(setc[x]); } System.out.print(" }"); break; case 6: System.out.print("\nRelative(C-B) = \t{ "); for(x=0;x<n3;x++) { for(y=n2-1 ;y>=0;y--) { if(setc[x]==setb[y]) { x=x+1; y=n2-1; } } if(x<n3) System.out.print(setc[x]); } System.out.print(" }"); break; default: System.out.print("Invalid input!"); break; } System.out.print("\n\nBack to Relative menu[Y\\N]?"); op=Character.toUpperCase((char)System.in.read()); System.in.read(); System.in.read(); }while((op=='y')||(op=='Y')); } }



Reply With Quote

