Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: resubmitting question from yesterday

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default resubmitting question from yesterday

    public class Pizza
    {
    private String size;
    private int cheese;
    private int pepperoni;
    private int ham;


    public Pizza()
    {

    size = "small";
    cheese = 0;
    pepperoni = 0;
    ham = 0;
    }

    public Pizza(String size)

    {
    this.size = size;
    cheese = 0;
    pepperoni = 0;
    ham = 0;
    }


    public Pizza(String size, int cheese, int pepperoni, int ham)
    {
    this.size = size;
    if(cheese < 0)
    this.cheese = 0;

    else

    this.cheese = cheese;

    if(pepperoni < 0)
    this.pepperoni = 0;

    else

    this.pepperoni = pepperoni;

    if(ham < 0)
    this.ham = 0;

    else

    this.ham = ham;
    }

    public void setSize(String newSize)

    {

    size = newSize;

    }

    public void setCheese(int newCheese)
    {

    if(newCheese < 0)
    cheese = 0;

    else

    cheese = newCheese;

    }

    public void setPepperoni(int newPepperoni)
    {
    if(newPepperoni < 0)
    pepperoni = 0;

    else

    pepperoni = newPepperoni;

    }

    public void setHam(int newHam)
    {
    if(newHam < 0)
    ham = 0;

    else

    ham = newHam;
    }

    public String getSize()
    {

    return size;

    }

    public int getCheese()

    {

    return cheese;

    }

    public int getPepperoni()

    {

    return pepperoni;

    }

    public int getHam()

    {
    return ham;

    }

    public double calcCost()
    {
    if(size.equals("small"))
    return 10 + 2 *(ham + cheese + pepperoni);

    else if(size.equals("medium"))
    return 12 + 2 *(ham + cheese + pepperoni);

    else
    return 14 + 2 *(ham + cheese + pepperoni);
    
    }
    public String getDescription()

    {

    return size + "pizza with" + ham + "ham toppings," + cheese + "cheese toppings, and" + pepperoni + "pepperoni toppings.":

    the error message on this one is illegal character 29. that is when I compile, when I run it, it says, could not load or find main class Pizza. I will attach the test program needed. it is as follows.

    public class TestPizza
    {


    public static void main(String[] args)
    {
    Pizza pizza1 = new Pizza();
    Pizza pizza2 = new Pizza("small");
    Pizza pizza3 = new Pizza("large", 3,4,5);

    pizza1.setSize("medium");
    pizza1.setPepperoni(5);
    pizza2.setHam(5);
    pizza3.setCheese(4);

    System.out.println("Pizza 1's data:");
    System.out.println("Size:" + pizza1.getSize());
    System.out.println("Pepperoni toppings:" + pizza1.getPepperoni());
    System.out.println("Cheese toppings:" + pizza1.getCheese());
    System.out.println("Ham toppings:" + pizza1.getHam());

    System.out.println();
    System.out.println(pizza1.getDescription());
    System.out.println(pizza2.getDescription());
    System.out.println(pizza3.getDescription());
    System.out.println();
    System.out.println("Pizza 1's cost: $" + pizza1.calcCost());
    System.out.println("Pizza 1's cost: $" + pizza2.calcCost());
    System.out.println("Pizza 3's cost: $" + pizza3.calcCost());

    }
    }
    This one says same error code, and when I try and run it says could not find or load main class TestPizza.


  2. #2
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: resubmitting question from yesterday

    .
    Last edited by javaiscool; February 27th, 2013 at 01:42 AM. Reason: typos

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: resubmitting question from yesterday

    I am so sorry I didn't comply with the proper way. I am new on here and yes, I guess nobody would be sure who answered me yesterday and there are so many other people here who need help too. Apologies. I thank you in advance for anything that you can do, thanks.

  4. #4
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: resubmitting question from yesterday

    X

  5. The Following User Says Thank You to javaiscool For This Useful Post:

    Norm (February 11th, 2013)

  6. #5
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: resubmitting question from yesterday

    .

  7. #6
    Junior Member
    Join Date
    Feb 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: resubmitting question from yesterday

    will do. thank you!!!!