Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package frontend;
- import java.util.Hashtable;
- import java.util.Enumeration;
- import java.util.Collections;
- import java.util.Vector;
- public class Priceprint {
- String message = new String("");
- boolean msgflag = false;
- public Priceprint(Hashtable<String, Double> b, Hashtable<String, Double> d, String m) {
- message = new String(m);
- out(b, d);
- }
- public Priceprint(Hashtable<String, Double> b, Hashtable<String, Double> d) {
- out(b, d);
- }
- public Priceprint(String l, Double d, Double b) {
- msgflag = true;
- out(l, d, b);
- }
- public Priceprint(String l, Double d, Double b, String m) {
- message = new String(m);
- }
- public void out(Hashtable<String, Double> b, Hashtable<String, Double> d) {
- Vector<String> v;
- Enumeration<String> k;
- String te1, te2, e;
- int ex, sp;
- v = new Vector<String>(d.keySet());
- Collections.sort(v);
- te1 = new String(v.get(0));
- ex = v.indexOf("exchange");
- v.set(ex, te1); v.set(0, "exchange");
- te2 = new String(v.get(1));
- ex = v.indexOf("special");
- v.set(ex, te2); v.set(1, "special");
- if (msgflag == true)
- System.out.println("Listing Bitcoin and dollar prices.");
- else {
- System.out.println("Listing Bitcoin and dollar prices, " + message + ".");
- msgflag = true;
- }
- k = v.elements();
- while (k.hasMoreElements()) {
- e = new String(k.nextElement());
- out(e, d.get(e), b.get(e));
- }
- }
- private void out(String l, Double d, Double b) {
- String tab; //This holds either one or two tabs, depending on size of label.
- if (l.equals("exchange")) {
- if (msgflag == true)
- System.out.println("Exchange rate is $" + d + " (USDBTC).");
- else
- System.out.println("Exchange rate is $" + d + " (USDBTC), " +
- message + ".");
- }
- else if (l.equals("special")) {
- if (msgflag == true)
- System.out.println("Special is " + (d * 100) + "%.");
- else
- System.out.println("Special is " + (d * 100) + "%, " + message + ".");
- }
- else {
- if (l.length() > 6) tab = new String("\t");
- else tab = new String("\t\t");
- if (message.equals("length"))
- System.out.println(l + ":" + tab + "$" + d + "\t" + b + "BTC.");
- else
- System.out.println(l + ":" + tab + "$" + d + "\t" + b + "BTC, " +
- message + ".");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement