public class Formatter { double totalPrice; int amountOfPeople; Formatter(double totalPrice, int amountOfPeople) { this.totalPrice = totalPrice; this.amountOfPeople = amountOfPeople; } public void printFinalResult() { double averagePrice = totalPrice / amountOfPeople; String correctRuble = "ÑÑблÑ"; int nearestInt = (int) (totalPrice / amountOfPeople); if ((nearestInt >= 5) && (nearestInt <= 20)) { correctRuble = "ÑÑблей"; } else { switch (nearestInt % 10) { case 1: { correctRuble = "ÑÑблÑ"; break; } case 2, 3, 4: { correctRuble = "ÑÑблÑ"; break; } case 5, 6, 7, 8, 9, 0: { correctRuble = "ÑÑблей"; break; } } } String template = "ÐÐ°Ð¶Ð´Ð¾Ð¼Ñ Ð¿ÑидеÑÑÑ Ð·Ð°Ð¿Ð»Ð°ÑиÑÑ Ð¿Ð¾ %.2f "; System.out.println(String.format(template, averagePrice) + correctRuble); } }