package com.evolvus.common.util;
public class AmountInWords {
final static String units[] = {"","one ","two ","three ","four ","five ","six ",
"seven ","eight ","nine ","ten ","eleven ","twelve ","thirteen ",
"fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "};
String tens[] = {"", "ten ","twenty ","thirty ","forty ","fifty ","sixty ","seventy ",
"eighty ","ninety "};
public String format(String aHigherCurrency, String aLowerCurrency,
String aAmount, String aSystemCurrencyFormat,int decimalLength) {
String words="";
String[] systemCurrencyFormats = aSystemCurrencyFormat.split(",");
int formatCount = systemCurrencyFormats[0].length();
String higherCurrencyValue = null;
String lowerCurrencyValue = null;
String[] amounts = aAmount.split("\\.");
if (amounts != null && amounts.length > 0) {
higherCurrencyValue = amounts[0];
if (amounts.length > 1)
lowerCurrencyValue = amounts[1];
}
words=words.concat(aHigherCurrency);
words=words.concat(" ");
/* Call to amount to words for higher currency */
words=words.concat(this.intialFormat(Integer.parseInt(higherCurrencyValue), formatCount));
if (lowerCurrencyValue != null) {
if (lowerCurrencyValue.length() > decimalLength) {
lowerCurrencyValue = lowerCurrencyValue.substring(0,
decimalLength);
}
words=words.concat("and ");
/* Call to amount to words for lower currency */
words=words.concat(this.intialFormat(Integer.parseInt(lowerCurrencyValue), 2));
words=words.concat(aLowerCurrency);
}
return words;
}
public String intialFormat(int amount,int foramt)
{
String words = "";
String tword="";
if(foramt==3){
int millions = amount / 1000000;
tword =threeDigits(millions);
if(tword.length()>1)
words=tword + "million ";
amount-= millions*1000000;
}
else if (foramt==2){
int crore = amount / 10000000;
tword =threeDigits(crore);
tword = threeDigits(crore);
if(tword.length()>1)
words+= tword + "crore ";
amount-= crore*10000000;
int lakhs = amount / 100000;
tword = threeDigits(lakhs);
if(tword.length()>1)
words+= tword + "lakh ";
amount-= lakhs*100000;
}
int thousands = amount / 1000;
tword = threeDigits(thousands);
if(tword.length()>1)
words+= tword + "thousand ";
amount-=thousands*1000;
words+=threeDigits(amount);
return words;
}
public String threeDigits(int digits)
{
String digWord = "";
int hnd = digits / 100;
if(hnd>0)
digWord+=units[hnd] + "hundred ";
int ten = digits - hnd *100;
if(ten<20)>
digWord+= units[ten];
else
{
int tenth = ten / 10;
digWord+=tens[tenth];
int last = ten - tenth*10;
digWord+= units[last];
}
return digWord;
}
public static void main(String args[]){
AmountInWords a = new AmountInWords();
/* Inputs
*
* Higher Currency
* Lower Currency
* Amount
* SystemConfiguration
* Selected Currency Decimal Points
* */
String s=a.format("Rupees", "Paisa", "3451234.425", "##,###", 3);
System.out.println(s);
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.Date;
public class DBBackupUtil {
public static boolean getData(String userName,String password,String dbName,String FileName) throws Exception {
boolean isCompleted=true;
FileWriter fstream=null;
BufferedWriter out=null;
BufferedReader in=null;
Process run=null;
try{
System.out.println("DBBackup Start time:"+new Date());
System.out.println("---Started--");
run = Runtime.getRuntime().exec("mysqldump -u"+userName+" -p"+password+" --database "+dbName+" --routines=1");
in= new BufferedReader(new InputStreamReader(run.getInputStream()));
String line = null;
fstream = new FileWriter(FileName);
out = new BufferedWriter(fstream);
while ((line = in.readLine()) != null) {
out.write(line+'\r');
}
out.close();
in.close();
System.out.println("---Completed--");
System.out.println("DBBackup Completed time:"+new Date());
}catch (Exception e) {
e.printStackTrace();
isCompleted =false;
}finally{
fstream=null;
out=null;
in=null;
}
return isCompleted;
}
public static void main(String[] args) {
try{
DBBackupUtil backup = new DBBackupUtil();
backup.getData("root","root","ams_cameltest2","C:\\back.sql");
}catch (Exception e) {
e.printStackTrace();
}
}
}
public class GenericFormatCurrency {
String preixStr="";
String postfixStr = "";
int postfixLen=0;
String[] preixStrArray;
int prefixArrayLen = 0;
int prefixLen1=0;
int prefixLen2=0;
format(String formatStr){
preixStr=formatStr.substring(0,formatStr.lastIndexOf("."));
postfixStr=formatStr.substring(formatStr.lastIndexOf(".")+1);
postfixLen = postfixStr.length();
preixStrArray = preixStr.split(",");
prefixArrayLen = preixStrArray.length;
if(prefixArrayLen-1==0){
prefixLen1=preixStrArray[0].length();
}else{
prefixLen1=preixStrArray[prefixArrayLen-1].length();
prefixLen2=preixStrArray[prefixArrayLen-2].length();
}
}
public void formaNumber(String number) {
//format format = new format("##,####.0000");
//String number="87654321.12345";
String pre=number.substring(0,number.lastIndexOf("."));
String postnum=number.substring(number.lastIndexOf(".")+1);
String output="";
int length1=this.prefixLen1;
int length2=this.prefixLen2;
if(postnum.trim().length()<=this.postfixLen){
output="."+postnum;
}else{
output="."+postnum.substring(0,this.postfixLen);
}
System.out.println(output);
if(pre.trim().length()
output=pre+output ;
}else{
while(pre.trim().length()>0){
output=","+pre.substring(pre.trim().length()-length1,pre.trim().length())+output;
pre = pre.substring(0,pre.trim().length()-length1);
length1 = length2;
if(pre.trim().length()<=this.prefixLen1){
output = pre+output;
break;
}
}
}
System.out.println(output);
}
public static void main(String[] args) {
GenericFormatCurrency format = new GenericFormatCurrency("##,####.0000");
String number="87654321.12345";
format.formaNumber(number);
System.out.println("-------------------------");
format.formaNumber("87654321.1234");
}
}