Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.81 KB | None | 0 0
  1.  
  2.  
  3. i need some help .I have a project, but there is one thing I do not know how to do, which is, how do I allow the program to print all the requests received and count them together on the bill. this is the code.
  4.  
  5.  
  6.  
  7. package proj3;
  8.  
  9.  
  10. import java.io.File;
  11. import java.io.FileNotFoundException;
  12. import java.io.FileWriter;
  13. import java.util.Random ;
  14. import java.io.IOException;
  15. import java.util.Scanner;
  16.  
  17.  
  18. public class Proj3 {
  19.  
  20.    
  21.     public static void main(String[] args) throws FileNotFoundException {
  22.        
  23.  //==============================file have the meun====================================  
  24.  
  25.      File file = new File("\\Users\\moo-m\\Documents\\NetBeansProjects\\file\\menu1.txt");
  26.      Scanner scan = new Scanner(file);
  27.      while (scan.hasNextLine()){
  28.      System.out.println(scan.nextLine());
  29.      }
  30.      
  31.  //===================coustmer information====================
  32.      PizzaOrder p1 = new PizzaOrder();
  33.         Scanner scanner = new Scanner(System.in);
  34.            try{
  35.                 System.out.print("Name: ");
  36.                 p1.setName(scanner.nextLine());
  37.                 System.out.print("Phone: ");
  38.                 p1.setPhoneNumber(scanner.nextInt());
  39.            }catch(Exception m){
  40.            System.out.println("sorry, you writ something wrong");
  41.            }
  42.            
  43.  //===================================loop for how many time the coustmer want to order=======================================
  44.             int pizzanumber ;
  45.             int countPizza  = 1;
  46.             //Declare input Scanners
  47.             Scanner numpizza = new Scanner(System.in);
  48.          
  49.             //Adding a new Order
  50.             System.out.println("==============================");
  51.             System.out.println("Enter number of Pizza Orders: ");
  52.             pizzanumber = numpizza.nextInt();
  53.            
  54.             //declaring a counter
  55.             int i = 1;
  56.             //creating a loop to display entry details for pizzas
  57.             while (i<=pizzanumber){
  58.                 System.out.println("Enter Details of Pizza Order " + countPizza  + ":");
  59.                 System.out.println("=================================================");
  60.                 countPizza += + 1;
  61.                
  62.                 i++;
  63.                
  64. //==================================take the order from coustmer===========================================
  65.          Scanner scann = new Scanner(System.in);
  66.          try{  
  67.          System.out.println("Enter your favorit pizza: ");
  68.          p1.setOrder(scann.nextLine());
  69.          System.out.println("What would you like the size will be? ");
  70.          p1.setsize(scann.nextLine());
  71.          System.out.println("Do you want to add something (yes - no): ");
  72.          p1.setadd(scann.nextLine());
  73.          
  74.          //*****************
  75.          String s1= "cheese";
  76.          String s2= "chickens";    // addtion add
  77.          String s3= "Bell pepper";
  78.          //***********************
  79.          
  80.          if (p1.getadd().equals("yes")){
  81.              
  82.           Scanner p3 = new Scanner (System.in);
  83.           System.out.println("the addtion that we have are:"+"\n"+" 1)cheese "+"\n"+"2)chickens"+"\n"+"3)Bell pepper");
  84.            p3.nextLine();
  85.            if(p3.equals(s1)){
  86.              System.out.println("the addtion will cast you 5($) ");
  87.             }
  88.             if(p3.equals(s2)){
  89.              System.out.println("the addtion will cast you 5($) ");
  90.             }
  91.             if(p3.equals(s3)){
  92.              System.out.println("the addtion will cast you 5($) ");
  93.            }
  94.                
  95.          }
  96.                  
  97.         }
  98.        catch(Exception m){
  99.            System.out.println("An error occurred.");  
  100.        }        
  101.             }
  102.            
  103.  //===============================file for what tha input will save==========================
  104.                 try {
  105.                     FileWriter myWriter = new FileWriter("filename.txt");
  106.                     myWriter.write(p1.getName());
  107.                     myWriter.write(p1.getPhoneNumber());
  108.                     myWriter.write(p1.getOrder()+ p1.getsize());
  109.                     myWriter.close();
  110.                     System.out.println("");
  111.                 } catch (IOException e) {
  112.                     System.out.println("An error occurred.");
  113.                    
  114.                 }
  115.  
  116. //=====================printing the bill ==========================
  117. System.out.println(p1.printbill());
  118. }}  
  119.  class PizzaOrder {
  120.   public String printbill(){
  121.  //order number  
  122. Random ran = new Random();
  123. int n = ran.nextInt(100);
  124.  
  125.  
  126. System.out.println("*******************************************************");
  127. System.out.println("                       your bill                       ");
  128. System.out.println("*******************************************************");
  129. System.out.println("  |    your order number is :"+ n+                   "|");
  130. System.out.println("  |    Name:"+getName()+                             "|");    
  131. System.out.println("  |    Phone:"+getPhoneNumber()+                     "|");
  132. System.out.println("  |    Order: "+ getOrder()+"("+getsize()+")"+       "|");  
  133. System.out.println("  |    Pizza Cost ($): "+ determinePizzaPrice()+     "|");
  134. System.out.println("  |    the addition order will cost you  + 5($)       |");
  135. System.out.println("*******************************************************");
  136. System.out.println("  |     total to pay ($): " +totalCost()+            "|");
  137. System.out.println("*******************************************************");
  138. return                       "thank you for visiting our restaurant";
  139. }
  140.  
  141.  
  142.  //declaring variables
  143.  
  144.   private String name;
  145.   private  int phoneNumber;
  146.   private String order;
  147.   private String type;
  148.   private String size;
  149.   private String add;
  150.  
  151. //=================================================================  
  152.   public void setName(String name) {
  153.     this.name = name;
  154.   }
  155.  
  156.   public void setPhoneNumber(int phoneNumber) {
  157.     this.phoneNumber = phoneNumber;
  158.   }
  159.  
  160.   public void setOrder(String order) {
  161.     this.order = order;
  162.   }
  163.  
  164.   public void setsize(String size) {
  165.     this.size = size;
  166.   }
  167.   public void setadd(String add) {
  168.     this.add = add;
  169.   }
  170.  
  171.   ///=======================================================
  172.   public String getName() {
  173.     return name;
  174.   }
  175.  
  176.   public int getPhoneNumber() {
  177.     return phoneNumber;
  178.   }
  179.  
  180.   public String getOrder() {
  181.     return order;
  182.   }
  183.   public String getsize() {
  184.     return size;
  185.   }
  186.  public String getadd() {
  187.     return add;
  188.   }
  189.  
  190. //==============================================================
  191.   double totalCost; //c is the total cost (in dollars)
  192.   double price; //p is the cost of the pizza
  193.   double price1 ;
  194.  
  195. //===================================================
  196. //method for determining pizza price
  197.  
  198.   public double determinePizzaPrice(){
  199.       switch (getOrder()) {
  200.          
  201.       //end if for order Pepperoni Pizza
  202.           case "Pepperoni Pizza":
  203.       switch (getsize()) {
  204.           case "small":
  205.               price =10;
  206.               break;
  207.           case "medium":
  208.               price =20;
  209.               break;
  210.           case "large":
  211.               price =30;
  212.               break;
  213.           default:
  214.               break;
  215.       }
  216. break;
  217.  
  218.       //end else-if for order Cheese pizza
  219.           case "Cheese pizza":
  220.       switch (getsize()) {
  221.           case "small":
  222.               price =10;
  223.               break;
  224.           case "medium":
  225.               price =20;
  226.               break;
  227.           case "large":
  228.               price =30;
  229.               break;
  230.           default:
  231.               break;
  232.       }
  233. break;
  234.       //end else-if for order vegetable pizza
  235.  
  236.           case "vegetable Pizza":
  237.       switch (getsize()) {
  238.           case "small":
  239.               price =10;
  240.               break;
  241.           case "medium":
  242.               price =20;
  243.               break;
  244.           case "large":
  245.               price =30;
  246.               break;
  247.           default:
  248.               break;
  249.       }
  250. break;
  251.       //end else-if for order BBQ Pizza
  252.           case "BBQ Pizza":
  253.       switch (getsize()) {
  254.           case "small":
  255.               price =10;
  256.               break;
  257.           case "medium":
  258.               price =20;
  259.               break;
  260.           case "large":
  261.               price =30;
  262.               break;
  263.           default:
  264.               break;
  265.       }
  266. break;
  267.           default:
  268.               System.out.println("Error: Incorrect Order name has been entered.");
  269.               break; //end else
  270.       }
  271.     return price;
  272.   }
  273.  
  274.  //====================method for total cost for addtion================================
  275.   public double totalCost(){
  276.    if (getadd().equals("yes")){
  277.        
  278.        price1= 5;
  279.    }
  280.    else {
  281.    price1= 0;
  282.    }
  283.     return totalCost = price + price1 ;
  284.   }
  285.  
  286.  
  287.  
  288.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement