I'm having troubles converting a String(birthyear) into an int(age). I want someone to type in their year of birth, and have the program do a simple subtraction calculation to work out their age. I'm new to programming, so I've been searching around, and most places tell me the same thing.
Integer.parseInt(birthyear);
However, having done that, when I try to do the math...
int age = year-birthyear;
I get the error in the title.
public class WordGameScanner
{
public static void main(String[] argus)
{
String name;
String home;
String birthyear;
String course;
String reason;
String feedback;
int year = 2013;
Scanner input = new Scanner(System.in);
System.out.print("What is your name: ");
name = input.nextLine();
System.out.print("Where are you from: ");
home = input.nextLine();
System.out.print("What year were you born: ");
birthyear = input.nextLine();
Integer.parseInt(birthyear);
System.out.print("What are you studying: ");
course = input.nextLine();
System.out.print("Why are you studying " + course + ": ");
reason = input.nextLine();
System.out.print("How is " + course + " coming along so far: ");
feedback = input.nextLine();
int age = year-birthyear;
System.out.println("There once was a person named " + name +
" who came all the way from " + home +
" to study for the " + course +
" degree at --------------.\n\n" + name +
" was born in " + birthyear + " and so will turn " + age +
" this year.");
System.out.println(name + " decided to study the unit ------------, because \"" +
reason + "\". So far, ----------- is turning out to be " +
feedback + ".");
}
}
I'm sorry if this is in the wrong place, this is only my second post here. I just clicked "ask a question" and followed the directions >.<
Integer#parseInt(). Don't do that.