Questions & AnswersSoftware engineering

/* * To change this license header, choose License Headers in...

Question
Answered step-by-step
Asked by vitthani on coursehero.com

/* * To change this license header, choose License Headers in...

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pizzashop;

import java.util.Scanner;

/**
 Review class for Final Exam Part D review.
* Creates a pizza of a given type and cuts it into slices.
* Note that the following source was used as a reference in 
* creating this example:
* Freeman, E.Freeman, E., Sierra, K., & Bates, B. (2004). Head First Design patterns. Sebastopol, CA: O'Reilly.
* @author dancye, 2019
*/
public class PizzaShop {

  public static PizzaCutter pizzaCutter = new PizzaCutter();//we only ever want one 
  // of these. The pizza shop takes consistency very seriously
  //and all pizzas must be cut by the same cutter.
   public static void main(String[] args) 
   {
       Scanner sc = new Scanner(System.in);
       System.out.println("Welcome to the pizza shop");
       System.out.println("What kind of pizza do you want?");
       System.out.println("Please enter exactly cheese or pepperoni");
       String type = sc.nextLine();
       PizzaFactory pf = new PizzaFactory();
       Pizza pizza = pf.createPizza(type);
       System.out.println("how many slices would you like?");
       int numSlices = sc.nextInt();
       pizzaCutter.numSlices = numSlices;
       if (pizza!=null)
       {
           System.out.println("Great job, here is your pizza in " + numSlices + " slices");
           
       }
       else
       {
           System.out.println("Enter a valid pizza type so we can cut it next time!");
       }
       
   }//end main
   
}

package pizzashop;

/**
* A class to model pizzas that only have cheese on them
* Note that the following source was used as a reference in 
* creating this example:
* Freeman, E.Freeman, E., Sierra, K., & Bates, B. (2004). Head First Design patterns. Sebastopol, CA: O'Reilly.
* @author dancye
*/
public class CheesePizza extends Pizza
{
   public CheesePizza()
   {
       super();
       super.addTopping("cheese");
   }
   public void bake(int temp)
   {
       super.bakeTemp = temp;
       //do some baking here, code not implemented yet
       //not necessary for the review
   }
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pizzashop;

/**
* A class to model pizzas that have cheese and 
* pepperoni
* Note that the following source was used as a reference in 
* creating this example:
* Freeman, E.Freeman, E., Sierra, K., & Bates, B. (2004). Head First Design patterns. Sebastopol, CA: O'Reilly.
* @author dancye
*/
public class PepperoniPizza extends Pizza 
{
   public PepperoniPizza()
   {
       super();
       super.addTopping("cheese");
       super.addTopping("pepperoni");
   }
   
   public void bake(int temp)
   {
       super.bakeTemp = temp;
       //do some baking here, code not implemented yet
       //not necessary for the review
   }
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pizzashop;

import java.util.ArrayList;

/**
* A class that represents a basic pizza
* @author dancye
*/
public class Pizza 
{
   public int bakeTemp = 100;//temp to bake at
   private ArrayList<String> ingredients = new ArrayList();
   public void bake(int temp)
   {
       bakeTemp = temp;
       //do some baking here, code not implemented yet
       //not necessary for the review
   }
   /**
    *  A method to add toppings to the ingredients
    * list
    * @param topping 
    */
   public void addTopping(String topping)
   {
       ingredients.add(topping);
   }
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pizzashop;

/**
* A class that creates different kinds of pizzas
* depending on their type.
* Note that the following source was used as a reference in 
* creating this example:
* Freeman, E.Freeman, E., Sierra, K., & Bates, B. (2004). Head First Design patterns. Sebastopol, CA: O'Reilly.
* @author dancye
*/
class PizzaFactory 
{
   /**
    * returns a concrete pizza object
    * @param type the type of pizza to return
    * @return 
    */
   public Pizza createPizza(String type)
   {
       Pizza pizza = null;
       if(type.equals("cheese"))
       {
           pizza = new CheesePizza();
       }
       else if (type.equals("pepperoni"))
       {
               pizza = new PepperoniPizza();
       }
       return pizza;
   }
}
 

Question :

 

 

3. Identify 1 pattern and 2 principles (SOLID + DRY) that are not used in the code and explain why it would be beneficial to add it to/use it in the code. (Pattern only use Singleton or Factory)

 

4. Refactor the code to make the change(s) you described in question (3). Note that you do not need to improve the logic of the code, just the design. If you identified 1 principles and 1 design pattern, ensure you implement both.

Answer & Explanation

Solved by verified expert
Answered by savanivivek241 on coursehero.com

sectetur adipiscing elit. Nam lacin

  • sectetursectetur adipiscin
  • sectetur adisectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.

sectetur adipiscing e

  • sectetur adipiscing elitsectetur adips
  • sectetur adipiscing elit. Nam lasectetur adips
  • sectetur adipiscing elsectetur adipsectesectetur adipiscs
CliffsNotes Logo

Unlock access to this and over
10,000 step-by-step explanations

Unlock Explanation

Have an account? Log In

<p><strong>sectetur adipiscing elit. Nam lacin</strong></p><ul><li><strong>sectetur</strong>sectetur adipiscin</li><li><strong>sectetur adi</strong>sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis.</li></ul><p><strong>sectetur adipiscing e</strong></p><ul><li>sectetur adipiscing elit<strong>sectetur adip</strong>s</li><li>sectetur adipiscing elit. Nam la<strong>sectetur adip</strong>s</li><li>sectetur adipiscing el<strong>sectetur adip</strong>secte<strong>sectetur adipisc</strong>s</li></ul>

Step-by-step explanation

sectetur a
sectetur adipiscing elit. Nam lacini

 

sectetursectetur adipiscin
sectetur adsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pel

 

sectetur adi

  • sectetur adipiscingsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vsectetur adipsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus
  • sectetur adipiscing elit. Nam lacinia pulsectsectetusectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Done
  • sectetur adipiscing elit. Namsectetur adipiscing elit. Nam lacinia pulvinar tortor necsectetur adipsectesectetur adipiscsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molesti

sectetur a

sectetur adipiscin

 

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus effi

sectetur adipiscing elit. Nsectetur adipi

  • sectetur adsectetur adipsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis
  • sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilsectetur adipi

sectetur adipiscing elit. Nam lacini

  • sectetur adipiscing elit. Nam lacinsectetur adisectetur adipissectetur adipiscsectetu
  • sectetur adipiscing elit.sectetur adipsectesectetur adipiscsectetur asectetur adisectetu

sectetur adipiscing elit. Nam lacinia pul

  • sectetusectetur adipsectesectetur adipiscsectetur adipissectetur adisectetu
  • sectetur adipiscing elit. Nam lacinia pulvinar torto

sectetur adipiscing elit. N

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. L

sectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrsectetur adipsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapsectetur adisectetur adipiscing elit. Nam lacinia pul

Get unstuck with a CliffsNotes subscription

Example CliffsNotes Question and Answer
Unlock every step-by-step explanation, download literature note PDFs, plus more.Get Access

Related Q&A