diff options
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() + ")"); + } } |