Help with user defined methods

Joined
Jan 23, 2008
Messages
1
Reaction score
0
/**
*
* 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top