import javax.swing.JOptionPane;
abstract class LogicGate{
protected String strUserInput;
protected String strWhatKindofOption;
protected int intUserInput_1st;
protected int intUserInput_2nd;
protected int intResult;
protected int intErrorInputRecord;
protected boolean boolUserNeedThisInput;
final protected int UserInput(){
boolUserNeedThisInput = false;
while(!(boolUserNeedThisInput)){
intErrorInputRecord = 0; //set variable intErrorInputRecord = 0
while (intErrorInputRecord < 3) {
JOptionPane.showMessageDialog(null, "Please input the figure you would like to calculate"+ "\n\n" +
"IMPORTANT NOTICE: "+ "\n\n"+
"PLEASE ONLY input SINGLE figure: " + "\n" +
"1 (=One) or 0(=Zero)"+"\n");
System.out.println("Please input the value you would like to calculate"+ "\n\n" +
"IMPORTANT NOTICE: "+ "\n\n"+
"PLEASE ONLY input SINGLE figure: " + "\n" +
"1 (=One) or 0(=Zero)"+"\n");
InputData userInput = new InputData(); //get input and save input string to strUserInput
strUserInput = userInput.GetKeyboardInput();
if (!(strUserInput.equals("0")) & !(strUserInput.equals("1"))) {
JOptionPane.showMessageDialog(null, "Your input is: "+ strUserInput + "\n\n" +
"PLEASE ONLY input SINGLE figure: " + "\n" +
"1 (=One) or 0(=Zero)"+"\n");
System.out.println("Your input is: "+ strUserInput + "\n\n" +
"PLEASE ONLY input SINGLE figure: " + "\n" +
"1 (=One) or 0(=Zero)"+"\n");
intErrorInputRecord++;
} //end of if()
if (strUserInput.equals("0") | strUserInput.equals("1")){
intErrorInputRecord=5; //quit loop method: while(intErrorInputRecord < 3)
//by giving value 5(>3) to variable intErrorInputRecord = 5
}
if (intErrorInputRecord == 3) {
JOptionPane.showMessageDialog(null,
"You input wrong figure for 3 times!" +"\n\n" +
"Thank you for use this program!"+ "\n\n" +
"Program provided by: Mr ZHU Xing Jin" +"\n" +
"Student of University of Center Lancashire" + "\n" +
"Program based on: JAVA Technology" + "\n\n" +
"JAVA is a registered Trade Mark of Sun Micorsystems" + "\n" +
"For more information please visit:" + "\n" +
"http://java.sun.com" +"\n\n" +
"Program TERMINATE" + "\n");
System.exit(0);
} //end of if()
} //end of while(intErrorInputRecord < 3)
intErrorInputRecord = 0;
while (intErrorInputRecord < 3){
JOptionPane.showMessageDialog(null, "You have input the following figure: "+ "\n" +
strUserInput + "\n\n" +
"Is it what you want? Please Confirm by choosing the following options" + "\n" +
"Please input Single Figure:"+ "\n\n" +
"1 = YES, Its what i want" + "\n" +
"5 = NO, Its NOT what i want, i wanna INPUT AGAIN" + "\n" +
"0 = Exit program"+ "\n");
System.out.println("You have input the following figure: "+ "\n" +
strUserInput + "\n\n" +
"Is it what you want? Please Confirm by choosing the following options" + "\n" +
"Please input Single Figure:"+ "\n\n" +
"1 = YES, Its what i want" + "\n" +
"5 = NO, Its NOT what i want, i wanna INPUT AGAIN" + "\n" +
"0 = Exit program"+ "\n");
InputData userInput = new InputData(); //get user input and save input string to strstrWhatKindofOption
strWhatKindofOption = userInput.GetKeyboardInput();
if (!(strWhatKindofOption.equals("0")) & !(strWhatKindofOption.equals("1")) &
!(strWhatKindofOption.equals("5"))) {
JOptionPane.showMessageDialog(null, "Your input is: "+ strWhatKindofOption + "\n\n" +
"Please ONLY input:"+"\n\n" +
"1 = YES, Its what i want" + "\n" +
"5 = NO, Its NOT, i wanna INPUT the figure i want AGAIN" + "\n\n" +
"0 = Exit program"+ "\n");
System.out.println("Your input is: "+ strWhatKindofOption + "\n\n" +
"Please ONLY input:"+"\n\n" +
"1 = YES, Its what i want" + "\n" +
"5 = NO, Its NOT, i wanna INPUT the figure i want AGAIN" + "\n\n" +
"0 = Exit program"+ "\n");
intErrorInputRecord++;
} //end of if()
if (strWhatKindofOption.equals("0")) {
JOptionPane.showMessageDialog(null,
"Thank you for use this program!"+ "\n\n" +
"Program provided by: Mr ZHU Xing Jin" +"\n" +
"Student of University of Center Lancashire" + "\n" +
"Program based on: JAVA Technology" + "\n\n" +
"JAVA is a registered Trade Mark of Sun Micorsystems" + "\n" +
"For more information please visit:" + "\n" +
"http://java.sun.com" +"\n\n" +
"Program TERMINATE" + "\n");
System.out.println(
"Thank you for use this program!"+ "\n\n" +
"Program provided by: Mr ZHU Xing Jin" +"\n" +
"Student of University of Center Lancashire" + "\n" +
"Program based on: JAVA Technology" + "\n\n" +
"JAVA is a registered Trade Mark of Sun Micorsystems" + "\n" +
"For more information please visit:" + "\n" +
"http://java.sun.com" +"\n\n" +
"" + "\n");
System.exit(0);
} //end of if()
if(strWhatKindofOption.equals("1")) {
intErrorInputRecord=5; //quit loop method: while(intErrorInputRecord < 3)
//by giving value 5(>3) to variable intErrorInputRecord = 5
boolUserNeedThisInput = true; //quit loop method: while(!(boolUserNeedThisInput))
//by giving "true" to boolUserNeedThisLogicGate
} //end of if()
if(strWhatKindofOption.equals("5")) {
intErrorInputRecord=5; //quit loop method: while(intErrorInputRecord < 3)
//by giving value 5(>3) to variable intErrorInputRecord = 5
//but NOT quit loop method: while(!(boolUserNeedThisInput))
//because boolean variable boolUserNeedThisLogicGate is STILL false
//the loop method: while(!(boolUserNeedThisInput)) is STILL RUNING
} //end of if()
if (intErrorInputRecord == 3) {
JOptionPane.showMessageDialog(null,
"You input wrong figure for 3 times!" +"\n\n" +
"Thank you for use this program!"+ "\n\n" +
"Program provided by: Mr ZHU Xing Jin" +"\n" +
"Student of University of Center Lancashire" + "\n" +
"Program based on: JAVA Technology" + "\n\n" +