Im trying to program a survey and one of the bits on my survey wont work and heres the little bit that wont work please help!!!
class jon{
public static void main(String[] args)
{
char yes = 'y', no = 'n', answer1;
int addition=0, subtraction=0;
if ('y' < 5)
{
System.out.println("Do you drink alcohol? Y/N : ");
answer1 = Keyboard.readChar( );
}
else if (answer1 == 'y')
{
addition=(addition + 1);
}
else if (answer1 == 'n')
{
subtraction=(subtraction + 1);
}
}
}
i keep getting an error like this
error : variable answer1 might not have been initialized else if (answer1) == 'y')
but java underlines answer1
please i dont know whats going on please help
heres my full program
its not finished yet because of this program
class Survey{
public static void main(String[ ] args)
{
char yes = 'y', no = 'n', answer1, answer2, answer3, answer4, answer5, answer6, answer7,answer8, answer9, answer10, answer11, answer12;
int addition=0, subtraction=0;
System.out.print("Do you like sports Y/N: ");
answer1 = Keyboard.readChar( );
if (answer1 == 'y')
{
addition=(addition + 1);
}
else if (answer1 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like ireland Y/N: ");
answer2 = Keyboard.readChar( );
if (answer2 == 'y')
{
addition=(addition + 1);
}
else if (answer2 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like movies Y/N: ");
answer3 = Keyboard.readChar( );
if (answer3 == 'y')
{
addition=(addition + 1);
}
else if (answer3 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like europe Y/N: ");
answer4 = Keyboard.readChar( );
if (answer4 == 'y')
{
addition=(addition + 1);
}
else if (answer4 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like america Y/N: ");
answer5 = Keyboard.readChar( );
if (answer5 == 'y')
{
addition=(addition + 1);
}
else if (answer5 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like Manchester United Y/N: ");
answer6 = Keyboard.readChar( );
if (answer6 == 'y')
{
addition=(addition + 1);
}
else if (answer6 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like Dublin Y/N: ");
answer7 = Keyboard.readChar( );
if (answer7 == 'y')
{
addition=(addition + 1);
}
else if (answer7 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like ITB Y/N: ");
answer8 = Keyboard.readChar( );
if (answer8 == 'y')
{
addition=(addition + 1);
}
else if (answer8 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like computers Y/N: ");
answer9 = Keyboard.readChar( );
if (answer9 == 'y')
{
addition=(addition + 1);
}
else if (answer9 =='n')
{
subtraction=(subtraction + 1);
}
System.out.print("Do you like programming Y/N: ");
answer10 = Keyboard.readChar( );
if (answer10 == 'y')
{
addition=(addition + 1);
}
else if (answer10 =='n')
{
subtraction=(subtraction + 1);
}
System.out.println("To Question 1o you like sports Y/N : You answered"+" "+ answer1);
System.out.println("To Question 2o you like ireland Y/N: You answered"+" "+ answer2);
System.out.println("To Question 3o you like movies Y/N: You answered"+" "+ answer3);
System.out.println("To Question 4o you like europe Y/N: You answered"+" "+ answer4);
System.out.println("To Question 5o you like america Y/N: You answered"+" "+ answer5);
System.out.println("To Question 6o you like Manchester United Y/N:You answered"+" "+ answer6);
System.out.println("To Question 7o you like Dublin Y/N:You answered"+" "+ answer7);
System.out.println("To Question 8o you like ITB Y/N:You answered"+" "+ answer8);
System.out.println("To Question 9o you like computers Y/N:You answered"+" "+ answer9);
System.out.println("To Question 10o you like programming Y/N:You answered"+" "+ answer10);
if ( 'y' < 5)
{
System.out.println("Thank you for answering the survey, to complete the survey could you answer these two questions ");
}
else if ('y' > 5)
{
System.out.println("Thank you for completing the survey ");
}
else if ('y' < 5)
{
System.out.println("Do you drink alcohol? Y/N : ");
answer11 = Keyboard.readChar( );
}
else if (answer11 == 'y')
{
addition=(addition + 1);
}
else if (answer11 == 'n')
{
subtraction=(subtraction + 1);
}
System.out.println("Do you eat potatoes? Y/N : ");
answer12 = Keyboard.readChar( );
if (answer12 == 'y')
{
addition=(addition + 1);
}
else if (answer12 == 'n')
{
subtraction=(subtraction + 1);
}
System.out.println("To Question 11o you drink alcohol? Y/N : You answered"+" "+ answer11);
System.out.println("To Question 12: Do you eat potatoes? Y/N : You answered"+" "+ answer12);
if ( 'y' == 2)
{
System.out.print("You have a very agreeable person ");
}
else if ('n' == 2)
{
System.out.print("You like saying no don't you!");
}
}
}