diff options
| author | John H. Anthony <johnhant@gmail.com> | 2010-09-04 14:46:46 +0200 | 
|---|---|---|
| committer | John H. Anthony <johnhant@gmail.com> | 2010-09-04 14:46:46 +0200 | 
| commit | c35a035d25b06bc7ad403ec82dd4495056e599d7 (patch) | |
| tree | 09e514c08613002a41941a0837860156339fcf78 /src/lq | |
| parent | 34a49b17b16edae59b903a61def80e003227b097 (diff) | |
format score
Diffstat (limited to 'src/lq')
| -rw-r--r-- | src/lq/Printer.java | 4 | ||||
| -rw-r--r-- | src/lq/QuoteUtil.java | 9 | 
2 files changed, 11 insertions, 2 deletions
| diff --git a/src/lq/Printer.java b/src/lq/Printer.java index e5bdc0b..573ab5d 100644 --- a/src/lq/Printer.java +++ b/src/lq/Printer.java @@ -17,11 +17,11 @@ public class Printer {              "</a>"+              ", lagt til av " + Strings.escape(quote.getAuthor()) + "<br>"); -        String score = quote.getScore().toString();          String date = DateUtil.dateFormat.format(quote.getQuoteDate());          out.println("Dato: " + date + ", Score: "); +          out.println("<span id=\"v" + quote.getId() + "\">"); -        out.println((score==null?"-":(score+ " (fra " + quote.getNumVotes() +")"))); +        out.println(QuoteUtil.formatScore(quote));          out.println("<br> Vote: <font size=\"-1\">");          for(int nv=1; nv<=5; nv++)               out.println("<a href=\"javascript:ajaxvote(" + quote.getId() + ","+nv+")\">"+nv+"</a> "); diff --git a/src/lq/QuoteUtil.java b/src/lq/QuoteUtil.java index 82ff932..3b4fb5c 100644 --- a/src/lq/QuoteUtil.java +++ b/src/lq/QuoteUtil.java @@ -3,6 +3,7 @@ package lq;  import java.util.Collections;  import java.util.List;  import java.util.Comparator; +import java.text.DecimalFormat;  import javax.jdo.PersistenceManager;  import javax.jdo.Query; @@ -142,4 +143,12 @@ public class QuoteUtil {          double scorePoints = (vote.getRating()-2.5) * Math.abs((vote.getRating()-2.5));          quote.setScorePoints(quote.getScorePoints() + scorePoints);      } + +    public static String formatScore(Quote quote) { +        if (quote.getNumVotes() == 0) { +            return "-"; +        } +        String score = DecimalFormat.getInstance().format(quote.getScore()); +        return (score + " (fra " + quote.getNumVotes() + ")"); +    }  } | 
