Results 1 to 3 of 3
  1. #1
    fezman1337 is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default [SOLVED] Need some help with this program please.

    Hello everyone, im somewhat new to the java scene and only have little experince in java. Im having a problem with this program where 2/3 of the parts work while the third one doesn't return the right data.

    import java.text.*;

    *Program to test the Pizza class by creating Pizza objects and displaying there information
    *@version 1.0
    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

    NumberFormat nf = NumberFormat.getInstance();
    NumberFormat nf2 = NumberFormat.getInstance();
    NumberFormat cf = NumberFormat.getCurrencyInstance();


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



    and this is what i have so far.

    public class Pizza{

    private double diameter;

    private double price;

    private double d;
    private double p;
    private double Area;
    private double pricePerSquareInch;
    private double Diameter;
    private double Price;
    private double pi;

    public Pizza() {
    Diameter = 6.0;
    Price = 2.25;
    public Pizza(double d, double p){
    d = diameter;
    p = price;
    public Pizza(Pizza pi){
    d = pi.getDiameter();
    p = pi.getPrice();
    public double calculateArea(){
    Area = Math.PI * (Diameter/2) * (Diameter/2);
    return Area;
    public double pricePerSquareInch(){
    pricePerSquareInch = Price / Area;
    return pricePerSquareInch;
    public double getDiameter(){
    return Diameter;
    public double getPrice(){
    return Price;
    public void setDiameter(double d){
    Diameter = d;
    public void setPrice(double p){
    Price = p;

    I cannot get the second line to show properly. It only returns 0's for everything. Any help will be much appreciated and thanks in advance.
    Last edited by fezman1337; 10-04-2010 at 09:30 PM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power


    Your second constructor is wrong.
    Java Code:
    	public Pizza(double d, double p) {
    		Diameter = d;
    		Price = p;
    but --> Naming Conventions

  3. #3
    fezman1337 is offline Member
    Join Date
    Oct 2010
    Rep Power

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts