A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Simple java program?

1.2k views · started by Taz ·
#2
lol make me a Java calculator with advanced functions and/or make a Java calculator that has a GUI.
#3
Make a browser with bookmarks.
#4
lol make me a Java calculator with advanced functions and/or make a Java calculator that has a GUI.


Last night i made a simple calculator that does addition subtraction multiplication and division took me a while lol.
What else should i add on to it? Also what is GUI?
#7
So this how far i came with the rock-paper-scissors game:
import javax.swing.JOptionPane;

/**
* @(#)RockPaperScissors.java
*
* RockPaperSissors application
*
* @author
* @version 1.00 2013/3/8
*/

public class RockPaperScissors {

public static void main(String[] args) {

int rps;
int rps2;
String input;


input = JOptionPane.showInputDialog("Player one: \n 1 - Rock \n 2 - Paper \n 3 - Scissors");
rps = Integer.parseInt(input);

input = JOptionPane.showInputDialog("Player one: \n 1 - Rock \n 2 - Paper \n 3 - Scissors");
rps2 = Integer.parseInt(input);

if(rps == 1 && rps2 == 3)
JOptionPane.showMessageDialog(null, "Player 1 wins!");

else if(rps == 1 && rps2 == 2)
JOptionPane.showMessageDialog(null, "Player 2 wins!");

else if(rps == 1 && rps2 == 1)
JOptionPane.showMessageDialog(null, "It was a tie!");

else if(rps == 2 && rps2 == 1)
JOptionPane.showMessageDialog(null, "Player 1 wins!");

else if(rps == 2 && rps2 == 2)
JOptionPane.showMessageDialog(null, "It was a tie!");

else if(rps == 2 && rps2 == 3)
JOptionPane.showMessageDialog(null, "Player 2 wins!");

else if(rps == 3 && rps2 == 1)
JOptionPane.showMessageDialog(null, "Player 2 wins!");

else if(rps == 3 && rps2 == 2)
JOptionPane.showMessageDialog(null, "Player 1 wins!");

else if(rps == 3 && rps2 == 3)
JOptionPane.showMessageDialog(null, "It was a tie!");

else
JOptionPane.showMessageDialog(null, "You did not enter 1, 2 or 3!");








System.exit(0);

}
}


I was wondering how can i make it loop?
Ask if they wanna play again and make it go back to the beginning?
#8
Just wrap up the code you used to make the game in a while loop.

while (true)
{
// statement(s)
}


Then put a breaking clause after the game is over instead of the exit procedure. Something that asks for input. (i.e. "Do you want to play again?" If answer == 'y' then continue loop else exit program.)
#9
Just wrap up the code you used to make the game in a while loop.

while (true)
{
// statement(s)
}


Then put a breaking clause after the game is over instead of the exit procedure. Something that asks for input. (i.e. "Do you want to play again?" If answer == 'y' then continue loop else exit program.)


Can you make it a bit more simpler?
Show me.
#10
Something like this:

import javax.swing.JOptionPane;

/**
* @(#)RockPaperScissors.java
*
* RockPaperSissors application
*
* @author
* @version 1.00 2013/3/8
*/

public class RockPaperScissors {

public static void main(String[] args) {

int rps;
int rps2;
String input;

while (true)
{
input = JOptionPane.showInputDialog("Player one: \n 1 - Rock \n 2 - Paper \n 3 - Scissors");
rps = Integer.parseInt(input);

input = JOptionPane.showInputDialog("Player one: \n 1 - Rock \n 2 - Paper \n 3 - Scissors");
rps2 = Integer.parseInt(input);

if(rps == 1 && rps2 == 3)
JOptionPane.showMessageDialog(null, "Player 1 wins!");

else if(rps == 1 && rps2 == 2)
JOptionPane.showMessageDialog(null, "Player 2 wins!");

else if(rps == 1 && rps2 == 1)
JOptionPane.showMessageDialog(null, "It was a tie!");

else if(rps == 2 && rps2 == 1)
JOptionPane.showMessageDialog(null, "Player 1 wins!");

else if(rps == 2 && rps2 == 2)
JOptionPane.showMessageDialog(null, "It was a tie!");

else if(rps == 2 && rps2 == 3)
JOptionPane.showMessageDialog(null, "Player 2 wins!");

else if(rps == 3 && rps2 == 1)
JOptionPane.showMessageDialog(null, "Player 2 wins!");

else if(rps == 3 && rps2 == 2)
JOptionPane.showMessageDialog(null, "Player 1 wins!");

else if(rps == 3 && rps2 == 3)
JOptionPane.showMessageDialog(null, "It was a tie!");

else
JOptionPane.showMessageDialog(null, "You did not enter 1, 2 or 3!");

input = JOptionPane.showInputDialog("Do you wish to play again? [y/n]");

if (input == 'y')
// Continue Loop
else if (input == 'n')
System.exit(0);

}


}
}