import java.util.Random; public class Srv { public int lastDay(int month) { // Jan, Feb, March, etc. int[] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int lastDay = 0; if(month > 0 && month <= 12) { lastDay = months[month - 1]; } return lastDay; } public boolean allDigits(String _str) { boolean allDigits = true; if(_str.length() == 0) { allDigits = false; } for(int i = 0; i < _str.length() && allDigits; i++) { // if the char is NOT a number if(!(_str.charAt(i) >= '0' && _str.charAt(i) <= '9')) allDigits = false; } return allDigits; } public boolean payday(int _day, int _month) { boolean isPayday = false; if((_month > 0 || _month <= 12) && (_day > 0 && _day <= lastDay(_month)) ) { if(_day == 15 || lastDay(_month) == _day) { isPayday = true; } } return isPayday; } public void printTriangle(int _num) { /* * printTriangle(3) * * * ** * *** */ // going down the triangle (each row) for(int row = 1; row <= _num; row++) { // going across the row (each col) for(int col = 0; col < row; col++) System.out.print("*"); System.out.println(); } } public String leftPad(String _str, int _spaces) { String result = ""; for(int i = 0; i < _spaces; i++) { // * represents space result += "*"; } // result = result + _str result += _str; return result; } public int genRandomNum(int _boundOne, int _boundTwo) { Random randObj = new Random(); /* * bound1 = 2 * bound2 = 5 * 4 values total */ int range = _boundOne - _boundTwo; int startingPoint = 0; if(range < 0 ) { range *= -1; startingPoint = _boundOne; } else startingPoint = _boundTwo; range++; //randObj.nextInt("range value") + "where to start" int randNum = randObj.nextInt(range) + startingPoint; return randNum; } }