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.

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

public class CoffeeItem {
private String itemName; //name of the item
private double price; //price of the item

//constructor for the item
CoffeeItem(String itemName, double price){
this.itemName = itemName;
this.price = price;
}

//setters and getters for the coffee item
public String getItemName(){
return itemName;
}

public void setItemName(String itemName) {
this.itemName = itemName;
}

public double getPrice() {
return price;
}

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

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

public class Customer {
private String name; //name of the customer
private String email; //email for the customer
private int drinksPurchased; //number of drinks the customer purchased
Customer(){
}

//Constructor for the customer object
Customer(String name, String email, int drinksPurchased){
this.name = name;
this.email = email;
this.drinksPurchased = drinksPurchased;
}

//setters and getters for the instance variables
public String getName(){
return name;
}

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

public String getEmail() {
return email;
}

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

public int getDrinksPurchased() {
return drinksPurchased;
}

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


//checks to see if the customer is eligible for a reward
public boolean isEligibleForReward(){
if(drinksPurchased >= 5){
return true;
}
return false;
}
}// ends Customer class
85 changes: 75 additions & 10 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,82 @@
package org.codedifferently;

import java.util.*;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
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 input = new Scanner(System.in); //scanner object

//vars for the customer, the customer's order, boolean var for the menu checkout, and the receipt object
Customer customer1 = new Customer("Bryant", "bob@gmail.com",0);
boolean checkout = false;
String customerOrder ="";
Receipt receipt = new Receipt();

//Prompts the user for their order, displays the menu, and displays their receipt
do {
System.out.println("Welcome " + customer1.getName() + " to Triple Cs!");
System.out.println("*************************************");
System.out.println("Our Menu:");
System.out.println("1) Coffee $10.00");
System.out.println("2) Tea $5.50");
System.out.println("3) Lemonade $12.00");
System.out.println("4) Water $17.50");
System.out.println("5) Soda $10.50");
System.out.println("6) Milkshake $8.00");
System.out.println();
System.out.println("Please enter the number(s) of the drink(s) you would like to order.");
System.out.println("Separate multiple items with a comma (e.g., 1,3,5).");

boolean validOrder = false;

while (!validOrder) {

customerOrder = input.nextLine();

// checks if input contains ONLY digits 1-6 and commas
if (customerOrder.matches("[1-6,]+")) {
validOrder = true;
} else {
System.out.println("Invalid selection. Please enter numbers 1-6 only.");
System.out.println("Try again:");
}
}

System.out.println("*************************************");
receipt.createCustomerOrder(customer1, customerOrder);
System.out.println(receipt.getFullReceipt());
System.out.println("*************************************");
receipt.checkRewards(customer1, receipt.getTotalAmt());
System.out.println("*************************************");

//prompts the user to check out
System.out.println("Are you ready to checkout? (y/n)");

boolean validAnswer = false;
String choice = "";

while (!validAnswer) {

choice = input.nextLine().toLowerCase();

/*this chunk of code checks to see if the user's choice is a valid input
and if they want to continue shopping or not*/
if (choice.matches("[yn]")) {
validAnswer = true;

if (choice.equals("y")) {
System.out.println("Goodbye, have a great day!");
checkout = true;
}

} else {
System.out.println("Invalid selection. Please enter y or n.");
System.out.println("Try again:");
}
}

} while(!checkout);
}


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

public class Receipt
{
private double totalAmt; //customer's total bill amount
private StringBuilder orderSummary = new StringBuilder("You ordered:\n"); //creates the customer's receipt

//setters and getters for the instance variables
public void setTotalAmt(double totalAmt) {
this.totalAmt = totalAmt;
}

public double getTotalAmt() {
return totalAmt;
}

//creates the receipt for the customer by creating coffeeItem objects
public StringBuilder createCustomerOrder(Customer customer, String customerOrder){
int drinkCounter = 0;
for (int i=0; i< customerOrder.length(); i++) {

switch (Character.getNumericValue(customerOrder.charAt(i))) {
case 1:
CoffeeItem item1 = new CoffeeItem("Coffee", 10.00);
orderSummary.append(
String.format("%s $%.2f%n", item1.getItemName(), item1.getPrice())
);
drinkCounter++;
totalAmt += item1.getPrice();
break;

case 2:
CoffeeItem item2 = new CoffeeItem("Tea", 5.50);
orderSummary.append(
String.format("%s $%.2f%n", item2.getItemName(), item2.getPrice())
);
drinkCounter++;
totalAmt += item2.getPrice();
break;

case 3:
CoffeeItem item3 = new CoffeeItem("Lemonade", 12.00);
orderSummary.append(
String.format("%s $%.2f%n", item3.getItemName(), item3.getPrice())
);
drinkCounter++;
totalAmt += item3.getPrice();
break;

case 4:
CoffeeItem item4 = new CoffeeItem("Water", 17.50);
orderSummary.append(
String.format("%s $%.2f%n", item4.getItemName(), item4.getPrice())
);
drinkCounter++;
totalAmt += item4.getPrice();
break;

case 5:
CoffeeItem item5 = new CoffeeItem("Soda", 10.50);
orderSummary.append(
String.format("%s $%.2f%n", item5.getItemName(), item5.getPrice())
);
drinkCounter++;
totalAmt += item5.getPrice();
break;

case 6:
CoffeeItem item6 = new CoffeeItem("Milkshake", 8.00);
orderSummary.append(
String.format("%s $%.2f%n", item6.getItemName(), item6.getPrice())
);
drinkCounter++;
totalAmt += item6.getPrice();
break;
}
}

customer.setDrinksPurchased(customer.getDrinksPurchased() + drinkCounter);

return orderSummary;
}

//returns the customer's receipt '
public String getFullReceipt() {
return orderSummary.toString() + String.format("%nYour total is $%.2f", totalAmt);
}

//checks to see if the customer has earned any awards and displays a message to the user
public void checkRewards(Customer customer, double total){
if (customer.isEligibleForReward()) {
System.out.println("Congrats, You are eligible for a reward!\nYour next drink is free!");
}
if (total > 20.00){
System.out.println("You have gained bonus points on your account.");
}

if(customer.getDrinksPurchased() < 5){
System.out.println("Drinks towards reward: " + (5 - customer.getDrinksPurchased()));
}

}
}