Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- package proj3;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.util.Random ;
- import java.io.IOException;
- import java.util.Scanner;
- public class Proj3 {
- public static void main(String[] args) throws FileNotFoundException {
- //==============================file have the meun====================================
- File file = new File("\\Users\\moo-m\\Documents\\NetBeansProjects\\file\\menu1.txt");
- Scanner scan = new Scanner(file);
- while (scan.hasNextLine()){
- System.out.println(scan.nextLine());
- }
- //===================coustmer information====================
- PizzaOrder p1 = new PizzaOrder();
- Scanner scanner = new Scanner(System.in);
- try{
- System.out.print("Name: ");
- p1.setName(scanner.nextLine());
- System.out.print("Phone: ");
- p1.setPhoneNumber(scanner.nextInt());
- }catch(Exception m){
- System.out.println("sorry, you writ something wrong");
- }
- //===================================loop for how many time the coustmer want to order=======================================
- int pizzanumber ;
- int countPizza = 1;
- //Declare input Scanners
- Scanner numpizza = new Scanner(System.in);
- //Adding a new Order
- System.out.println("==============================");
- System.out.println("Enter number of Pizza Orders: ");
- pizzanumber = numpizza.nextInt();
- //declaring a counter
- int i = 1;
- //creating a loop to display entry details for pizzas
- while (i<=pizzanumber){
- System.out.println("Enter Details of Pizza Order " + countPizza + ":");
- System.out.println("=================================================");
- countPizza += + 1;
- i++;
- //==================================take the order from coustmer===========================================
- Scanner scann = new Scanner(System.in);
- try{
- System.out.println("Enter your favorit pizza: ");
- p1.setOrder(scann.nextLine());
- System.out.println("What would you like the size will be? ");
- p1.setsize(scann.nextLine());
- System.out.println("Do you want to add something (yes - no): ");
- p1.setadd(scann.nextLine());
- //*****************
- String s1= "cheese";
- String s2= "chickens"; // addtion add
- String s3= "Bell pepper";
- //***********************
- if (p1.getadd().equals("yes")){
- Scanner p3 = new Scanner (System.in);
- System.out.println("the addtion that we have are:"+"\n"+" 1)cheese "+"\n"+"2)chickens"+"\n"+"3)Bell pepper");
- p3.nextLine();
- if(p3.equals(s1)){
- System.out.println("the addtion will cast you 5($) ");
- }
- if(p3.equals(s2)){
- System.out.println("the addtion will cast you 5($) ");
- }
- if(p3.equals(s3)){
- System.out.println("the addtion will cast you 5($) ");
- }
- }
- }
- catch(Exception m){
- System.out.println("An error occurred.");
- }
- }
- //===============================file for what tha input will save==========================
- try {
- FileWriter myWriter = new FileWriter("filename.txt");
- myWriter.write(p1.getName());
- myWriter.write(p1.getPhoneNumber());
- myWriter.write(p1.getOrder()+ p1.getsize());
- myWriter.close();
- System.out.println("");
- } catch (IOException e) {
- System.out.println("An error occurred.");
- }
- //=====================printing the bill ==========================
- System.out.println(p1.printbill());
- }}
- class PizzaOrder {
- public String printbill(){
- //order number
- Random ran = new Random();
- int n = ran.nextInt(100);
- System.out.println("*******************************************************");
- System.out.println(" your bill ");
- System.out.println("*******************************************************");
- System.out.println(" | your order number is :"+ n+ "|");
- System.out.println(" | Name:"+getName()+ "|");
- System.out.println(" | Phone:"+getPhoneNumber()+ "|");
- System.out.println(" | Order: "+ getOrder()+"("+getsize()+")"+ "|");
- System.out.println(" | Pizza Cost ($): "+ determinePizzaPrice()+ "|");
- System.out.println(" | the addition order will cost you + 5($) |");
- System.out.println("*******************************************************");
- System.out.println(" | total to pay ($): " +totalCost()+ "|");
- System.out.println("*******************************************************");
- return "thank you for visiting our restaurant";
- }
- //declaring variables
- private String name;
- private int phoneNumber;
- private String order;
- private String type;
- private String size;
- private String add;
- //=================================================================
- public void setName(String name) {
- this.name = name;
- }
- public void setPhoneNumber(int phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
- public void setOrder(String order) {
- this.order = order;
- }
- public void setsize(String size) {
- this.size = size;
- }
- public void setadd(String add) {
- this.add = add;
- }
- ///=======================================================
- public String getName() {
- return name;
- }
- public int getPhoneNumber() {
- return phoneNumber;
- }
- public String getOrder() {
- return order;
- }
- public String getsize() {
- return size;
- }
- public String getadd() {
- return add;
- }
- //==============================================================
- double totalCost; //c is the total cost (in dollars)
- double price; //p is the cost of the pizza
- double price1 ;
- //===================================================
- //method for determining pizza price
- public double determinePizzaPrice(){
- switch (getOrder()) {
- //end if for order Pepperoni Pizza
- case "Pepperoni Pizza":
- switch (getsize()) {
- case "small":
- price =10;
- break;
- case "medium":
- price =20;
- break;
- case "large":
- price =30;
- break;
- default:
- break;
- }
- break;
- //end else-if for order Cheese pizza
- case "Cheese pizza":
- switch (getsize()) {
- case "small":
- price =10;
- break;
- case "medium":
- price =20;
- break;
- case "large":
- price =30;
- break;
- default:
- break;
- }
- break;
- //end else-if for order vegetable pizza
- case "vegetable Pizza":
- switch (getsize()) {
- case "small":
- price =10;
- break;
- case "medium":
- price =20;
- break;
- case "large":
- price =30;
- break;
- default:
- break;
- }
- break;
- //end else-if for order BBQ Pizza
- case "BBQ Pizza":
- switch (getsize()) {
- case "small":
- price =10;
- break;
- case "medium":
- price =20;
- break;
- case "large":
- price =30;
- break;
- default:
- break;
- }
- break;
- default:
- System.out.println("Error: Incorrect Order name has been entered.");
- break; //end else
- }
- return price;
- }
- //====================method for total cost for addtion================================
- public double totalCost(){
- if (getadd().equals("yes")){
- price1= 5;
- }
- else {
- price1= 0;
- }
- return totalCost = price + price1 ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement