mirror of
https://github.com/ysoftdevs/Theatrical-Players-Refactoring-Kata.git
synced 2026-01-11 22:30:27 +01: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 String customer;
|
||||
public List<Performance> performances;
|
||||
private String customer;
|
||||
private List<Performance> performances;
|
||||
|
||||
public Invoice(String customer, List<Performance> performances) {
|
||||
this.customer = customer;
|
||||
this.performances = performances;
|
||||
}
|
||||
|
||||
public String getCustomer() {
|
||||
return customer;
|
||||
}
|
||||
|
||||
public List<Performance> getPerformances() {
|
||||
return performances;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
public class Performance {
|
||||
|
||||
public String playID;
|
||||
public int audience;
|
||||
private String playID;
|
||||
private int audience;
|
||||
|
||||
public Performance(String playID, int audience) {
|
||||
this.playID = playID;
|
||||
this.audience = audience;
|
||||
}
|
||||
|
||||
public String getPlayID() {
|
||||
return playID;
|
||||
}
|
||||
|
||||
public int getAudience() {
|
||||
return audience;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
public class Play {
|
||||
|
||||
public String name;
|
||||
public String type;
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
public Play(String name, String type) {
|
||||
this.name = name;
|
||||
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) {
|
||||
var totalAmount = 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);
|
||||
|
||||
for (var perf : invoice.performances) {
|
||||
var play = plays.get(perf.playID);
|
||||
for (var perf : invoice.getPerformances()) {
|
||||
var play = plays.get(perf.getPlayID());
|
||||
var thisAmount = 0;
|
||||
|
||||
switch (play.type) {
|
||||
switch (play.getType()) {
|
||||
case "tragedy":
|
||||
thisAmount = 40000;
|
||||
if (perf.audience > 30) {
|
||||
thisAmount += 1000 * (perf.audience - 30);
|
||||
if (perf.getAudience() > 30) {
|
||||
thisAmount += 1000 * (perf.getAudience() - 30);
|
||||
}
|
||||
break;
|
||||
case "comedy":
|
||||
thisAmount = 30000;
|
||||
if (perf.audience > 20) {
|
||||
thisAmount += 10000 + 500 * (perf.audience - 20);
|
||||
if (perf.getAudience() > 20) {
|
||||
thisAmount += 10000 + 500 * (perf.getAudience() - 20);
|
||||
}
|
||||
thisAmount += 300 * perf.audience;
|
||||
thisAmount += 300 * perf.getAudience();
|
||||
break;
|
||||
default:
|
||||
throw new Error("unknown type: ${play.type}");
|
||||
}
|
||||
|
||||
// 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
|
||||
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
|
||||
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;
|
||||
}
|
||||
result += String.format("Amount owed is %s\n", frmt.format(totalAmount / 100));
|
||||
|
||||
Reference in New Issue
Block a user