Help with user defined methods

Discussion in 'Java' started by ielhox, Jan 23, 2008.

  1. ielhox

    ielhox

    Joined:
    Jan 23, 2008
    Messages:
    1
    /**
    *
    * Name: Stephen Coley /*
    * Date: January 23 2008
    * Program Name: FinalProject
    *
    */

    import java.io.*;
    public class FinalProject
    {

    public static void main(String[] args) throws IOException
    {
    System.out.println("This program was created by Stephen Coley.\n");
    BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

    //Declare Variables
    String nameStr;
    String ageStr;
    int age;
    String yearStr;
    String quitStr;
    int quit;
    boolean done = false;

    while(!done)
    {

    try
    {
    System.out.print("What is your name? ");
    nameStr = dataIn.readLine();
    System.out.println("Hello, " + nameStr + ". My name is Stephen.");
    System.out.print("How old are you? ");
    ageStr = dataIn.readLine();
    age = Integer.parseInt(ageStr);

    figureAge(age);

    System.out.print("Enter 1 to quit, anything else to start again. ");
    quitStr = dataIn.readLine();
    quit = Integer.parseInt(quitStr);
    switch (quit)
    {
    case 0:
    System.out.println("Okay, here we go again!");
    break;
    case 1:
    System.out.println("Nice meeting you, " + nameStr + ". Goodbye!");
    done = true;
    break;
    default:
    throw new NumberFormatException();
    }// Line comment to end decision block
    }// Line comment to end try block
    catch (NumberFormatException e)
    {
    System.out.println("Okay! Here we go again.");
    } // Line comment to end catch block
    } // End While Loop
    }//Line comment to end Main method
    public static int figureAge(age)
    {
    if (age > 18) {
    age = age - 18;
    if (age == 1) {
    yearStr = System.out.println("You are " + age + " year older than me.");
    }else {
    yearStr = System.out.println("You are " + age + " years older than me.");
    }
    }else if (age < 18) {
    age = 18 - age;
    if (age == 1) {
    yearStr = System.out.println("You are " + age + " year younger than me.");
    }else {
    yearStr = System.out.println("You are " + age + " years younger than me.");
    }
    }else {
    yearStr = System.out.println("You are 18? So am I!");
    }
    return yearStr;
    }
    }// Line comment to end class.


    I'm not exactly sure what's wrong. It won't compile though... please help.
     
    ielhox, Jan 23, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hallvard B Furuseth

    Dispatching operations to user-defined methods

    Hallvard B Furuseth, May 2, 2006, in forum: Python
    Replies:
    3
    Views:
    312
    Hallvard B Furuseth
    May 8, 2006
  2. Oodini
    Replies:
    1
    Views:
    1,796
    Keith Thompson
    Sep 27, 2005
  3. jmike@alum.mit.edu
    Replies:
    1
    Views:
    517
    Sion Arrowsmith
    Jul 10, 2008
  4. M. Ayhan
    Replies:
    1
    Views:
    123
    Trans
    Mar 8, 2007
  5. Kenneth McDonald
    Replies:
    5
    Views:
    345
    Kenneth McDonald
    Sep 26, 2008
Loading...

Share This Page