Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MenuItem {
- private String name;
- private double price;
- public MenuItem(String name, double price) {
- this.name = name;
- this.price = price;
- }
- public double getPrice() {
- return price;
- }
- public void setPrice(double price) {
- this.price = price;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- MenuItem menuItem = (MenuItem) o;
- return Double.compare(menuItem.price, price) == 0 &&
- Objects.equals(name, menuItem.name);
- }
- public boolean isServedHot() {
- return false;
- }
- @Override
- public String toString() {
- return name + " - $" + price;
- }
- }
- public class Pasta extends MenuItem {
- private boolean isSalad;
- private String[] ingredients;
- public Pasta(String name, double price, boolean isSalad, String[] ingredients) {
- super(name, price);
- this.isSalad = isSalad;
- this.ingredients = ingredients;
- }
- @Override
- public double getPrice() {
- if (isSalad) {
- return super.getPrice() * 1.5;
- } else {
- return super.getPrice();
- }
- }
- @Override
- public boolean isServedHot() {
- return true;
- }
- }
- public class Juice extends MenuItem {
- private String fruits;
- public Juice(String name, double price, String fruits) {
- super(name, price);
- this.fruits = fruits;
- }
- @Override
- public boolean isServedHot() {
- return false;
- }
- @Override
- public String toString() {
- return super.toString() + " - " + fruits;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment