Advertisement
Guest User

Priceprint.java

a guest
May 6th, 2013
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package frontend;
  2.  
  3. import java.util.Hashtable;
  4. import java.util.Enumeration;
  5. import java.util.Collections;
  6. import java.util.Vector;
  7.  
  8. public class Priceprint {
  9.     String message = new String("");
  10.     boolean msgflag = false;
  11.  
  12.     public Priceprint(Hashtable<String, Double> b, Hashtable<String, Double> d, String m) {
  13.         message = new String(m);
  14.         out(b, d);
  15.     }
  16.  
  17.     public Priceprint(Hashtable<String, Double> b, Hashtable<String, Double> d) {
  18.         out(b, d);
  19.     }
  20.  
  21.     public Priceprint(String l, Double d, Double b) {
  22.         msgflag = true;
  23.         out(l, d, b);
  24.     }
  25.  
  26.     public Priceprint(String l, Double d, Double b, String m) {
  27.         message = new String(m);
  28.     }
  29.  
  30.     public void out(Hashtable<String, Double> b, Hashtable<String, Double> d) {
  31.         Vector<String> v;
  32.         Enumeration<String> k;
  33.         String te1, te2, e;
  34.         int ex, sp;
  35.  
  36.         v = new Vector<String>(d.keySet());
  37.         Collections.sort(v);
  38.  
  39.         te1 = new String(v.get(0));
  40.         ex = v.indexOf("exchange");
  41.         v.set(ex, te1); v.set(0, "exchange");
  42.  
  43.         te2 = new String(v.get(1));
  44.         ex = v.indexOf("special");
  45.         v.set(ex, te2); v.set(1, "special");
  46.  
  47.         if (msgflag == true)
  48.             System.out.println("Listing Bitcoin and dollar prices.");
  49.         else {
  50.             System.out.println("Listing Bitcoin and dollar prices, " + message + ".");
  51.             msgflag = true;
  52.         }
  53.  
  54.         k = v.elements();
  55.         while (k.hasMoreElements()) {
  56.             e = new String(k.nextElement());
  57.             out(e, d.get(e), b.get(e));
  58.         }
  59.     }
  60.  
  61.     private void out(String l, Double d, Double b) {
  62.         String tab; //This holds either one or two tabs, depending on size of label.
  63.  
  64.         if (l.equals("exchange")) {
  65.             if (msgflag == true)
  66.                 System.out.println("Exchange rate is $" + d + " (USDBTC).");
  67.             else
  68.                 System.out.println("Exchange rate is $" + d + " (USDBTC), " +
  69.                     message + ".");
  70.  
  71.         }
  72.         else if (l.equals("special")) {
  73.             if (msgflag == true)
  74.                 System.out.println("Special is " + (d * 100) + "%.");
  75.             else
  76.                 System.out.println("Special is " + (d * 100) + "%, " + message + ".");
  77.         }
  78.         else {
  79.             if (l.length() > 6) tab = new String("\t");
  80.             else tab = new String("\t\t");
  81.             if (message.equals("length"))
  82.                 System.out.println(l + ":" + tab + "$" + d + "\t" + b + "BTC.");
  83.             else
  84.                 System.out.println(l + ":" + tab + "$" + d + "\t" + b + "BTC, " +
  85.                     message + ".");
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement