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: Program won't run help!

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    3
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Program won't run help!

    /**
    * @author iridebmxnj
    *
    */
    public class PiggyBank {

    /**
    * @param args
    */
    public static void main(String[] args) {}
    // TODO Auto-generated method stub

    private int numPennies;
    private int numNickels;
    private int numDimes;
    private int numQuarters;



    /**
    * Constructor for objects of class PiggyBank
    */
    public PiggyBank()
    {
    numPennies =0;
    numNickels = 0;
    numDimes = 0;
    numQuarters = 0;
    }

    public PiggyBank (int p, int n, int d, int q)
    {
    numPennies = p;
    numNickels = n;
    numDimes = d;
    numQuarters = q;
    }

    public void insertPenny()
    {
    }

    public void insertNickel()
    {
    }

    public void insertDime()
    {
    }

    public void insertQuarter()
    {
    }

    public void insertPennies(int p)
    {
    numPennies = numPennies + p;
    }

    public void insertNickels(int n)
    {
    numNickels = numNickels + n;
    }

    public void insertDimes(int d)
    {
    numDimes = numDimes + d;
    }

    public void insertQuarters(int q)
    {
    numQuarters = numQuarters + q;
    }

    public int getTotalAmount ()
    {
    return (numPennies + 5*numNickels + 10*numDimes + 25*numQuarters);
    }

    public void printContents()
    {
    System.out.println("The number of pennies: " + numPennies);
    System.out.print("The total value of pennies:" + 1*numPennies);
    System.out.println("The number of nickels: " + numNickels);
    System.out.print("The total value of nickels:" + 5*numNickels);
    System.out.println("The number of dimes: " + numDimes);
    System.out.print("The total value of dimes:" + 10*numDimes);
    System.out.println("The number of quarters: " + numQuarters);
    System.out.print("The total value of nickels:" + 25*numQuarters);
    }


    }


  2. #2
    Junior Member awinston's Avatar
    Join Date
    Jul 2012
    Location
    United States
    Posts
    10
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Program won't run help!

    Quote Originally Posted by iridebmxnj View Post
    public static void main(String[] args) {}
    		// TODO Auto-generated method stub
    Your main method is empty. Are you receiving error messages when you try to run this program, or is nothing happening? If it is the latter, then you simply have to add some code to your main method if you expect this program to do something.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    3
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program won't run help!

    nothing happens when I run the program no error just blanks

  4. #4
    Junior Member awinston's Avatar
    Join Date
    Jul 2012
    Location
    United States
    Posts
    10
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Program won't run help!

    And this is because you don't have anything in your main method. If you want code to execute, then you must add it to your main method.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  5. #5
    Junior Member
    Join Date
    Jul 2012
    Posts
    3
    My Mood
    Angry
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Program won't run help!

    Sorry I'm really new at this how can I add it to my main method?

  6. #6
    Junior Member awinston's Avatar
    Join Date
    Jul 2012
    Location
    United States
    Posts
    10
    My Mood
    Fine
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Program won't run help!

    That's okay!

    I'm assuming that you want to create a piggy-bank and print its contents, correct?

    In the method named "main", which is at the top of your code:
    Quote Originally Posted by iridebmxnj View Post
    /**
    public static void main(String[] args) {}
    		// TODO Auto-generated method stub
    ...you want to create a PiggyBank object. If you don't know how to create an object, learn here: Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Next, you want to call the object's printContents() method. If you don't know how to call an object's method, learn here: Using Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    In short, the main method is where you specify what you want to happen. In this case, you want to create a piggy-bank and print out the contents of it.

    Also, surround your code with these tags (minus the spaces between the brackets and the word code): [ code ] [ /code ]
    The tags will make your code easier to read.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Replies: 1
    Last Post: July 8th, 2012, 11:23 AM
  2. Program to launch and mirror another program
    By hayate in forum Java Theory & Questions
    Replies: 13
    Last Post: March 9th, 2012, 12:47 AM
  3. Help with class program!!! STUCK! Program not doing what I Want!!!
    By sketch_flygirl in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 4th, 2011, 08:29 AM

Tags for this Thread