Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Gyros.java #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/main/java/com/example/bigmac/Gyros.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,69 @@
package com.example.bigmac;

public class Gyros {
String meat;
boolean hasTomatoes;
boolean hasOnions;
boolean hasLettuce;
boolean hasTzatziki;
double price;

public Gyros(String meat, boolean hasTomatoes, boolean hasOnions, boolean hasLettuce, boolean hasTzatziki) {
this.meat = meat;
this.hasTomatoes = hasTomatoes;
this.hasOnions = hasOnions;
this.hasLettuce = hasLettuce;
this.hasTzatziki = hasTzatziki;
this.price = calculatePrice();
}

private double calculatePrice() {
double basePrice = 5.0;
double meatPrice = 0.0;
if (meat.equals("Chicken")) {
meatPrice = 1.0;
} else if (meat.equals("Lamb")) {
meatPrice = 2.0;
} else if (meat.equals("Beef")) {
meatPrice = 2.5;
}
double toppingsPrice = 0.0;
if (hasTomatoes) {
toppingsPrice += 0.5;
}
if (hasOnions) {
toppingsPrice += 0.5;
}
if (hasLettuce) {
toppingsPrice += 0.3;
}
if (hasTzatziki) {
toppingsPrice += 0.7;
}
return basePrice + meatPrice + toppingsPrice;
}

public String getMeat() {
return meat;
}

public boolean hasTomatoes() {
return hasTomatoes;
}

public boolean hasOnions() {
return hasOnions;
}

public boolean hasLettuce() {
return hasLettuce;
}

public boolean hasTzatziki() {
return hasTzatziki;
}

public double getPrice() {
return price;
}
}