104 lines
2.7 KiB
Plaintext
104 lines
2.7 KiB
Plaintext
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class Order {
|
|
//Varabler
|
|
private static long counter;
|
|
private final long orderNumber;
|
|
private final List<Item> items = new ArrayList<Item>();
|
|
|
|
|
|
//Konstruktior
|
|
public Order(List<Item> itemsList){
|
|
|
|
for(Item item : itemsList){
|
|
this.items.add(item);
|
|
}
|
|
|
|
counter++;
|
|
orderNumber = counter;
|
|
}
|
|
|
|
public Order(Item [] itemsList){
|
|
|
|
for(Item item : itemsList){
|
|
this.items.add(item);
|
|
}
|
|
|
|
counter++;
|
|
orderNumber = counter;
|
|
}
|
|
|
|
public Order(Item itemEtt, Item itemTva){
|
|
|
|
this.items.add(itemEtt);
|
|
this.items.add(itemTva);
|
|
|
|
counter++;
|
|
orderNumber = counter;
|
|
}
|
|
|
|
public Order(Item itemEtt, Item itemTva, Item itemTre){
|
|
|
|
this.items.add(itemEtt);
|
|
this.items.add(itemTva);
|
|
this.items.add(itemTre);
|
|
|
|
counter++;
|
|
orderNumber = counter;
|
|
}
|
|
|
|
//Metoder
|
|
public String getReceipt(){
|
|
String receipt;
|
|
String toSplit;
|
|
String[] divString;
|
|
|
|
//Formatera utskriften
|
|
receipt = "Receipt for order #" + orderNumber + "\n";
|
|
receipt += "-----------\n";
|
|
for(Item item : items){
|
|
if (item instanceof Book) {
|
|
toSplit = item.toString();
|
|
divString = toSplit.split(",");
|
|
//divString[0] = bound
|
|
//divString[1] = price
|
|
//divString[2] = name
|
|
//divString[3] = author
|
|
receipt += "Book { name='" + divString[2] + "', author='" + divString[3] + "', bound=" + divString[0] + ", price=" + divString[1] + ", price+vat=" + + item.getPriceWithVAT() + " }\n";
|
|
}else if (item instanceof CompactDisc) {
|
|
receipt += "CD " + item.toString() + "\n";
|
|
|
|
}else if (item instanceof LongPlay) {
|
|
receipt += "LP " + item.toString() + "\n";
|
|
|
|
}
|
|
}
|
|
receipt += "Total excl. VAT: " + getTotalValue()+ "\n";
|
|
receipt += "Total ink. VAT: " + getTotalValuePlusVAT();
|
|
|
|
return receipt;
|
|
|
|
}
|
|
|
|
//Metod som hämtar pris + VAT för varje item och lägger ihop till ett totalvärde
|
|
public double getTotalValuePlusVAT(){
|
|
double totalValueWithVAT = 0;
|
|
|
|
for(Item item : items){
|
|
totalValueWithVAT += item.getPriceWithVAT();
|
|
}
|
|
return totalValueWithVAT;
|
|
|
|
}
|
|
|
|
//Metod som hämtar pris för varje item och lägger ihop till ett totalvärde
|
|
public double getTotalValue(){
|
|
double totalValue = 0;
|
|
|
|
for(Item item : items){
|
|
totalValue += item.getPrice();
|
|
}
|
|
return totalValue;
|
|
}
|
|
} |