I was trying to get a few separated lines of text within one System.out. There was supposed to be 4 separate lines and instead of that program only prints the last one.
I was thinking about replacing it with separate System.out for each of the lines but i'm not sure if it's the fastest solution and what is wrong with the current one.
Method that contains above mentioned code:
public double getTotal(Addition addition1, Addition addition2, Addition addition3, Addition addition4){
this.additionPrices = ("First addition - " + addition1.getName() + " costs " + addition1.getPrice() + "\r" +
"Second addition - " + addition2.getName() + " costs " + addition2.getPrice() + "\r" +
"Third addition - " + addition3.getName() + " costs " + addition3.getPrice() + "\r" +
"Fourth addition - " + addition4.getName() + " costs " + addition4.getPrice());
this.total = this.price + addition1.getPrice() + addition2.getPrice() + addition3.getPrice() + addition4.getPrice();
return (this.price + addition1.getPrice() + addition2.getPrice() + addition3.getPrice() + addition4.getPrice());
}
Main class where it's used:
public static void main(String[] args) {
Meat meat = new Meat();
Roll roll = new Roll();
Addition tomato = new Tomatos(2);
Addition lettuce = new Lettuce(1);
Addition pickle = new Pickle(3);
Addition onion = new Onion(1.5);
Hamburger hamburger = new Hamburger(meat,roll,20);
hamburger.getTotal(onion,onion, tomato, onion);
hamburger.showPrice();
}
}
Result:
Base price equals: 20.0
Total price equals: 26.5
Fourth addition - Onion costs 1.5
Process finished with exit code 0
Sorry if that's something obvious. It's my first question here and I couldnt find the answer in old questions.