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 9 of 9

Thread: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.

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

    Default My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.

    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.
    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


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,346
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.

    compile it is showing one error
    Please copy and post the full text of the compiler's error messages.
    not finding the main class
    If the compiler does not create a .class file because of errors, the java program won't find one.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.

    .

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

    Default 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.
    Screenshot (15).jpgScreenshot (16).jpgScreenshot (17).jpgScreenshot (18).jpg

    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.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,346
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.

    .

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

    Default 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!!!

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

    Default Re: My program won't compile or run. Java homework assignment from the book absoulte Java, chapter 4, prob 11.

    .

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

    Default 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 View Post
    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!!

Similar Threads

  1. Showrt program will compile but nothing happens when I run it.
    By learningjavanow in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 25th, 2012, 06:36 PM
  2. My program will compile but wont run
    By joshp1993 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 23rd, 2012, 08:45 AM
  3. Program won't run help!
    By iridebmxnj in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 26th, 2012, 10:00 PM
  4. program won't compile, can't get data from google analytics
    By nervous in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 21st, 2012, 12:57 AM
  5. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 07:32 AM