Answer to Question #299652 in Java | JSP | JSF for Mr.Answers

Question #299652

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 23.70).

Include methods to get and set values for each of these fields. 


B. Create an application name TESTPizza the intantiates one demonstrate the use of Pizza set and get methods.

Save the application TestPizza.java




1
Expert's answer
2022-02-18T14:11:01-0500


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());
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS