Hi everyone. First time poster, brand new to java but I like it. I'm comfortable with the very basics but as we move forward I'm starting to struggle. My prof is not very good about explaining things so I've been teaching it to myself mostly. My most recent assignment involves creating a program that has the user input two integers and then users those integers to create 3 math problems. The end is supposed to tally all the correct answers and output the user's score and a message. I've got everything to work down to where you tally the answers. I'm not how to do that. I will leave my latest attempt to create the output at the end of the paste. If you could be any help, or at least point me to the correct method to use that would be great. Thanks! -J
import java.util.Scanner;
public class Lab3Part2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int integer1, integer2, answer1, answer2, answer3;
System.out.println("Please enter an integer.");
Scanner keyboard = new Scanner(System.in);
integer1 = keyboard.nextInt();
System.out.println("Please enter another integer.");
integer2 = keyboard.nextInt();
System.out.println("");
System.out.println("Answer the following questions:");
System.out.println("");
System.out.println("1. " + integer1 + " * " + integer2 + " = ?");
answer1 = keyboard.nextInt();
if (answer1 == integer1 * integer2)
{System.out.println("Correct.");
}
else
{System.out.println("Wrong!");
}
System.out.println("");
System.out.println("2. " + integer1 + " / " + integer2 + " = ?");
answer2 = keyboard.nextInt();
if (answer2 == integer1 / integer2)
{System.out.println("Correct.");
}
else
{System.out.println("Wrong!");
}
int a = 0;
System.out.println("");
System.out.println("3. " + integer1 + " % " + integer2 + " = ?");
answer3 = keyboard.nextInt();
if (answer3 == integer1 % integer2)
{System.out.println("Correct.");
}
else
{System.out.println("Wrong!");
}
System.out.println("");
if (answer1 == integer1 * integer2)
{int total = 1;
}
else {int total = 0;
}
if (answer2 == integer1 / integer2)
{int total1 = total + 1;
}
else
{int total1 = total;
}
if (answer3 == integer1 % integer2)
{int total2 = total1 +1;
else
{int total2 = total1;
}
}
}
{System.out.println("You got " + total2 + "correct.");
}
}
I also have to compute their score, so if they missed 1 of 3, I give them 66.67% I'm just not sure how to hold the values of the score.