Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Program 3

BunkerHillBroad
BunkerHillBroad 


use files Pizza.java and PizzaParty.java Pizzas can be ordered in several sizes. Some pizza parlors cut all pizzas into 8 slices, while others get more slices out of the larger pizza pies. It might be useful to know what size pie offers the best deal in terms of cost per slice or cost per square inch of pizza. Here’s a Java main program to help determine these facts. public class PizzaParty { public static void main(String[] args) { Pizza appetizer = new Pizza("Pepperoni", 16, 10.50, 10); Pizza mainCourse = new Pizza("Anchovy & Pineapple", printPizzaStats(appetizer); System.out.println(); printPizzaStats(mainCourse); } public static void printPizzaStats(Pizza { p) %.2f square inches " System.out.printf("Your %s pizza has + " per slice.\n", p.getName(), p.areaPerSlice()); System.out.printf("One slice costs $%.2f, which comes” + " to $%.3f per square inch.\n", p.costPerSlice(), p.costPerSquareInch() ); } } Your task is to implement the Pizza class with instance variables and methods. If the Pizza class were properly defined, here is what your program would look like in action (note the use of printf to format the output of double values in an appropriate way). Your Pepperoni pizza has 20.11 square inches per slice. One slice costs $1.05, which comes to $0.052 per square inch. Your Anchovy & Pineapple pizza has 39.27 square inches per slice. One slice costs $1.49, which comes to $0.038 per square inch. Attachments
Tags Clarifications

Answers

Java Program 3 - Solution

mariobeka
mariobeka 



Includes the implementation of Pizza class with some explanation comments.
Also a screenshot of the output.
Attachments
Java Solution 3.zip (1 K) Download
Preview
name; private int diameter; private double totalPrice; private int slices; /** * Constructor initializing the name, diameter, total price and slices of a pizza. * * @param name The name of the pizza. * @param diameter The diameter of the pizza. * @param totalPrice The total price of the pizza.

Preview
%s pizza has %.2f square inches " + " per slice.\n", p.getName(), p.areaPerSlice()); System.out.printf("One slice costs $%.2f, which comes" +

Screen Shot 2016-11-26 at 20.13.28.png (57 K) Download Preview

Screenshots
Screenshot
Purchase Answer