I wrote almost the entire class other than one thing that i'm confused about which is this:
public Pizza(Pizza pi) { }
the rest of the coding is done. when i test it it says that calculateArea() is required:double...arguments found: no arguments
this is my class:
and i'm using this to test it:public class Pizza { private static double diameter; private static double price; public Pizza() { diameter = 6.0; price = 2.25; } public Pizza(double d, double p) { diameter = d; price = p; } public Pizza(Pizza pi) { } public double calculateArea(double area) { area = diameter / 2; return area; } public double pricePerSquareInch(double priceSqIn, double area) { area = diameter / 2; priceSqIn = price / area; return priceSqIn; } public double getDiameter() { return diameter; } public double getPrice() { return price; } public void setDiameter(double d) { diameter = d; } public void setPrice(double p) { price = p; } }
import java.text.*; public class CheapPizza{ public static void main(String[] arg){ //declare pizza objects Pizza p1 = new Pizza(); Pizza p2 = new Pizza(9.0, 3.10); Pizza p3 = new Pizza(p2); //change some info on p3 p3.setPrice(4.00); p3.setDiameter(12.0); //formatting NumberFormat nf = NumberFormat.getInstance(); NumberFormat nf2 = NumberFormat.getInstance(); NumberFormat cf = NumberFormat.getCurrencyInstance(); nf.setMaximumFractionDigits(2); nf2.setMaximumFractionDigits(4); //display the information System.out.println("Diameter of Pizza Area of Pizza Price Price/SQ Inch"); System.out.printf("%15.2f %13.2f " + cf.format(p1.getPrice()) + " %13.4f\n", p1.getDiameter(), p1.calculateArea(), p1.pricePerSquareInch()); System.out.printf("%15.2f %13.2f " + cf.format(p2.getPrice()) + " %13.4f\n", p2.getDiameter(), p2.calculateArea(), p2.pricePerSquareInch()); System.out.printf("%15.2f %13.2f " + cf.format(p3.getPrice()) + " %13.4f\n", p3.getDiameter(), p3.calculateArea(), p3.pricePerSquareInch()); } }