if there are are any java programmers on the forum, feel free to share your programs here, although i may ask you lots of question, because i am only on week 2 of my three week java course, but here is one of my programs anyways.
//author: Gabriel B.
//quizzes the user on mental math aptitude.
import javax.swing.*;
import java.util.*;
public class calculate_this_gui
//author: Gabriel B.
//quizzes the user on mental math aptitude.
import javax.swing.*;
import java.util.*;
public class calculate_this_gui
{
static int computeAnswer(int x, int y, char operator)
{
switch(operator)
{
case '+': return x + y;
case '-': return x - y;
case '*': return x * y;
case '/': return x / y;
case '%': return x % y;
default: return -999999;
}
}
public static void main(String[] args)
{
JFrame frame = new JFrame("calculate this");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
Random rand = new Random();
int rand_int_x = 24;
int rand_int_y = 24;
int correct = 0;
int times_to_play = 0;
int answer = 0;
int right = 0;
int wrong = 0;
int count = 0;
int x;
int y;
int which_operator = 0;
char operators[] = {'*', '/', '+', '-', '%'};
String playTimes;
String yes;
String no;
String finalCount;
String question;
playTimes = JOptionPane.showInputDialog("How many times do you want to play?");
times_to_play = Integer.parseInt(playTimes);
for(; count<times_to_play; count++)
{
x = rand.nextInt(rand_int_x)+1;
y = rand.nextInt(rand_int_y)+1;
which_operator = rand.nextInt(5);
question = JOptionPane.showInputDialog("what is "+x+operators[which_operator]+y+"?");
correct = computeAnswer(x,y,(operators[which_operator]));
answer = Integer.parseInt(question);
if (answer == correct)
{
yes = "you're right!";
JOptionPane.showMessageDialog(null, yes);
right++;
rand_int_x += 2;
rand_int_y += 2;
}
else
{
no = "you're wrong.";
JOptionPane.showMessageDialog(null, no);
wrong++;
rand_int_x--;
rand_int_y--;
}
}
finalCount = "you got it right "+right+" times, "+" and got it wrong "+wrong+" times.";
JOptionPane.showMessageDialog(null, finalCount);
}
}
think like a computer, everything s an integer.