Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(Ruleset rule : rules){
- if(!rule.hasEmptyCells()){
- switch(rule.getOperation()){
- case '+' :
- int sum = 0;
- for(Cell c : rule.getCells()){
- sum += c.getValue();
- }
- if(sum != rule.getTotal()){
- return false;
- }
- break;
- case '-' :
- int difference = 0;
- for(Cell c : rule.getCells()){
- difference = Math.abs(difference - c.getValue());
- }
- if(difference != rule.getTotal()){
- return false;
- }
- break;
- case '*' :
- int product = 1;
- for(Cell c : rule.getCells()){
- product *= c.getValue();
- }
- if(product != rule.getTotal()){
- return false;
- }
- break;
- case '/' :
- float total = 1;
- int temp = 0;
- for(Cell c : rule.getCells()){
- temp = c.getValue();
- if(temp > total){
- total = (float)temp/total;
- }else if(temp < total){
- total = total/temp;
- }
- }
- if(total != rule.getTotal()){
- return false;
- }
- break;
- }//close switch
Add Comment
Please, Sign In to add comment