Basically I have the following method, which is a bit picky, I know, but I teach .....
public String showOrder() {
String x = "";
x = "Order Summary: \n ";
for (Order order : orders) {
x += " Product Id: " + order.getProductCode() + " Product Description: " + order.getProductDesc() +
" Order Quantity: " + order.getQuantity() + " Order Cost: £" + order.getCost() + "\n ";
}
x += "Total Cost: "+ getTotalCost() + "p Number of Orders: " + numOfOrders() + " Total Products: " + numOfProducts();
return x;
}
This returns in my test program, as I would expect with each order on its own line.
Product Id: 1...etcetc
Product Id 2...etcetc
Product Id 3...etcetc
But when I create PrintWriter, the showOrder () method outputs one long list in my .txt. file.
PrintWriter cartReceipt = new PrintWriter("Cart.txt");
cartReceipt.println(cart1.showOrder());
cartReceipt.flush();
cartReceipt.close();
Is there a way to make the same method return a good ordered list in a txt file, as in the IDE?
source
share