Unit 5 Chapter 14 Assignment Comments are REQUIRED Direction

Unit 5 Chapter 14 Assignment
Comments are REQUIRED

Directions
The files must be called <LiFiUnit5Ch14.java> (driver program)
     - LiFiPizza.java
     - LiFiCheese.java (which extends LiFiPizza)

The files must be called as specified above, (LiFi = Your Last Initial Your First Initial)

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.

Style Components
Include properly formatted prologue, comments, indenting, and other style elements

Topics to cover in Code (please indicate in comments)
Topics with * are covered in this assignment. Ensure you use every item listed below in your completed assignment.

*Object class
*equals method
toString method
*Polymorphism
Abstract
Interfaces
Protected access modifier

Basic Requirements
Write a super basic Pizza ordering system using Polymorphism.
The setCrust method varies based on which type of Pizza is instantiated.

LiFiUnit5Ch14
Get input for Cheese or Meat pizza.
     - Declare a single pizza to be used for both Cheese and Meat
     - If a Meat pizza is selected
    - instantiate your pizza as a LiFiPizza pizza with zero arguments
      - setType to Meat via the constructor
     - If a Cheese pizza is selected,
    - Instantiate your pizza as a LiFiCheese pizza with zero arguments.
     - Output of your order varies based on Cheese or Meat (See Example)

LiFiPizza.java
     - Default constructor should set pizzaType to Meat and cost to $5
     - setCrust()
          - Call setCrust and allow selection of Thin or Thick crust
     - setIngredients()
      - and allow for only 1 ingredient
     - setCost()
      - add $2 to the initial cost which is $5
     - Include accessor methods as needed.
     - Ensure all instance variables are private

LiFiCheese.java
     - Set the type to cheese via the constructor body.
     - setCrust() – (notice this is different from LiFiPizza setCurst method)
     - Automatically set it to “Thin” crust, no option to change, sorry.

Sample
Your output will vary based on Input.

Solution

Answer:

//LiFiPizza.java

import java.io.*;

import java.util.*;

import java.lang.*;

//LiFiPizza class

class LiFiPizza

{

     //pizza-type

     protected String pizzaType;

     //pizza-crust

     protected String crust;

     //pizza ingredients

     String ingredients;

     //pizza-cost

     protected float pizzaCost;

     //default-constructor

     LiFiPizza()

     {

          //set pizza type, cost, crust

          pizzaType=\"Meat\";

          pizzaCost=5;

          crust=\"Thin\";

          ingredients=\"\";

     }

     //set the pizza crust

     public void setCrust(String pCrust)

     {

          crust=pCrust;

     }

     //set ingredients

     public void setIngredients(String ing)

     {

          ingredients=ing;

     }

     //set pizza-type

     public void setPizzaType(String type)

     {

          pizzaType=type;

     }

     //set pizza cost

     public void setCost()

     {

          pizzaCost +=2;

     }

     //Return the string representing Pizza

     public String toString()

     {

return \"Your ordered:\ \"+getPizzaType()+\" Pizza\ \"+ingredients+\" (+$2.00)\ \"+crust+\" crust\ Total cost of $\"+pizzaCost;

     }

     //get pizza crust

     public String getCrust()

     {

          return crust;

     }

     //getpizza ingredients

     public String getIngredients()

     {

          return ingredients;

     }

     //Get pizzcost.

     public float getPizzaCost()

     {

          return pizzaCost;

     }

     //GET PIZZA-TYPE

     public String getPizzaType()

     {  

         return pizzaType;

     }

}

//LiFiCheese.java

class LiFiCheese extends LiFiPizza

{

     //default-sonstructor

     public LiFiCheese()

     {

          //super-class constructor

          super();

          //set piza-type

          super.setPizzaType(\"Cheese\");

     }

     //set pizaa crust to thin

     public void setCrust()

     {

          super.setCrust(\"Thin\");

     }

     //method to represent the cheese-pizza

     public String toString()

     {

return \"Your Ordered:\ \"+super.getPizzaType()+\" Pizza\ \"+super.getCrust()+\" crust\ Total cost of $\"+super.getPizzaCost();

     }

}

//LiFiUnit5Ch14.java

public class LiFiUnit5Ch14

{

     //main method

     public static void main(String[] args)

     {

          //Pizza object

          LiFiPizza pp;

          //variables

          String pizTyp;

          String pCrust;

          String ing;

          //Scanner object sss

          Scanner sss=new Scanner(System.in);

          //Get pizza type

System.out.print(\"What type of pizza would you like <Cheese or Meat>:\");

          pizTyp=sss.nextLine();

          //If cheese-pizza is selected

          if(pizTyp.equals(\"Cheese\"))

          {

              //instantiate cheese-pizza

              pp=new LiFiCheese();

              //print cheese-pizza

              System.out.println(\"\ \"+pp.toString());

          }

          //if meat-pizza is slected

          if(pizTyp.equals(\"Meat\"))   

          {

              //get crust-type

              System.out.print(\"Thick or Thin crust:\");

              pCrust=sss.nextLine();

              //get ingredients

System.out.print(\"What ingredients, sorry, only 1:\");

              ing=sss.nextLine();

              //instantiate meat-pizza

              pp=new LiFiPizza();

              //set crust,cost, ingredients

              pp.setCrust(pCrust);

              pp.setIngredients(ing);

              pp.setCost();

              //print meat-pizza

              System.out.println(\"\ \"+pp.toString());

          }

     }

}

Sample output:

Run1:

sh-4.3$ javac LiFiUnit5Ch14.java                                                                                                       

sh-4.3$ java -Xmx128M -Xms16M LiFiUnit5Ch14                                                                                          

What type of pizza would you like <Cheese or Meat>:Cheese                                                                          

                                                                                                                                   

Your Ordered:                                                                                                                      

Cheese Pizza                                                                                                                       

Thin crust                                                                                                                         

Total cost of $5.0  

Run2:                                                                                                              

sh-4.3$ java -Xmx128M -Xms16M LiFiUnit5Ch14                                                                                           

What type of pizza would you like <Cheese or Meat>:Meat                                                                             

Thick or Thin crust:Thick                                                                                                          

What ingredients, sorry, only 1:Sausage                                                                                             

                                                                                                                                   

Your ordered:                                                                                                                      

Meat Pizza                                                                                                                          

Sausage (+$2.00)                                                                                                                   

Thick crust                                                                                                                         

Total cost of $7.0   

Unit 5 Chapter 14 Assignment Comments are REQUIRED Directions The files must be called <LiFiUnit5Ch14.java> (driver program) - LiFiPizza.java - LiFiCheese
Unit 5 Chapter 14 Assignment Comments are REQUIRED Directions The files must be called <LiFiUnit5Ch14.java> (driver program) - LiFiPizza.java - LiFiCheese
Unit 5 Chapter 14 Assignment Comments are REQUIRED Directions The files must be called <LiFiUnit5Ch14.java> (driver program) - LiFiPizza.java - LiFiCheese
Unit 5 Chapter 14 Assignment Comments are REQUIRED Directions The files must be called <LiFiUnit5Ch14.java> (driver program) - LiFiPizza.java - LiFiCheese
Unit 5 Chapter 14 Assignment Comments are REQUIRED Directions The files must be called <LiFiUnit5Ch14.java> (driver program) - LiFiPizza.java - LiFiCheese
Unit 5 Chapter 14 Assignment Comments are REQUIRED Directions The files must be called <LiFiUnit5Ch14.java> (driver program) - LiFiPizza.java - LiFiCheese

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site