Create class named PIZZA.
Data field include a string for toppings( such as pepperoni), an integer for diameter in inches (such as 12), and a double for price(such as as 23.70).
Include methods to get and set values for each of these fields.
B. Create an application name TESTPizza the instantiates one demonstrate the use of Pizza set and get methods. Save the application TestPizza.java
class PIZZA {
private String toppings;
private int diameter;
private double price;
public PIZZA() {
}
/**
* @return the toppings
*/
public String getToppings() {
return toppings;
}
/**
* @param toppings the toppings to set
*/
public void setToppings(String toppings) {
this.toppings = toppings;
}
/**
* @return the diameter
*/
public int getDiameter() {
return diameter;
}
/**
* @param diameter the diameter to set
*/
public void setDiameter(int diameter) {
this.diameter = diameter;
}
/**
* @return the price
*/
public double getPrice() {
return price;
}
/**
* @param price the price to set
*/
public void setPrice(double price) {
this.price = price;
}
}
class TestPizza {
public static void main(String[] args) {
PIZZA PIZZA = new PIZZA();
PIZZA.setToppings("pepperoni");
PIZZA.setDiameter(12);
PIZZA.setPrice(23.70);
System.out.println("Toppings: " + PIZZA.getToppings());
System.out.println("Diameter: " + PIZZA.getDiameter());
System.out.println("Price: " + PIZZA.getPrice());
}
}
Comments
Leave a comment