Posts

user interface - java- why is my "deposit" method not working for my ATM with gui? -

i'm making atm in user must first enter pin (1234), , once pin entered correctly, user can either withdraw 50, 100, or 200 dollars or make deposit under $1000. withdraw methods working, when run program , try make deposit, nothing happens after enter amount , try hit "enter" button. seems if enter button not working. here code used deposit method: if (event.getsource() == deposit) { instructionscreen.settext("enter amount deposit, click enter."); if (event.getsource() == enter) { savescreen = displayinput.gettext(); double add = double.parsedouble(savescreen); if (add <= 1000) { balance += add; instructionscreen.settext("your new balance $" + balance + "."); } else { instructionscreen.settext("the maximum amount can deposit $1000. please enter new amount."); displayinput.settext(""); if (event.getsource() == enter) { ...

python - Replacing minimum element in a numpy array subject to a condition -

i need replace element of numpy array subject minimum of numpy array verifying 1 condition. see following minimal example: arr = np.array([0, 1, 2, 3, 4]) label = np.array([0, 0, 1, 1, 2]) cond = (label == 1) label[cond][np.argmin(arr[cond])] = 3 i expecting label now array([0, 0, 3, 1, 2]) instead getting array([0, 0, 1, 1, 2]) this consequence of known fact numpy arrays not updated double slicing . anyway, can't figure out how rewrite above code in simple way. hint? you triggering numpy's advanced indexing chaining of indexing , assigning doesn't go through. solve this, 1 way store indices corresponding mask , use indexing. here's implementation - idx = np.where(cond)[0] label[idx[arr[idx].argmin()]] = 3 sample run - in [51]: arr = np.array([5, 4, 5, 8, 9]) ...: label = np.array([0, 0, 1, 1, 2]) ...: cond = (label == 1) ...: in [52]: idx = np.where(cond)[0] ...: label[idx[arr[idx].argmin()]] = 3 ...: in...

Using Javascript to Alternate background color of HTML element -

so have practise test asks me change background color , text color of paragraph section id "fourth" black background , white text vise versa , reverse every 30 seconds preferably using if/else statements. reason if statement (and else statement) not work. the code have far this: html <html> <head> <link href="teststyle.css" rel="stylesheet" type="text/css"/> <script src="flash.js" type="text/javascript"></script> </head> <body> <div id="first"> mares eat oats </div> <h1 id="second"> , eat oats </h1> <p id="third"> , little lambs eat ivy </p> <p id="fourth"> mirthipan karunakaran </p> </body> </html> css #first { text-align: center; } #second { color: green; text-align: left; } #third { color: orange; text-align: right; } #fourth { color: white; background-...

How can I implement Pencil Shades like hb, 2b, 4b, etc. to draw anything in Canvas of my Android Application? -

i need implement pencil shades 9b 9h list showing shades on pencil button click() , after clicking list item, pencil should change new shade. need eraser implementation on erase button click erase path drawn pencil. this code drawing fixed size pen on canvas without button click. , clearcanvas() method called on button click clears whole canvas. any appreciated. public class mainactivity extends appcompatactivity { private canvasview customcanvas; private toolbar toolbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); customcanvas = (canvasview) findviewbyid(r.id.custom_canvas); toolbar = (toolbar) findviewbyid(r.id.actionbar); setsupportactionbar(toolbar); assert getsupportactionbar()!=null; getsupportactionbar().sethomebuttonenabled(true); getsupportactionbar().setdisplayhomeasupenabled(true); } ...

java - for each loop with a second boolean parameter -

this question has answer here: java foreach condition 6 answers is there here know how this: boolean condition = true; for(int i=0; i<list.size() && condition; i++){ if (***) condition = false; } with each loop, that: boolean condition = true; for(string s : list && condition){ if (***) condition = false; } i know second loop not work, have same behaviour without using killing mortal ugly instruction "break". use break statement: for(string s: list) { if (....) { break; } } btw can kind of loop , imho preferable because more readable.

html parsing - Ignoring </span> tag and placing all closing tags before span opening tag in php -

my code in php is: while(preg_match('%(<span style="color: green;">)(?:\s+)?(</.*?>)%i', $result2)==1){ $result2 = preg_replace('%(<span style="color: green;">)(?:\s+)?(</.*?>)%i', '$2 $1', $result2); } right have input such as: <span style="color: green;"></p></i> and code whenever tag closing after span green tag, placed before span. output above input be: </p></i><span style="color: green;"> i want if there span tag closing after span green tag, should ignored , other closing tags should placed first.. example input: <span style="color: green;"></p></span></i> output: </p></i><span style="color: green;"></span> can me out in making change? in general regex implementations can use look-ahead mechanism, (?!</span>)(</.*?>) instead of (...

Calculating overlap (and distance measures) for categorical variables in R -

i trying calculate distance between rows (data points) on basis of categorical variables in columns. simplest method have seen calculate overlap. in other words in proportion of variables x , y take identical values. imagine have dataset follows; id = 1:5 dummy <- data.frame(country = c("uk", "uk", "usa", "usa", "usa"), category = c("private", "public", "private", "private", "public"), level = c("high", "low", "low", "low", "high")) and want calculate proportional overlap (as above) between pairs of rows. i define function this; calcoverlap <- function(id, df) { n <- length(id) results <- matrix(na, n, n) for(i in 1:n) { for(j in 1:n) { if(i > j) { results[i, j] <- length(which(df[i,] == df[j,])) / nc...