Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 5 -Hamburger For this assignment, you will create an application for

ID: 3712109 • Letter: A

Question

Assignment 5 -Hamburger

For this assignment, you will create an application for a hamburger restaurant.

Name this folder Assignment5

Include comments at the top of both of your Java files that include your name, course, assignment, and due date. For example, the top of my application may look like:

Hamburger Class

Write a Hamburger class with the following six attributes:

• bun - the type of bun the burger will be on

• patties - the number of patties on the burger

• cheese - whether or not the burger will have cheese

• price - the price of the burger

• toppings - an array of five toppings; it will need to start empty

Write getters/setters for all attributes except the toppings array.

Your constructor should create a single on white with no cheese and no toppings with a price of 1.99.

Your class should include the following methods in this order, please:

addCheese - this method has no parameters that adds cheese to the burger and increases the price by 50 cents

superSizeIt - this method has no parameters and adds a patty to the burger and increases the price by 1.00

addToppings - this method would present the user with at least five toppings (your choice) stored in an array of String objects. If the user indicates the wants the item, store the String in the toppings array. There would be no change in price

burgerDetails - this method prints the details of the burger order. It should include whether or not it has cheese, the number of patties, the type of bun, the toppings and the final price

Driver Class

Write a driver class to test your Hamburger class. Assume you have two visitors to your burger joint. Use your creativity to welcome the customers and take their order. Create an instance of the hamburger class for each customer.

For each customer do the following:

• ask if he would like cheese, if so, call the addCheese method

• ask if he would like to super size the meal, if so, call the superSizeIt method

• ask what type of bun he would like and pass that to the setter for your bun attribute

• call your addToppings method

• call your burgerDetails method to display the details of the burger order

Be sure to compile and run your application. Take a screenshot of your successful test run.

Deliverable

ZIP THE FOLDER YOU CREATED WITH YOUR FILES IN IT.

Submit this zipped folder and your screenshot to the appropriate dropbox.

Explanation / Answer

/**
*
*/
package burger;

import java.util.Scanner;

public class Hamburger {

   private String bun;
   private int patties;
   private boolean cheese;
   private double price;
   private String[] toppings;

   // constructor
   public Hamburger() {
       this.bun = "Single on white";
       this.cheese = false;
       this.price = 1.99;
       this.toppings = new String[5];
   }

   // Getters and Setters
   public String getBun() {
       return bun;
   }

   public void setBun(String bun) {
       this.bun = bun;
   }

   public int getPatties() {
       return patties;
   }

   public void setPatties(int patties) {
       this.patties = patties;
   }

   public boolean isCheese() {
       return cheese;
   }

   public void setCheese(boolean cheese) {
       this.cheese = cheese;
   }

   public double getPrice() {
       return price;
   }

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

   public String[] getToppings() {
       return toppings;
   }

   public void setToppings(String[] toppings) {
       this.toppings = toppings;
   }

   /**
   * this method has no parameters that adds cheese to the burger and increases
   * the price by 50 cents
   */
   public void addCheese() {
       this.setCheese(true);
       this.setPrice(getPrice() + 50);

   }

   /**
   * this method has no parameters and adds a patty to the burger and increases
   * the price by 1.00
   */
   public void superSizeIt() {
       this.setPatties(getPatties() + 1);
       this.setPrice(getPrice() + 1);
   }

   /**
   * this method would present the user with at least five toppings (your choice)
   * stored in an array of String objects. If the user indicates the wants the
   * item, store the String in the toppings array. There would be no change in
   * price
   */
   public void addToppings() {

       String [] defaulttopping=new String[] {
               "Latin Macho Burger.","Grilled Tomato Ketchup","Chow-Chow Burger","KGB Burger","Burgers with Crispy Pepperoni"
       };
       int i=1;
       System.out.println("Please select one of the following toppings ");
       for (String string : defaulttopping) {
           System.out.println(i+" . "+string);
           i++;
       }
       Scanner sc=new Scanner(System.in);
       int choice=sc.nextInt();
       if(choice<1 && choice>5)
       {
           System.out.println("Invalid Choice!! ");
          
       }
       else
       {
       for (int j=0;j<toppings.length;j++) {
          
           if(toppings[j]==null ||toppings[j].isEmpty())
           {
               this.toppings[j]=defaulttopping[choice-1];
               break;
           }
       }
       }
   }

   /***
   * this method prints the details of the burger order. It should include whether
   * or not it has cheese, the number of patties, the type of bun, the toppings
   * and the final price
   *
   * @return
   */
   public void burgerDetails() {

       System.out.println("Details of hamburger are : ");
       System.out.println("Bun : " + bun);
       System.out.println("Number of Patties : " + patties);
       if (cheese) {
           System.out.println("Burger Has Cheese");
       } else {
           System.out.println("Burger Doesn't have Cheese");
       }
       System.out.println("Price of Burger : " + price);
       System.out.println("Topping are : ");
       for (String string : this.toppings) {
           if(string!=null)
           {
               System.out.print(string);
           }
       }
   }

}

/**
*
*/
package burger;

import java.util.Scanner;

public class HamburgerDriver {

   /**
   * @param args
   */
   public static void main(String[] args) {

       int numberOfCustomers=2;
       Scanner sc=new Scanner(System.in);
       for(int i=0;i<numberOfCustomers;i++)
       {
           System.out.println(" ........Welcome Sir ! ...");
           Hamburger burger=new Hamburger();
           System.out.println("Would you like cheese , yes or no");
           boolean cheese=sc.nextLine().equalsIgnoreCase("yes");
           burger.addCheese();
           System.out.println("would you like to super size the meal, yes or no");
           boolean superSize=sc.nextLine().equalsIgnoreCase("yes");
           burger.superSizeIt();
           System.out.println("What type of Bun you like");
           String bun=sc.nextLine();
           burger.setBun(bun);
           //call addToppings
           burger.addToppings();
           //call burgerDetails
           burger.burgerDetails();
          
       }
   }

}

output


........Welcome Sir ! ...
Would you like cheese , yes or no
yes
would you like to super size the meal, yes or no
yes
What type of Bun you like
ExtraLarge
Please select one of the following toppings
1 . Latin Macho Burger.
2 . Grilled Tomato Ketchup
3 . Chow-Chow Burger
4 . KGB Burger
5 . Burgers with Crispy Pepperoni
1
Details of hamburger are :
Bun : ExtraLarge
Number of Patties : 1
Burger Has Cheese
Price of Burger : 52.99
Topping are :
Latin Macho Burger.


........Welcome Sir ! ...
Would you like cheese , yes or no
no
would you like to super size the meal, yes or no
no
What type of Bun you like
Small
Please select one of the following toppings
1 . Latin Macho Burger.
2 . Grilled Tomato Ketchup
3 . Chow-Chow Burger
4 . KGB Burger
5 . Burgers with Crispy Pepperoni
2
Details of hamburger are :
Bun : Small
Number of Patties : 1
Burger Has Cheese
Price of Burger : 52.99
Topping are :
Grilled Tomato Ketchup