This repository has been archived on 2026-10-15. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
projectstem-keys-java/Practices/Trio.java
T
2024-06-13 08:40:42 -07:00

29 lines
900 B
Java

public class Trio {
private Sandwich sandwich;
private Salad salad;
private Drink drink;
public Trio(Sandwich sandwich, Salad salad, Drink drink) {
this.sandwich = sandwich;
this.salad = salad;
this.drink = drink;
}
String getName() {
return sandwich.getName() + "/" + salad.getName() + "/" + drink.getName() + " Trio";
}
double getPrice() {
double sandwichPrice = sandwich.getPrice();
double saladPrice = salad.getPrice();
double drinkPrice = drink.getPrice();
if(sandwichPrice < saladPrice && sandwichPrice < drinkPrice) {
return saladPrice + drinkPrice;
} else if(saladPrice < sandwichPrice && saladPrice < drinkPrice) {
return sandwichPrice + drinkPrice;
} else {
return sandwichPrice + saladPrice;
}
}
}