import java.io.*;

public class Pizza implements Serializable

{

private String variety;

private int size;

public Pizza(String var, int sze)

{

setVariety(var);

setSize(sze);

}

public String getVariety()

{

return variety;

}

public void setVariety(String variety)

{

this.variety = variety;

}

public int getSize()

{

return size;

}

public void setSize(int size)

{

this.size = size;

}

}

 

 

+++++++++++++++++++++++++++++++++++++++

 

 

import java.io.*;

 

public class PizzaBoom

{

private Pizza[] menu;

private int[] quantitySold;

public PizzaBoom(int size)

{

menu = new Pizza[size];

quantitySold = new int[size];

}

public void fill()

{

menu[0] = new Pizza("mexican", 12);

menu[1] = new Pizza("mexican", 6);

menu[2] = new Pizza("vegetarian", 5);

}

public void display()

{

System.out.println("++++++++++++++++++++");

for (int i=0; i<menu.length; i++)

{

System.out.println(menu[i].getVariety() + " " + menu[i].getSize() + " " + quantitySold[i]);

}

}

public void sellPizza(String var, int sze, int nbSold)

{

int i = 0;

while (i < menu.length &&

!(menu[i].getVariety().equals(var) && menu[i].getSize() == sze)

)

{

i++;

}

if (i < menu.length)

{

quantitySold[i] += nbSold;

}

else

 

{

System.out.println("Menu item not found");

}

}

public void logSales(String fileName)

{

try

 

{

File f = new File(fileName);

FileOutputStream fo = new FileOutputStream(f);

PrintWriter pw = new PrintWriter(fo);

pw.write("Pizza type Size Quantity\r\n");

for (int i=0; i<menu.length; i++)

{

pw.write(menu[i].getVariety()+ " "+menu[i].getSize()+

" "+quantitySold[i]+"\r\n");

}

pw.close();

}

catch(IOException e)

{

System.out.println("ERROR in logSales");

}

}

public void displaySalesFromFile(String fileName)

{

String line = "";

try

 

{

File f = new File(fileName);

FileReader fr = new FileReader(f);

BufferedReader br = new BufferedReader(fr);

while(line != null)

{

line = br.readLine();

if(line != null)

{

System.out.println(line);

}

}

br.close();

}

catch(IOException e)

{

System.out.println("ERROR in displaySalesFromFile");

}

}

public void storeInObjectFile(String fileName)

{

try

 

{

File f = new File(fileName);

FileOutputStream fo = new FileOutputStream(f);

ObjectOutputStream os = new ObjectOutputStream(fo);

os.writeObject(menu);

os.close();

}

catch(IOException e)

{

System.out.println("ERROR in storeInObjectFile " + e.getMessage());

}

}

public void displayMenuBySizeFromFile(String fileName, int minSize)

{

try

 

{

File f = new File(fileName);

FileInputStream fi = new FileInputStream(f);

ObjectInputStream is = new ObjectInputStream(fi);

Pizza[] parray = (Pizza[])is.readObject();

for(int i=0; i<parray.length; i++)

{

if(parray[i].getSize() > minSize)

{

System.out.println(parray[i].getVariety() + " " + parray[i].getSize());

}

}

is.close();

}

catch(IOException e)

{

System.out.println("ERROR in displayMenuBySizeFromFile");

}

catch(Exception e)

{

System.out.println("ERROR in displayMenuBySizeFromFile");

}

}

}

 

 

 

++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

 

 

public class App

{

 

public static void main(String[] args)

{

PizzaBoom pBoom = new PizzaBoom(3);

pBoom.fill();

pBoom.display();

pBoom.sellPizza("mexican", 12, 10);

pBoom.sellPizza("mexican", 6, 20);

pBoom.sellPizza("vegetarian", 5, 30);

pBoom.display();

pBoom.logSales("pizza.dat");

pBoom.displaySalesFromFile("pizza.dat");

pBoom.storeInObjectFile("pizzaObj.dat");

pBoom.displayMenuBySizeFromFile("pizzaObj.dat", 6);

}

}