Program ExamplesPre commentsPassword checkerAssorted testsMore testsAccess testInteresting loopSetting up a Choice (drop-down list)Case testingMore casesRandomPolymorphism? What’s that?Pop-upsMore pop-upsYet more pop-upsAn HTML formThe dialogFileMatrixThe EndJan 14, 2019Program ExamplesThe Good, the Bad, and the UglyPre commentsMany of these examples are not Java, so if the syntax is a bit strange, don’t worry about thatSome of these examples work, some don’tExcept as noted, the examples are from http://www.thedailywtf.com(I may have made a few minor editing changes)Password checkerprivate void txtHostname_KeyPress(object sender, KeyPressEventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append("SELECT Passwd FROM [Users] WHERE Username='"); sb.Append(this.txtUsername.Text + "'"); String password = GetPassword(sb.ToString()); for (int i = 0; i < (sender as TextBox).Text.Length; i++) { if (password[i] == (sender as TextBox).Text[i]) { this.lblError.Text = ""; } else this.lblError.Text = "Incorrect Password!"; if (i == (sender as TextBox).Text.Length) { if (password[i] == (sender as TextBox).Text[i]) { LogUserIn(this.txtUsername.Text); } } }}Assorted testsif (Math.max(1, 2) == 2) return; If Not IsPostBack Then If Not IsPostBack Then LoadReport() End IfEnd If IF 0 > 0BEGIN SELECT 'Equipment is in use‘ RETURNENDMore testsIf Not(blnIsDirty = True) Then ' Do NothingElse UpdateAccountRecordEnd If//return whether a double is negativebool IsNegative(double n){ string nStr = n.ToString(); if (nstr.IndexOf('-', 0, 1)) return true; return false;}Access testIf ((mintAccessLevelForm = NO_ACCESS) Or _ ((mintOperationMode = OP_NEW) And (mintAccessLevelForm = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelIndividuals = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelAddressAlias = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelContracts = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelCostCenter = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelCorrespondence = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelAccountProfile = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelInstructions = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelFBOVendors = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelFBOChains = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelCatering = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelGround = READ_ACCESS) And _ (mintOperationMode = OP_NEW) And (mintAccessLevelAccountProfileOSR = READ_ACCESS)) Or _ ((mintOperationMode = OP_NEW) And (mintAccessLevelForm <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelIndividuals <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelAddressAlias <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelContracts <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelCostCenter <> FULL_ACCESS)Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelCorrespondence <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelAccountProfile <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelInstructions <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelFBOVendors <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelFBOChains <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelCatering <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelGround <> FULL_ACCESS) Or _ (mintOperationMode = OP_NEW) And (mintAccessLevelAccountProfileOSR <> FULL_ACCESS))) Then DisplayNoAccessMessage Exit FunctionEnd IfInteresting loopfor (int i = 0; i < 12; i++) { switch(i) { case 0: list = paymentMethod; logger.debug("Payment method set."); break; case 1: list = productCategory; logger.debug("Product category set."); break; ... // I've omitted similar cases 2 through 10 case 11: list = productWaight; logger.debug("Product weight set."); default: list = new ArrayList(); logger.debug("Unknown value"); break; }}Setting up a Choice (drop-down list)annualMileageChoice = new Choice()annualMileageChoice.addItem(CHO_PLEASE_ENTER);annualMileageChoice.addItem("500")annualMileageChoice.addItem("1000")annualMileageChoice.addItem("1500")annualMileageChoice.addItem("2000")annualMileageChoice.addItem("2500")annualMileageChoice.addItem("3000")annualMileageChoice.addItem("3500");…annualMileageChoice.addItem("44000");annualMileageChoice.addItem("44500");annualMileageChoice.addItem("45000");Case testingMore casesRandomint invoiceId = new Random().nextInt(); hi all,IntTemp = Int((255 * Rnd()) + 1)I used above ASP.NET code. Problem is in " Rnd() "Rnd() value is changing everytime.What is the alternative for Rnd()? OR How will stop Rnd() value changes at everytime?if ($hour>=7 and $hour<18) { # Assign randomly to Biff or Cliff if (rand() > 0.5) {$Owner->LoadById('70656');} if (rand() < 0.5) {$Owner->LoadById('72586');}}Polymorphism? What’s that?if(obj instanceof MMSNode) { MMSNode node = (MMSNode)obj; attribs = node.getAttribs();}else if(obj instanceof MMSPhysComp) { MMSPhysComp physComp = (MMSPhysComp)obj; attribs = physComp.getAttribs();}else if(obj instanceof MMSLogComp) { MMSLogComp logComp = (MMSLogComp)obj; attribs = logComp.getAttribs();}else if (obj instanceof MMSPhysLink) { MMSPhysLink physLink = (MMSPhysLink)obj; attribs = physLink.getAttribs();}Pop-upsMore pop-upsYet more pop-upsAn HTML formThe dialogFileMatrixThe
View Full Document