Thursday, May 11, 2006

Ladies and Gentlement, I (edit: word removed incase I look back in a year and cringe).

Here's my second program ever.

After many tears this thing finally works. It's a tutor for times tables up to the 10 times table (bigger numbers can be broken down).


===========
import java.util.Random;
import java.util.Scanner;

class TimesTableTutor{
public static void main(String args[]){
Scanner myScanner = new Scanner(System.in);
Random myRandom = new Random();

int firstRandom, secondRandom, answer;
boolean anotherQuestion=true;
char c;

while(anotherQuestion==true){
firstRandom=myRandom.nextInt(10)+1;
secondRandom=myRandom.nextInt(10)+1;

System.out.print("What is ");
System.out.print(firstRandom);
System.out.print(" x ");
System.out.print(secondRandom);
System.out.println("?");

answer=myScanner.nextInt();

while(answer!=firstRandom*secondRandom){
System.out.println("That's not quite right");
System.out.println("Have another go");
answer=myScanner.nextInt();
}
System.out.println("Well Done");
System.out.println("Would you like another question?");

c=myScanner.findInLine(".").charAt(0);

if(c=='y'||c=='Y'){
anotherQuestion=true;
}else{
anotherQuestion=false;
}
}
}
}
===========

0 Comments:

Post a Comment

<< Home

0