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