Results 1 to 4 of 4

Thread: Java Program

  1. #1
    Senior Member
    Join Date
    Oct 2001
    Posts
    689

    Post Java Program

    This was an assignment in my CS151 Programming Fundamentals aka. Java class. Its supposed to be a cuckoo clock simulator. I know it pretty dumb, but I was wondering what the programming experts around here see that I can do to slim it down a little bit. In its current state it is over 5 pages long. By the way there is a lot of documentation with it because the teacher requires it.
    Wine maketh merry: but money answereth all things.
    --Ecclesiastes 10:19

  2. #2
    Senior Member
    Join Date
    Oct 2001
    Posts
    101

    Lightbulb Re: Java Program

    I gave it a try - what can I say, I was bored!

    I added error handling for the input. So, basically:
    - if they enter a non-integer as a start or end time it will prompt again.
    - if the enter a start time that is later than the end time it will prompt again
    - if their input is <0 or >24 then it prompts again

    Not sure if you counted seconds as ticks but if you do, change
    Code:
      s += "*tick* ";
      ticks++;
    to just
    Code:
      s += doSeconds();
    If that doesn't work gimme a shout and I can help you out some more.
    - Stronzo

    \"Vini, Vici, Vidi\"
    I came, I saw, I conquered.
    - Julius Caesar

  3. #3

    Cool Never ask a script kiddie to do a programmers job...

    If you're really interested in good advice, post a slightly more specific question at www.javajunkies.org and you should get some excellent advice.

  4. #4
    Senior Member
    Join Date
    Oct 2001
    Posts
    689

    Cool

    Yeah I know its a boring program, but the teacher doesnt want us doing anything exciting for fear we might learn something. He did this to show those in the class who have never programmed, how to do the "for" loop Thanks for the help. The method I wrote to handle bad numbers looks like this:

    num = getInt(startHour)
    public static int getInt(int hour)
    {
    while(hour > 12 || hour < 1)
    {
    JOptionPane.showErrorMessage("Please enter number between 1 and 12");
    JOptionPane.showInputDialog("Enter start hour");
    }
    return hour;

    }
    Wine maketh merry: but money answereth all things.
    --Ecclesiastes 10:19

Posting Permissions

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