Jump to content

Help writing Math Game in Dr. Java

- - - - -

  • Please log in to reply
2 replies to this topic

#1
CarlenDowns330

CarlenDowns330

    Newbie

  • Members
  • Pip
  • 2 posts
I haven't done any coding in about 2 months. My Computer Science teacher gave us a project to create a math game using a GUI or Menu. It has to have the following options for the user: Adding integers, subtracting integers, multiplying integers, dividing integers, adding decimals, subtracting decimals, multiplying decimals, square root of perfect square, cubic root of perfect cubes, power of an integer, area of a rectangle, perimeter of a rectangle. It should also store the student's name and grade on the game. I don't have a clue on how to start this so can someone help me out?

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Console example with only "+" and "-";

char[] operations = {'+', '-'};

Scanner scanner = new Scanner(System.in);

Random random = new Random();


while(true){

  char operation = operations[random.nextInt(2)];

  int a = random.nextInt(10);

  int b = random.nextInt(10);

  int result;

  switch(operation){

    case '+' : result = a + b; break;

    case '-' :  result = a - b; break; 

  }  


  System.out.println(a + " " + operation +" " + b " = ?");

  int input = scanner.nextInt();

  scanner.nextLine(); //clear \n in buffer


  if(input == result){

    System.out.println("correct.\n");

  } else {

    System.out.println("incorrect.\n");

  }

}


You just need a lot more operations and a GUI :P

#3
CarlenDowns330

CarlenDowns330

    Newbie

  • Members
  • Pip
  • 2 posts
Thanks for the help! I will definitely use this!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users