/* package whatever; // don't place package name! */
import java.util.* ;
import java.lang.* ;
import java.io.* ;
import java.math.BigDecimal ;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
test( 15.05 , 9.03 , 40 ) ;
test( 15.00 , 9.00 , 40 ) ;
test( 14.95 , 8.97 , 40 ) ;
test( 14.90 , 8.94 , 40 ) ;
test( 14.85 , 8.91 , 40 ) ;
}
public static void test
( Double oldPrice,
Double price,
int expected
) { int discount = getPriceDifferenceInPercentage( oldPrice, price) ;
String message
= "Discount between " + oldPrice
+ " EUR and " + price
+ " EUR: " + discount
+ "% off" ; if ( discount == expected) {
System .
out .
println ( "OK! " + message
) ; } else {
System .
out .
println ( "FAIL! " + message
+ ", expected: " + expected
+ "% off" ) ; }
}
public static int getPriceDifferenceInPercentage
( Double oldPrice,
Double price
) { return new BigDecimal ( ( oldPrice
- price
) * 100 / oldPrice
) .
setScale ( 1 ,
BigDecimal .
ROUND_HALF_UP ) .
intValue ( ) ; }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLm1hdGguQmlnRGVjaW1hbDsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJdGVzdCgxNS4wNSwgOS4wMywgNDApOwoJCXRlc3QoMTUuMDAsIDkuMDAsIDQwKTsKCQl0ZXN0KDE0Ljk1LCA4Ljk3LCA0MCk7CgkJdGVzdCgxNC45MCwgOC45NCwgNDApOwoJCXRlc3QoMTQ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