Assignment brief:
You are required to create an application so that students can remotely order their teas and coffees. If they make an invalid menu choice then they should be presented with a suitable error message and the application should give the options again.
Download full brief here

Download source code here

// Start of code---------------------
import java.util.Scanner;
import java.text.DecimalFormat;

/* Usage notes:
 * Redistribution, alteration and use of this code with or without
 * modification, are permitted provided that the following conditions are met:
 * In no event shall the copyright owner be liable for any direct, indirect,
 * incidental, special, exemplary, or consequential damages arising in any
 * way out of the use of this software, even if advised of the possibility
 * of such damage.
 */


public class TeaCoffeeMenu {
   
public static void main(String[] args) {
       
        Scanner input = new Scanner(System.in);
    System.out.print("\n__________________JAVA STOP___________________\n");
           
    DecimalFormat  df = new DecimalFormat ("\u20AC0.00");
   
    double cappuccinoCost = 2.00;
    double latteCost = 2.00;
    double espressoCost = 1.50;
    double americanoCost = 1.70;
    double bewleysCost = 1.80;
    double peppermintCost = 1.50;
    double camomileCost = 1.50;
    double deliveryCost = 1.00;
    double freeDeliveryCost = 0.00;
   
    String cost = null;
    String delivery = null;
    String deliverCost = null;
    String deliveryType = null;
    String totalCost = null;
    String menuType = null;
    String drinkType = null;
       
    int menu, Coffee, deliveryNumber;
   
             
        System.out.print("\n    *Coffee Menu enter 1 * Tea Menu enter 2*");
         
            menu=input.nextInt();
   
        while (menu< 1 || menu > 2) {
            System.out.println("Please select either '1' for Coffee or '2' for Tea");
                   
                menu = input.nextInt();                   
                }             
                switch (menu)
                    {
                    case 1:{ menuType = "Coffee";
                    System.out.print("\n\t\t Coffee Menu\n");
                    System.out.print("______________________________________________\n");
                    System.out.print("\n\t1.Cappuccino\t\t\u20AC2.00");
                    System.out.print("\n\t2.Latte\t\t        \u20AC2.00");
                    System.out.print("\n\t3.Espresso\t\t\u20AC1.50");
                    System.out.print("\n\t4.Americano\t\t\u20AC1.70");
                    System.out.print("\n______________________________________________\n");
       
        int coffeeNumber;
        System.out.print("\nPlease enter Your Choice 1,2,3,or4.");
        coffeeNumber=input.nextInt();
       
              if (coffeeNumber==1){
                  System.out.println("\n\tYou have ordered a Cappuccino !");
                  System.out.println("\t\u20AC2.00");
                  drinkType = "Cappuccino";
                  cost = (df.format(cappuccinoCost));}
              else if (coffeeNumber==2){
                  System.out.println("\n\tYou have ordered a latte !");
                  System.out.println("\t\u20AC2.00");
                  drinkType = "Latte\t";
                  cost = (df.format(latteCost));}
              else if (coffeeNumber==3){
                  System.out.println("\n\tYou have ordered an Espresso !");
                  System.out.println("\t\u20AC1.50");
                  drinkType = "Espresso";
                  cost = (df.format(espressoCost));}
              else if (coffeeNumber==4){
                  System.out.print("\n\tYou have ordered an Americano !");
                  System.out.println("\t\u20AC1.70");
                  drinkType = "Americano";
                  cost = (df.format(americanoCost));}
              else if (coffeeNumber< 1 || coffeeNumber > 4){
                  System.out.print("\nPlease enter Your Choice 1,2,3,or4.");}
                  break;
    }
        case 2: { menuType = "Tea";
            System.out.print("\n\t\tTea Menu\n");
            System.out.print("_______________________________________________\n");   
            System.out.print("   1.Beweley's Breakfast Tea (Pot for \u20AC1.80) \n");
            System.out.print("   2.Peppermint Tea\t\t\u20AC1.50\n");
            System.out.print("   3.Camomile Tea\t\t\u20AC1.50\n");
            System.out.print("_______________________________________________\n");
           
        int teaNumber;          
            System.out.println("\nEnter Your Choice 1,2,or3.");       
            teaNumber=input.nextInt();
       
              if (teaNumber==1){
                  System.out.print("\n\tYou have ordered Bewley's Breakfast Tea !");
                  drinkType = "Bewley's Breakfast \n\t\t\t  Tea (Pot)";
                  System.out.println("\t\u20AC1.80");
                  cost = (df.format(bewleysCost));}
              else if (teaNumber==2){
                  System.out.print("\n\tYou have ordered Peppermint Tea !");
                  System.out.println("\t\u20AC1.50");
                  drinkType = "Peppermint \n\t\t\t  Tea\t";
                  cost = (df.format(peppermintCost));}
              else if (teaNumber==3){
                  System.out.print("\n\t\tYou have ordered Camomile Tea ! ");
                  System.out.println("\t\u20AC1.50");
                  drinkType = "Camomile Tea";
                  cost = (df.format(camomileCost));}
              else if (teaNumber< 1 || teaNumber > 3){
                  System.out.print("\nPlease enter Your Choice 1,2,or3.");}
                   break;        
                    }   
                    default:
                    break;
                    }
        System.out.print("_______________________________________________\n");
               
        System.out.println("If You want it delivered (add £1.00) or \nFree for Collection from the Canteen");
                 
        System.out.println("\nPlease select either '1' for Delivery or \n\t\t     '2' for Collection");
               
            deliveryNumber = input.nextInt();
           
                if (deliveryNumber==1){
                        System.out.println("\nYou have selected delivery to Lab 1.2");
                        delivery = "Delivery";
                        deliveryType = "Delivery to Lab 1.2";
                        deliverCost = (df.format(deliveryCost));}
                else if (deliveryNumber==2){
                        System.out.println("\nYou have selected collection at Canteen");
                        delivery = "Collection";
                        deliveryType = "Collection at Canteen";
                        deliverCost = (df.format(freeDeliveryCost));}
                else if (deliveryNumber< 1 || deliveryNumber > 3){
                        System.out.println("Please select either '1' for Delivery or \n\t\t     '2' for Collection");}
             
        System.out.print("_______________________________________________\n");
   
    String fname, mname, lname, fullname, studentID, initials, orderNo, mobile;

        System.out.print("\nPlease enter your first name: " );       
        fname = input.next();
       
        System.out.print("\nPlease enter your middle name: " );       
        mname = input.next();
       
        System.out.print("\nPlease enter your last name: " );
        lname = input.next();
       
        fullname = fname + " " + mname + " "+ lname;
        String upper = fullname.toUpperCase();
   
            do{
                System.out.print("\nPlease enter your Studet ID Number (ie. R00123456): ");
                studentID = input.next();
            } while ( studentID.length() != 9 || 
              studentID.toUpperCase().charAt(0)!= 'R'  );
               
            do{
                System.out.print("\nPlease enter your Mobile Number (ie. 0871234567): ");
                mobile = input.next();
            } while ( mobile.length() != 10);
           
    char fnameletter = fname.charAt(0);
    char mnameletter = mname.charAt(0);
    char lnameletter = lname.charAt(0);
           
    //String initials = (fullname);
    //int spacePos = fullname.indexOf(" ");
    //System.out.println(initials.substring(0));
    //System.out.println(initials.substring(spacePos+1));

    initials = fnameletter+""+mnameletter+lnameletter;
   
    String newUpper = initials.toUpperCase();
   
    String ID = (studentID);
   
    String IDdigits;
       
    totalCost = cost + deliverCost;
   
    IDdigits = (ID.substring(5,9));
   
    orderNo = (newUpper +"_"+ID.substring(5,9));

    System.out.print("_______________________________________________\n\n");
    System.out.print("\t\t *** JAVA STOP ***\n");
    System.out.println("\n\tYOUR ORDER NUMBER IS: " + orderNo);
    System.out.println("\n\tNAME: " + upper);
    System.out.print("      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n");
    System.out.println("\n\tITEM ORDERED:     "+drinkType +"\t"+ cost );
    System.out.println("\n\tADDITIONAL ITEMS: "+ delivery +"\t"+ deliverCost );
    System.out.println("\n\tTOTAL COST:                     "+ totalCost);
    System.out.print("      _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n");
    System.out.println("\n\tDELIVERY OPTION: "+deliveryType);
    System.out.println("\n\t    Thank you for your custom");
      }
      }// End of code---------------------

0 comments:

Post a Comment

Please feel free to leave comments or ask questions related to the tutorials.