Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jcarlosgarcia/SandwichDeliveryServiceBBFWorkshop
base: 91413a2cfb
...
head fork: jcarlosgarcia/SandwichDeliveryServiceBBFWorkshop
compare: f702314aea
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
45 SandwichDeliveryServiceBBFWorkshop/src/com/knowledgeblackbelt/sandwichdelivery/Main.java
@@ -0,0 +1,45 @@
+package com.knowledgeblackbelt.sandwichdelivery;
+
+import com.knowledgeblackbelt.sandwichdelivery.model.Sandwich;
+import com.knowledgeblackbelt.sandwichdelivery.model.Supplement;
+import com.knowledgeblackbelt.sandwichdelivery.model.Worker;
+
+public class Main {
+
+ public static void main(String... args) {
+ Sandwich usa = new Sandwich("USA", 3);
+ Sandwich cheese = new Sandwich("Cheese", 3.5);
+ Sandwich ham = new Sandwich("Ham", 3);
+
+ Supplement salad = new Supplement("Salad");
+ Supplement tomato = new Supplement("Tomato");
+ Supplement egg = new Supplement("Egg");
+ Supplement corn = new Supplement("Corn");
+
+ usa.getSupplements().add(salad);
+ usa.getSupplements().add(tomato);
+
+ cheese.getSupplements().add(tomato);
+ cheese.getSupplements().add(corn);
+
+ ham.getSupplements().add(egg);
+ ham.getSupplements().add(corn);
+
+ Worker marty = new Worker("Marty", 5);
+ Worker biff = new Worker("Biff", 12);
+
+ marty.purchase(usa);
+ marty.purchase(cheese);
+
+ biff.purchase(cheese);
+ biff.purchase(ham);
+ biff.purchase(usa);
+
+ marty.listSandwiches();
+ biff.listSandwiches();
+
+ }
+
+
+
+}
View
8 SandwichDeliveryServiceBBFWorkshop/src/com/knowledgeblackbelt/sandwichdelivery/model/Sandwich.java
@@ -6,12 +6,12 @@
public class Sandwich {
private String name;
- private long price;
+ private double price;
private Worker owner;
private List<Supplement> supplements = new ArrayList<Supplement>();
- public Sandwich(String name, long price) {
+ public Sandwich(String name, double price) {
this.name = name;
this.price = price;
}
@@ -24,11 +24,11 @@ public void setName(String name) {
this.name = name;
}
- public long getPrice() {
+ public double getPrice() {
return price;
}
- public void setPrice(long price) {
+ public void setPrice(double price) {
this.price = price;
}
View
36 SandwichDeliveryServiceBBFWorkshop/src/com/knowledgeblackbelt/sandwichdelivery/model/Worker.java
@@ -5,19 +5,19 @@
public class Worker {
private String name;
- private long money;
+ private double money;
private List<Sandwich> sandwiches = new ArrayList<Sandwich>();
- public Worker(String name, long money) {
+ public Worker(String name, double money) {
this.name = name;
this.money = money;
}
- public long getMoney() {
+ public double getMoney() {
return money;
}
- public void setMoney(long money) {
+ public void setMoney(double money) {
this.money = money;
}
@@ -25,7 +25,35 @@ public void setMoney(long money) {
return sandwiches;
}
+ public void purchase(Sandwich sandwich) {
+
+ if (sandwich.getOwner() != null) {
+ System.out.println("Cannot buy such sandwich: " + sandwich + ". It has already an owner: " + sandwich.getOwner());
+ }
+
+ if (sandwich.getPrice() > this.getMoney()) {
+ System.out.println("Cannot buy such sandwich: " + sandwich + ". Worker hasn't got enough money: " + this);
+
+ } else {
+ this.setMoney(this.getMoney() - sandwich.getPrice());
+ this.getSandwiches().add(sandwich);
+ sandwich.setOwner(this);
+ }
+
+ }
+
public String toString() {
return name + " (" + money + ")";
}
+
+ public void listSandwiches() {
+
+ System.out.println("Snadwiches owned by " + this);
+
+ for (Sandwich sandwich : this.getSandwiches()) {
+ System.out.println(sandwich);
+ }
+
+ }
+
}

No commit comments for this range

Something went wrong with that request. Please try again.