package Ġf tl . util Ċ Ċ import Ġjava . math . BigDecimal Ċ import Ġjava . math . Round ingMode Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ private Ġval Ġphysical Cost Per Minute Ġ= Ġdiv By 6 0 ( 5 ) Ġ// Ġ$ 5 / hr Ċ Ċ private Ġval Ġvirtual Cost Per Minute Ġ= Ġdiv By 6 0 ( 1 ) Ġ// Ġ$ 1 / hr Ċ Ċ private Ġfun Ġdiv By 6 0 ( value : ĠLong ) Ġ= ĠBigDecimal ( value ). divide ( BigDecimal ( 6 0 ), Ġ 1 0 , ĠRound ingMode . HALF _ UP ) Ċ Ċ private Ġfun Ġdiv By 6 0 ( value : ĠBigDecimal ) Ġ= Ġvalue . divide ( BigDecimal ( 6 0 ), Ġ 1 0 , ĠRound ingMode . HALF _ UP ) Ċ Ċ // Ġround Ġdecimals Ġup . Ġ 0 . 0 1 Ġminutes Ġis Ġbill able Ġat Ġ 1 Ġminute . Ċ fun Ġbill able Minutes ( test Duration Seconds : ĠLong ) Ġ= Ġdiv By 6 0 ( check For Zero ( BigDecimal ( test Duration Seconds ))) ĊĠĠĠ Ġ. set Scale ( 0 , ĠRound ingMode . UP ) ĊĠĠĠ Ġ. longValue Exact () Ċ Ċ // Ġ 0 s Ġduration Ġ=> Ġ 1 s Ċ private Ġfun Ġcheck For Zero ( test Duration Seconds : ĠBigDecimal ) Ġ= ĊĠĠĠ Ġif Ġ( test Duration Seconds Ġ== ĠBigDecimal . ZERO ) ĠBigDecimal . ONE ĊĠĠĠ Ġelse Ġtest Duration Seconds Ċ Ċ fun Ġestimate Cost s ( bill able Virtual Minutes : ĠLong , Ġbill able Physical Minutes : ĠLong ): ĠString Ġ{ ĊĠĠĠ Ġreturn Ġestimate Cost s ( BigDecimal ( bill able Virtual Minutes ), ĠBigDecimal ( bill able Physical Minutes )) Ċ } Ċ Ċ private Ġfun Ġestimate Cost s ( bill able Virtual Minutes : ĠBigDecimal , Ġbill able Physical Minutes : ĠBigDecimal ): ĠString Ġ{ ĊĠĠĠ Ġval Ġvirtual Cost Ġ= Ġbill able Virtual Minutes . multiply ( virtual Cost Per Minute ). set Scale ( 2 , ĠRound ingMode . HALF _ UP ) ĊĠĠĠ Ġval Ġphysical Cost Ġ= Ġbill able Physical Minutes . multiply ( physical Cost Per Minute ). set Scale ( 2 , ĠRound ingMode . HALF _ UP ) ĊĠĠĠ Ġval Ġtotal Cost Ġ= Ġ( virtual Cost Ġ+ Ġphysical Cost ). set Scale ( 2 , ĠRound ingMode . HALF _ UP ) ĊĊĠĠĠ Ġval Ġbill able Virtual Time Ġ= Ġpretty Time ( bill able Virtual Minutes ) ĊĠĠĠ Ġval Ġbill able Physical Time Ġ= Ġpretty Time ( bill able Physical Minutes ) ĊĠĠĠ Ġval Ġtotal Time Ġ= Ġpretty Time ( bill able Virtual Minutes Ġ+ Ġbill able Physical Minutes ) ĊĊĠĠĠ Ġval Ġdisplay Physical Ġ= Ġbill able Physical Minutes . sign um () Ġ== Ġ 1 ĊĠĠĠ Ġval Ġdisplay Virtual Ġ= Ġbill able Virtual Minutes . sign um () Ġ== Ġ 1 Ġ// Ġ 1 Ġ= Ġpositive Ġnumber Ġ> Ġ 0 ĊĠĠĠ Ġval Ġdisplay Total Ġ= Ġdisplay Physical Ġ&& Ġdisplay Virtual ĊĠĠĠ Ġvar Ġresult Ġ= Ġ"" ĊĊĠĠĠ Ġif Ġ(! display Physical Ġ&& Ġ! display Virtual ) Ġ{ ĊĠĠĠĠĠĠĠ Ġresult Ġ= Ġ" No Ġcost . Ġ 0 m " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġif Ġ( display Physical ) Ġ{ ĊĠĠĠĠĠĠĠ Ġresult Ġ+= Ġ""" Ċ Physical Ġdevices ĊĠ Ġ$$ physical Cost Ġfor Ġ$ bill able Physical Time Ċ """ ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġif Ġ( display Virtual ) Ġ{ ĊĠĠĠĠĠĠĠ Ġresult Ġ+= Ġ""" Ċ Virtual Ġdevices ĊĠ Ġ$$ virtual Cost Ġfor Ġ$ bill able Virtual Time Ċ """ ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġif Ġ( display Total ) Ġ{ ĊĠĠĠĠĠĠĠ Ġresult Ġ+= Ġ""" Ċ Total ĊĠ Ġ$$ total Cost Ġfor Ġ$ total Time Ċ """ ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġreturn Ġresult . trim () Ċ } Ċ Ċ private Ġfun Ġpretty Time ( bill able Minutes : ĠBigDecimal ): ĠString Ġ{ ĊĠĠĠ Ġval Ġremainder Ġ= Ġbill able Minutes . to Long () ĊĠĠĠ Ġval Ġhours Ġ= ĠTimeUnit . MIN UTES . to Hours ( remainder ) ĊĠĠĠ Ġval Ġminutes Ġ= Ġremainder Ġ% Ġ 6 0 ĊĊĠĠĠ Ġreturn Ġif Ġ( hours Ġ> Ġ 0 ) Ġ"${ hours } h Ġ${ minutes } m " ĊĠĠĠ Ġelse Ġ"${ minutes } m " Ċ } Ċ