mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-04-28 19:58:12 +02:00
visibility of variables of classes are private
This commit is contained in:
@@ -2,11 +2,19 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Invoice {
|
public class Invoice {
|
||||||
|
|
||||||
public String customer;
|
private String customer;
|
||||||
public List<Performance> performances;
|
private List<Performance> performances;
|
||||||
|
|
||||||
public Invoice(String customer, List<Performance> performances) {
|
public Invoice(String customer, List<Performance> performances) {
|
||||||
this.customer = customer;
|
this.customer = customer;
|
||||||
this.performances = performances;
|
this.performances = performances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCustomer() {
|
||||||
|
return customer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Performance> getPerformances() {
|
||||||
|
return performances;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
public class Performance {
|
public class Performance {
|
||||||
|
|
||||||
public String playID;
|
private String playID;
|
||||||
public int audience;
|
private int audience;
|
||||||
|
|
||||||
public Performance(String playID, int audience) {
|
public Performance(String playID, int audience) {
|
||||||
this.playID = playID;
|
this.playID = playID;
|
||||||
this.audience = audience;
|
this.audience = audience;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlayID() {
|
||||||
|
return playID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAudience() {
|
||||||
|
return audience;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
public class Play {
|
public class Play {
|
||||||
|
|
||||||
public String name;
|
private String name;
|
||||||
public String type;
|
private String type;
|
||||||
|
|
||||||
public Play(String name, String type) {
|
public Play(String name, String type) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,39 +7,39 @@ public class StatementPrinter {
|
|||||||
public String print(Invoice invoice, Map<String, Play> plays) {
|
public String print(Invoice invoice, Map<String, Play> plays) {
|
||||||
var totalAmount = 0;
|
var totalAmount = 0;
|
||||||
var volumeCredits = 0;
|
var volumeCredits = 0;
|
||||||
var result = String.format("Statement for %s\n", invoice.customer);
|
var result = String.format("Statement for %s\n", invoice.getCustomer());
|
||||||
|
|
||||||
NumberFormat frmt = NumberFormat.getCurrencyInstance(Locale.US);
|
NumberFormat frmt = NumberFormat.getCurrencyInstance(Locale.US);
|
||||||
|
|
||||||
for (var perf : invoice.performances) {
|
for (var perf : invoice.getPerformances()) {
|
||||||
var play = plays.get(perf.playID);
|
var play = plays.get(perf.getPlayID());
|
||||||
var thisAmount = 0;
|
var thisAmount = 0;
|
||||||
|
|
||||||
switch (play.type) {
|
switch (play.getType()) {
|
||||||
case "tragedy":
|
case "tragedy":
|
||||||
thisAmount = 40000;
|
thisAmount = 40000;
|
||||||
if (perf.audience > 30) {
|
if (perf.getAudience() > 30) {
|
||||||
thisAmount += 1000 * (perf.audience - 30);
|
thisAmount += 1000 * (perf.getAudience() - 30);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "comedy":
|
case "comedy":
|
||||||
thisAmount = 30000;
|
thisAmount = 30000;
|
||||||
if (perf.audience > 20) {
|
if (perf.getAudience() > 20) {
|
||||||
thisAmount += 10000 + 500 * (perf.audience - 20);
|
thisAmount += 10000 + 500 * (perf.getAudience() - 20);
|
||||||
}
|
}
|
||||||
thisAmount += 300 * perf.audience;
|
thisAmount += 300 * perf.getAudience();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error("unknown type: ${play.type}");
|
throw new Error("unknown type: ${play.type}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// add volume credits
|
// add volume credits
|
||||||
volumeCredits += Math.max(perf.audience - 30, 0);
|
volumeCredits += Math.max(perf.getAudience() - 30, 0);
|
||||||
// add extra credit for every ten comedy attendees
|
// add extra credit for every ten comedy attendees
|
||||||
if ("comedy".equals(play.type)) volumeCredits += Math.floor(perf.audience / 5);
|
if ("comedy".equals(play.getType())) volumeCredits += Math.floor(perf.getAudience() / 5);
|
||||||
|
|
||||||
// print line for this order
|
// print line for this order
|
||||||
result += String.format(" %s: %s (%s seats)\n", play.name, frmt.format(thisAmount / 100), perf.audience);
|
result += String.format(" %s: %s (%s seats)\n", play.getName(), frmt.format(thisAmount / 100), perf.getAudience());
|
||||||
totalAmount += thisAmount;
|
totalAmount += thisAmount;
|
||||||
}
|
}
|
||||||
result += String.format("Amount owed is %s\n", frmt.format(totalAmount / 100));
|
result += String.format("Amount owed is %s\n", frmt.format(totalAmount / 100));
|
||||||
|
|||||||
Reference in New Issue
Block a user