fork download
  1. import java.io.PrintStream;
  2. import java.math.BigDecimal;
  3. import java.math.RoundingMode;
  4. import java.nio.charset.StandardCharsets;
  5. import java.util.Locale;
  6.  
  7. public class Main {
  8.  
  9. private static final class TuitionPlan {
  10. private final BigDecimal hourlyRateGbp;
  11. private final int lessonMinutes;
  12. private final BigDecimal lessonsPerWeek;
  13. private final int numberOfWeeks;
  14.  
  15. TuitionPlan(
  16. BigDecimal hourlyRateGbp,
  17. int lessonMinutes,
  18. BigDecimal lessonsPerWeek,
  19. int numberOfWeeks) {
  20.  
  21. this.hourlyRateGbp = hourlyRateGbp;
  22. this.lessonMinutes = lessonMinutes;
  23. this.lessonsPerWeek = lessonsPerWeek;
  24. this.numberOfWeeks = numberOfWeeks;
  25. }
  26.  
  27. void validate() {
  28. if (hourlyRateGbp.compareTo(BigDecimal.ZERO) <= 0) {
  29. "Hourly rate must be greater than zero."
  30. );
  31. }
  32.  
  33. if (lessonMinutes < 15 || lessonMinutes > 180) {
  34. "Lesson length must be between 15 and 180 minutes."
  35. );
  36. }
  37.  
  38. if (lessonsPerWeek.compareTo(BigDecimal.ZERO) <= 0) {
  39. "Lessons per week must be greater than zero."
  40. );
  41. }
  42.  
  43. if (numberOfWeeks < 1 || numberOfWeeks > 52) {
  44. "Number of weeks must be between 1 and 52."
  45. );
  46. }
  47. }
  48.  
  49. BigDecimal lessonCost() {
  50. return hourlyRateGbp
  51. .multiply(BigDecimal.valueOf(lessonMinutes))
  52. .divide(
  53. BigDecimal.valueOf(60),
  54. 2,
  55. RoundingMode.HALF_UP
  56. );
  57. }
  58.  
  59. BigDecimal fourWeekCost() {
  60. return lessonCost()
  61. .multiply(lessonsPerWeek)
  62. .multiply(BigDecimal.valueOf(4))
  63. .setScale(2, RoundingMode.HALF_UP);
  64. }
  65.  
  66. BigDecimal periodCost() {
  67. return lessonCost()
  68. .multiply(lessonsPerWeek)
  69. .multiply(BigDecimal.valueOf(numberOfWeeks))
  70. .setScale(2, RoundingMode.HALF_UP);
  71. }
  72. }
  73.  
  74. private static String money(BigDecimal value) {
  75. return String.format(Locale.UK, "£%,.2f", value);
  76. }
  77.  
  78. public static void main(String[] args) {
  79. // Ensure that the pound sign is printed correctly.
  80. System.setOut(
  81. System.out,
  82. true,
  83. StandardCharsets.UTF_8
  84. )
  85. );
  86.  
  87. /*
  88.   * Edit these four values before running:
  89.   *
  90.   * 30 = hourly rate in pounds
  91.   * 60 = lesson length in minutes
  92.   * 1 = lessons per week
  93.   * 12 = number of weeks
  94.   */
  95. TuitionPlan plan = new TuitionPlan(
  96. new BigDecimal("30"),
  97. 60,
  98. new BigDecimal("1"),
  99. 12
  100. );
  101.  
  102. plan.validate();
  103.  
  104. System.out.println("ONLINE TUITION BUDGET EXAMPLE");
  105. System.out.println("-".repeat(36));
  106.  
  107. System.out.printf(
  108. "Hourly rate: %s%n",
  109. money(plan.hourlyRateGbp)
  110. );
  111.  
  112. System.out.printf(
  113. "Lesson length: %d minutes%n",
  114. plan.lessonMinutes
  115. );
  116.  
  117. System.out.printf(
  118. "Lessons per week: %s%n",
  119. plan.lessonsPerWeek.toPlainString()
  120. );
  121.  
  122. System.out.printf(
  123. "Selected period: %d weeks%n",
  124. plan.numberOfWeeks
  125. );
  126.  
  127. System.out.println();
  128.  
  129. System.out.printf(
  130. "Cost per lesson: %s%n",
  131. money(plan.lessonCost())
  132. );
  133.  
  134. System.out.printf(
  135. "Four-week example: %s%n",
  136. money(plan.fourWeekCost())
  137. );
  138.  
  139. System.out.printf(
  140. "Period total: %s%n",
  141. money(plan.periodCost())
  142. );
  143.  
  144. System.out.println();
  145. System.out.println("Before booking, confirm:");
  146.  
  147. String[] prompts = {
  148. "the tutor's current live rate and lesson length",
  149. "subject, level and exam-board experience",
  150. "normal availability and cancellation terms",
  151. "how progress and homework will be handled",
  152. "the online platform and safeguarding arrangements"
  153. };
  154.  
  155. for (int i = 0; i < prompts.length; i++) {
  156. System.out.printf("%d. %s%n", i + 1, prompts[i]);
  157. }
  158.  
  159. System.out.println();
  160. System.out.println(
  161. "One UK directory using a pay-as-you-go model:"
  162. );
  163. System.out.println(
  164. "https://l...content-available-to-author-only...n.com/find-a-tutor"
  165. );
  166. System.out.println(
  167. "Live profiles and current terms are the source of truth."
  168. );
  169. }
  170. }
Success #stdin #stdout 0.11s 57156KB
stdin
Standard input is empty
stdout
ONLINE TUITION BUDGET EXAMPLE
------------------------------------
Hourly rate:       £30.00
Lesson length:     60 minutes
Lessons per week:  1
Selected period:   12 weeks

Cost per lesson:   £30.00
Four-week example: £120.00
Period total:      £360.00

Before booking, confirm:
1. the tutor's current live rate and lesson length
2. subject, level and exam-board experience
3. normal availability and cancellation terms
4. how progress and homework will be handled
5. the online platform and safeguarding arrangements

One UK directory using a pay-as-you-go model:
https://l...content-available-to-author-only...n.com/find-a-tutor
Live profiles and current terms are the source of truth.