My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Code Java:
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.";
}
}
it says can't find main class when I run, when I compile it is showing one error. I am so new I do not know what the error means.
Code Java:
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());
}
}
It says the same error messages, not finding the main class, won't run and one
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Quote:
compile it is showing one error
Please copy and post the full text of the compiler's error messages.
Quote:
not finding the main class
If the compiler does not create a .class file because of errors, the java program won't find one.
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
4 Attachment(s)
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
I AM USING TEXT PAD. Is that maybe the issue?? In the tutorial for the program example in the book he is using text pad, I do have Jcreator and net beans. I will tell you the error messages.
Attachment 1768Attachment 1769Attachment 1770Attachment 1771
i RAN IT IN JCREATOR AND IT WORKED. But I have been using text pad and feel cozy with it. Maybe it no good? I sent some attached screen shots. THANK YOU FOR YOUR HELP. Yes my print outs need to be fixed, spacing, etc. Like I said, I am sooo soo new. I want to keep on keeping on, I got discouraged. Please advise any help you can, maybe not use text pad? The errors were from that software.
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Can you copy the error messages and post them here.
On windows: To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Is it free? LOL. Text Pad is not and time is running out for the sample of it. Hey, I want to thank you for your kindness this morning. I DO appreciate it and was hesitant because I know people do not do their work and want help with it, as you see all my code was there, I just could not figure it out. I seen another error on line 134 that text pad was not showing.. WOW, I am learning, I won't give up, I love programming and it is a slap in the chops when I make a mistake, but I love the fact I get help from a person I do not know. I appreciate your all around kindness!!
--- Update ---
Yes, I fixed it, reran it, my issue is solved, I submitted it, and will look into Dr.Java as good advice you gave me! I thank you!!!
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.
Quote:
Originally Posted by
javaiscool
Great! I'm also a beginner (2nd semester uni course in java). Yes, Dr. Java is free and I believe open source. Much (maybe all?) software hosted on
SourceForge is open source and free (community developed by many programmers around the world). I can't believe Textpad sucks so much, AND that they charge for it. Hahaha.... What a failure of a company. You did a good job of re-phrasing your post by the way. Best wishes.
Thanks for your reply. Yes textpad missed an error and I ran it in Jcreator and it was seen by my own eyes, LOL . Will def look into DrJava. Best wishes to you as well!!