Notes
Notes - notes.io |
import java.io.InputStreamReader;
import java.util.*;
class Test1_2 {
static final int DENOMINATION_MULTIPLIER = 100;
public static void main(String[] args) {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
String input = br.readLine();
String[] ip = input.split(";");
double PP = Double.parseDouble(ip[0]);
double CP = Double.parseDouble(ip[1]);
// double PP = Double.parseDouble(br.readLine());
// double CP = Double.parseDouble(br.readLine());
calculateChange(PP, CP);
} catch(Exception e) {
System.out.println(e);
}
}
private static void calculateChange(double PP, double CH) {
double changeDiff = CH - PP;
if (changeDiff < 0) {
System.out.println("ERROR");
} else if (changeDiff == 0) {
System.out.println("ZERO");
} else {
LinkedHashMap<Double, String> map = new LinkedHashMap<>();
Money registerMoney = new Money();
map = registerMoney.getCashDenomination();
System.out.println(calculateChange(map,changeDiff));
}
}
private static String calculateChange(LinkedHashMap<Double,String> denominations, Double change) {
change = change * DENOMINATION_MULTIPLIER;
// LinkedHashMap<Double, String> demonimations = new LinkedHashMap<>();
// Money registerMoney = new Money();
// demonimations = registerMoney.getCashDenomination();
StringBuilder sb = new StringBuilder();
Iterator<Map.Entry<Double, String>> iterator = denominations.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Double, String> entry = iterator.next();
double mapDenomValue = entry.getKey() * DENOMINATION_MULTIPLIER;
String denomDescription = entry.getValue();
while (change >= mapDenomValue) {
change -= mapDenomValue;
sb.append(denomDescription);
sb.append(",");
}
}
String st = sb.toString();
return st.substring(0, st.length() - 1);
}
}
class Money {
private LinkedHashMap<Double,String> map;
Money(){
map = new LinkedHashMap<Double,String>();
populateCashDenomination();
}
private void populateCashDenomination() {
map.put(50.0, "Fifty Pounds");
map.put(20.0, "Twenty Pounds");
map.put(10.0, "Ten Pounds");
map.put(5.0, "Five Pounds");
map.put(2.0, "Two Pounds");
map.put(1.0, "One Pound");
map.put(0.5, "Fifty Pence");
map.put(0.2, "Twenty Pence");
map.put(0.1, "Ten Pence");
map.put(0.05, "Five Pence");
map.put(0.02, "Two Pence");
map.put(0.01, "One Pence"); }
public LinkedHashMap<Double,String> getCashDenomination() {
return map;
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team