Program Examples The Good the Bad and the Ugly Jan 14 2019 Pre comments Many of these examples are not Java so if the syntax is a bit strange don t worry about that Some of these examples work some don t Except as noted the examples are from http www thedailywtf com I may have made a few minor editing changes Password checker private 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 tests if Math max 1 2 2 return If Not IsPostBack Then If Not IsPostBack Then LoadReport End If End If IF 0 0 BEGIN SELECT Equipment is in use RETURN END More tests If Not blnIsDirty True Then Do Nothing Else UpdateAccountRecord End If return whether a double is negative bool IsNegative double n string nStr n ToString if nstr IndexOf 0 1 return true return false Access test If 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 Interesting loop for 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 E NTER 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 testing More cases Random int 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 ups More pop ups Yet more pop ups An HTML form The dialog FileMatrix The End
View Full Document
Unlocking...