BasicPizza.java
public class BasicPizza {
String type;
String crust;
String ingredients;
double cost;
public BasicPizza(String type) {
super();
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCrust() {
return crust;
}
public void setCrust(String crust) {
this.crust = crust;
}
public BasicPizza() {
super();
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
public double getCost() {
return cost;
}
public void setCost() {
this.cost = 5;
}
@Override
public String toString() {
return "BasicPizza [type=" + type + ", crust=" + crust + ", ingredients="
+ ingredients + ", cost=" + cost + "]";
}
}
________________________________________________________________________
LiFiCheese.java
public class LiFiCheese extends BasicPizza{
private String crust;
private double cost;
private String ingredients;
public LiFiCheese() {
super("Cheese");
this.cost=5;
}
public void setCrust()
{
this.crust="thin";
}
public String getCrust()
{
return crust;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
@Override
public String toString() {
System.out.println("You Ordered :");
System.out.println(getType());
setCrust();
System.out.println(getCrust());
System.out.println("Total Cost of :"+getCost());
return "";
}
}
_______________________________________________________________________
LiFiPizza.java
import java.util.Scanner;
public class LiFiPizza extends BasicPizza {
private String type;
private double cost;
private String crust;
private String ingredients;
public LiFiPizza()
{
super();
this.type = "Meat";
this.cost=5;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getCost() {
return cost;
}
public void setCost() {
this.cost = this.cost+2;
}
public String getCrust() {
return crust;
}
public void setCrust(String crust) {
if(crust.equals("Thin"))
{
this.crust="Thin";
}
else if(crust.equals("Thick"))
{
this.crust="Thick";
}
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
@Override
public String toString() {
System.out.println("You Ordered :");
System.out.println(getType());
System.out.println(getIngredients()+"<+$2.00>");
System.out.println(getCrust());
System.out.println("Total Cost of :"+getCost());
return "";
}
}
_____________________________________________________________________
LiFiUnit5Ch14.java
import java.util.Scanner;
public class LiFiUnit5Ch14 {
public static void main(String[] args) {
BasicPizza bp=null;
String typeOfPizza;
Scanner sc=new Scanner(System.in);
System.out.print("What type of pizza would you like :");
typeOfPizza=sc.next();
if(typeOfPizza.equalsIgnoreCase("Meat"))
{
bp=new LiFiPizza();
System.out.print("Thin or Thick Crust:");
String crust=sc.next();
bp.setCrust(crust);
System.out.print("What ingredient, sorry, only 1 :");
String ingredient=sc.next();
bp.setIngredients(ingredient);
bp.setCost();
bp.toString();
}
else if(typeOfPizza.equalsIgnoreCase("Cheese"))
{
bp=new LiFiCheese();
bp.toString();
}
}
}
_________________________________________________________________
Output:
What type of pizza would you like :Meat
Thin or Thick Crust:Thin
What ingredient, sorry, only 1 :Sausage
You Ordered :
Meat
Sausage<+$2.00>
Thin
Total Cost of :7.0
__________________________________________
Output:
What type of pizza would you like :Cheese
You Ordered :
Cheese
thin
Total Cost of :5.0
_______________________________________________________
Solution
BasicPizza.java
public class BasicPizza {
String type;
String crust;
String ingredients;
double cost;
public BasicPizza(String type) {
super();
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCrust() {
return crust;
}
public void setCrust(String crust) {
this.crust = crust;
}
public BasicPizza() {
super();
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
public double getCost() {
return cost;
}
public void setCost() {
this.cost = 5;
}
@Override
public String toString() {
return "BasicPizza [type=" + type + ", crust=" + crust + ", ingredients="
+ ingredients + ", cost=" + cost + "]";
}
}
________________________________________________________________________
LiFiCheese.java
public class LiFiCheese extends BasicPizza{
private String crust;
private double cost;
private String ingredients;
public LiFiCheese() {
super("Cheese");
this.cost=5;
}
public void setCrust()
{
this.crust="thin";
}
public String getCrust()
{
return crust;
}
public double getCost() {
return cost;
}
public void setCost(double cost) {
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
@Override
public String toString() {
System.out.println("You Ordered :");
System.out.println(getType());
setCrust();
System.out.println(getCrust());
System.out.println("Total Cost of :"+getCost());
return "";
}
}
_______________________________________________________________________
LiFiPizza.java
import java.util.Scanner;
public class LiFiPizza extends BasicPizza {
private String type;
private double cost;
private String crust;
private String ingredients;
public LiFiPizza()
{
super();
this.type = "Meat";
this.cost=5;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getCost() {
return cost;
}
public void setCost() {
this.cost = this.cost+2;
}
public String getCrust() {
return crust;
}
public void setCrust(String crust) {
if(crust.equals("Thin"))
{
this.crust="Thin";
}
else if(crust.equals("Thick"))
{
this.crust="Thick";
}
}
public String getIngredients() {
return ingredients;
}
public void setIngredients(String ingredients) {
this.ingredients = ingredients;
}
@Override
public String toString() {
System.out.println("You Ordered :");
System.out.println(getType());
System.out.println(getIngredients()+"<+$2.00>");
System.out.println(getCrust());
System.out.println("Total Cost of :"+getCost());
return "";
}
}
_____________________________________________________________________
LiFiUnit5Ch14.java
import java.util.Scanner;
public class LiFiUnit5Ch14 {
public static void main(String[] args) {
BasicPizza bp=null;
String typeOfPizza;
Scanner sc=new Scanner(System.in);
System.out.print("What type of pizza would you like :");
typeOfPizza=sc.next();
if(typeOfPizza.equalsIgnoreCase("Meat"))
{
bp=new LiFiPizza();
System.out.print("Thin or Thick Crust:");
String crust=sc.next();
bp.setCrust(crust);
System.out.print("What ingredient, sorry, only 1 :");
String ingredient=sc.next();
bp.setIngredients(ingredient);
bp.setCost();
bp.toString();
}
else if(typeOfPizza.equalsIgnoreCase("Cheese"))
{
bp=new LiFiCheese();
bp.toString();
}
}
}
_________________________________________________________________
Output:
What type of pizza would you like :Meat
Thin or Thick Crust:Thin
What ingredient, sorry, only 1 :Sausage
You Ordered :
Meat
Sausage<+$2.00>
Thin
Total Cost of :7.0
__________________________________________
Output:
What type of pizza would you like :Cheese
You Ordered :
Cheese
thin
Total Cost of :5.0
_______________________________________________________

BasicPizza.javapublic class BasicPizza { String type; String c.pdf

  • 1.
    BasicPizza.java public class BasicPizza{ String type; String crust; String ingredients; double cost; public BasicPizza(String type) { super(); this.type = type; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getCrust() { return crust; } public void setCrust(String crust) { this.crust = crust; } public BasicPizza() { super(); } public String getIngredients() { return ingredients; } public void setIngredients(String ingredients) { this.ingredients = ingredients; } public double getCost() { return cost; } public void setCost() {
  • 2.
    this.cost = 5; } @Override publicString toString() { return "BasicPizza [type=" + type + ", crust=" + crust + ", ingredients=" + ingredients + ", cost=" + cost + "]"; } } ________________________________________________________________________ LiFiCheese.java public class LiFiCheese extends BasicPizza{ private String crust; private double cost; private String ingredients; public LiFiCheese() { super("Cheese"); this.cost=5; } public void setCrust() { this.crust="thin"; } public String getCrust() { return crust; } public double getCost() { return cost; } public void setCost(double cost) { }
  • 3.
    public String getIngredients(){ return ingredients; } public void setIngredients(String ingredients) { this.ingredients = ingredients; } @Override public String toString() { System.out.println("You Ordered :"); System.out.println(getType()); setCrust(); System.out.println(getCrust()); System.out.println("Total Cost of :"+getCost()); return ""; } } _______________________________________________________________________ LiFiPizza.java import java.util.Scanner; public class LiFiPizza extends BasicPizza { private String type; private double cost; private String crust; private String ingredients; public LiFiPizza() { super(); this.type = "Meat"; this.cost=5; } public String getType() { return type;
  • 4.
    } public void setType(Stringtype) { this.type = type; } public double getCost() { return cost; } public void setCost() { this.cost = this.cost+2; } public String getCrust() { return crust; } public void setCrust(String crust) { if(crust.equals("Thin")) { this.crust="Thin"; } else if(crust.equals("Thick")) { this.crust="Thick"; } } public String getIngredients() { return ingredients; } public void setIngredients(String ingredients) { this.ingredients = ingredients; } @Override public String toString() { System.out.println("You Ordered :"); System.out.println(getType()); System.out.println(getIngredients()+"<+$2.00>"); System.out.println(getCrust());
  • 5.
    System.out.println("Total Cost of:"+getCost()); return ""; } } _____________________________________________________________________ LiFiUnit5Ch14.java import java.util.Scanner; public class LiFiUnit5Ch14 { public static void main(String[] args) { BasicPizza bp=null; String typeOfPizza; Scanner sc=new Scanner(System.in); System.out.print("What type of pizza would you like :"); typeOfPizza=sc.next(); if(typeOfPizza.equalsIgnoreCase("Meat")) { bp=new LiFiPizza(); System.out.print("Thin or Thick Crust:"); String crust=sc.next(); bp.setCrust(crust); System.out.print("What ingredient, sorry, only 1 :"); String ingredient=sc.next(); bp.setIngredients(ingredient); bp.setCost(); bp.toString(); } else if(typeOfPizza.equalsIgnoreCase("Cheese")) { bp=new LiFiCheese(); bp.toString(); } }
  • 6.
    } _________________________________________________________________ Output: What type ofpizza would you like :Meat Thin or Thick Crust:Thin What ingredient, sorry, only 1 :Sausage You Ordered : Meat Sausage<+$2.00> Thin Total Cost of :7.0 __________________________________________ Output: What type of pizza would you like :Cheese You Ordered : Cheese thin Total Cost of :5.0 _______________________________________________________ Solution BasicPizza.java public class BasicPizza { String type; String crust; String ingredients; double cost; public BasicPizza(String type) { super(); this.type = type; } public String getType() { return type; }
  • 7.
    public void setType(Stringtype) { this.type = type; } public String getCrust() { return crust; } public void setCrust(String crust) { this.crust = crust; } public BasicPizza() { super(); } public String getIngredients() { return ingredients; } public void setIngredients(String ingredients) { this.ingredients = ingredients; } public double getCost() { return cost; } public void setCost() { this.cost = 5; } @Override public String toString() { return "BasicPizza [type=" + type + ", crust=" + crust + ", ingredients=" + ingredients + ", cost=" + cost + "]"; } } ________________________________________________________________________ LiFiCheese.java public class LiFiCheese extends BasicPizza{ private String crust;
  • 8.
    private double cost; privateString ingredients; public LiFiCheese() { super("Cheese"); this.cost=5; } public void setCrust() { this.crust="thin"; } public String getCrust() { return crust; } public double getCost() { return cost; } public void setCost(double cost) { } public String getIngredients() { return ingredients; } public void setIngredients(String ingredients) { this.ingredients = ingredients; } @Override public String toString() { System.out.println("You Ordered :"); System.out.println(getType()); setCrust(); System.out.println(getCrust());
  • 9.
    System.out.println("Total Cost of:"+getCost()); return ""; } } _______________________________________________________________________ LiFiPizza.java import java.util.Scanner; public class LiFiPizza extends BasicPizza { private String type; private double cost; private String crust; private String ingredients; public LiFiPizza() { super(); this.type = "Meat"; this.cost=5; } public String getType() { return type; } public void setType(String type) { this.type = type; } public double getCost() { return cost; } public void setCost() { this.cost = this.cost+2; } public String getCrust() { return crust; } public void setCrust(String crust) {
  • 10.
    if(crust.equals("Thin")) { this.crust="Thin"; } else if(crust.equals("Thick")) { this.crust="Thick"; } } public StringgetIngredients() { return ingredients; } public void setIngredients(String ingredients) { this.ingredients = ingredients; } @Override public String toString() { System.out.println("You Ordered :"); System.out.println(getType()); System.out.println(getIngredients()+"<+$2.00>"); System.out.println(getCrust()); System.out.println("Total Cost of :"+getCost()); return ""; } } _____________________________________________________________________ LiFiUnit5Ch14.java import java.util.Scanner; public class LiFiUnit5Ch14 { public static void main(String[] args) { BasicPizza bp=null; String typeOfPizza; Scanner sc=new Scanner(System.in); System.out.print("What type of pizza would you like :");
  • 11.
    typeOfPizza=sc.next(); if(typeOfPizza.equalsIgnoreCase("Meat")) { bp=new LiFiPizza(); System.out.print("Thin orThick Crust:"); String crust=sc.next(); bp.setCrust(crust); System.out.print("What ingredient, sorry, only 1 :"); String ingredient=sc.next(); bp.setIngredients(ingredient); bp.setCost(); bp.toString(); } else if(typeOfPizza.equalsIgnoreCase("Cheese")) { bp=new LiFiCheese(); bp.toString(); } } } _________________________________________________________________ Output: What type of pizza would you like :Meat Thin or Thick Crust:Thin What ingredient, sorry, only 1 :Sausage You Ordered : Meat Sausage<+$2.00> Thin Total Cost of :7.0 __________________________________________ Output:
  • 12.
    What type ofpizza would you like :Cheese You Ordered : Cheese thin Total Cost of :5.0 _______________________________________________________