Skip to content
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/main/java/org/codedifferently/CoffeeItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.codedifferently;

public class CoffeeItem {

private String name;
private double price;

// Constructor
public CoffeeItem(String name, double price) {
this.name = name;
this.price = price;
}

// Getters
public String getName() {
return name;
}

public double getPrice() {
return price;
}

// Setters
public void setName(String name) {
this.name = name;
}

public void setPrice(double price) {
this.price = price;
}

}
66 changes: 66 additions & 0 deletions src/main/java/org/codedifferently/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.codedifferently;

public class Customer {

private String name;
private String phoneNumber;
private int drinksPurchased;

// Constructor
public Customer(String name, String phoneNumber, int drinksPurchased) {
this.name = name;
this.phoneNumber = phoneNumber;
this.drinksPurchased = drinksPurchased;
}

// Getters
public String getName() {
return name;
}

public String getPhoneNumber() {
return phoneNumber;
}

public int getDrinksPurchased() {
return drinksPurchased;
}

// Setters
public void setName(String name) {
this.name = name;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public void setDrinksPurchased(int drinksPurchased) {
this.drinksPurchased = drinksPurchased;
}

// Add one drink to rewards counter
public void incrementDrinks() {
drinksPurchased = drinksPurchased + 1;
}

// Check if customer has reward (5 drinks)
public boolean hasReward() {
if (drinksPurchased >= 5) {
return true;
} else {
return false;
}
}

// Redeem reward (reset count)
public void redeemReward() {
drinksPurchased = 0;
}

public String getCustomerInfo() {
return "Name: " + name +
"\nPhone Number: " + phoneNumber +
"\nDrinks Purchased: " + drinksPurchased;
}
}
116 changes: 105 additions & 11 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,111 @@
package org.codedifferently;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);

Scanner scanner = new Scanner(System.in);

// Create drinks
CoffeeItem latte = new CoffeeItem("Latte", 4.50);
CoffeeItem espresso = new CoffeeItem("Espresso", 3.00);
CoffeeItem cappuccino = new CoffeeItem("Cappuccino", 5.00);

System.out.println("Welcome to Triple C's!");

boolean shopOpen = true;

while (shopOpen) {

System.out.println("\nEnter customer name:");
String name = scanner.nextLine();

System.out.println("Enter customer email:");
String email = scanner.nextLine();

Customer customer = new Customer(name, email, 0);

System.out.println("\nMenu:");
System.out.println("1. Latte");
System.out.println("2. Espresso");
System.out.println("3. Cappuccino");
System.out.println("4. Close Shop");

int choice = scanner.nextInt();

if (choice == 4) {
shopOpen = false;
break;
}

CoffeeItem selectedDrink = null;

if (choice == 1) {
selectedDrink = latte;
} else if (choice == 2) {
selectedDrink = espresso;
} else if (choice == 3) {
selectedDrink = cappuccino;
} else {
System.out.println("Invalid choice.");
scanner.nextLine(); // clear
continue;
}

System.out.println("How many would you like?");
int quantity = scanner.nextInt();
scanner.nextLine(); // clear buffer

if (quantity <= 0) {
System.out.println("Invalid quantity.");
continue;
}

double total = selectedDrink.getPrice() * quantity;

System.out.println("\nCustomer: " + customer.getName());
System.out.println("Drinks toward reward: " + customer.getDrinksPurchased());
System.out.println("=========================");

// Reward check
if (customer.hasReward()) {

System.out.println("CONGRATS! Reward reached. Next drink is free!");
customer.redeemReward();
System.out.println("=========================");
} else {

System.out.println(customer.getName() + " purchased "
+ quantity + " " + selectedDrink.getName()
+ "(s) for $" + total);

// add drinks to reward counter
for (int i = 0; i < quantity; i++) {
customer.incrementDrinks();
}
}

// Golden Ticket
if (total > 20) {
System.out.println("Golden Ticket! You earned a bonus drink point!");
customer.incrementDrinks();
System.out.println("=========================");
}

System.out.println("Updated drinks toward reward: "
+ customer.getDrinksPurchased());
System.out.println("=========================");
System.out.println("\nNext customer? (yes/no)");
String answer = scanner.nextLine();
System.out.println("=========================");
if (answer.equalsIgnoreCase("no")) {
shopOpen = false;
}
}

System.out.println("Shop Closed!");
scanner.close();
}
}
}