Pizza!

This program uses Java classes to show some basic data regarding, in this case, pizza sizes, toppings and prices. A bit simplistic, but it demonstrates some classic Java commands. This was created and executed using Eclipse.

public class Week3
{
 public static void main(String[] args)
 {
    Pizza2 p1 = new Pizza2();
    Pizza2 p2 = new Pizza2();
    int Size;
    String Toppings;
    double Price;

    p1.setToppings(“Cheese”);
    p1.setSize(16);
    p1.setPrice(13.99);

    Toppings = p1.getToppings();
    Size = p1.getSize();
    Price = p1.getPrice();

    System.out.println(“Pizza has ” + Toppings + ” and the size is ” + Size  + ” inches ” + ” and the price is ” + Price);
 
    p2.setToppings(“Pepperoni”);
    p2.setSize(12);
    p2.setPrice(11.99);

    Toppings = p2.getToppings();
    Size = p2.getSize();
    Price = p2.getPrice();

    System.out.println(“Pizza has ” + Toppings + ” and the size is ” + Size  + ” inches ” + ” and the price is ” + Price);

 }
}
public class Pizza2
{
  int Size;
  String Toppings;
  double Price;

  public void setToppings(String t)
  {
     Toppings = t;
  }

  public void setSize(int pSize)
  {  
     Size = pSize;
  }

  public void setPrice(double pPrice)
  {
     Price = pPrice;
  }

  public String getToppings()
  {
     return(Toppings);
  }

  public int getSize()
  {
     return(Size);
  }
  
  public double getPrice()
  {
   return(Price);
  }
  
}

Screenshot:

About Lauren Mullaney

A student of software engineering looking for a place to display her work!

Posted on February 1, 2011, in Java. Bookmark the permalink. Leave a comment.

Leave a comment