Can someone give me a little java program i can attempt nothing to big but something kind of simple.
I really want to get better.
Something like this : http://forum.logicalgamers.com/progr...gram-help.html
Printable View
Can someone give me a little java program i can attempt nothing to big but something kind of simple.
I really want to get better.
Something like this : http://forum.logicalgamers.com/progr...gram-help.html
lol make me a Java calculator with advanced functions and/or make a Java calculator that has a GUI.
Make a browser with bookmarks.
As in a dialog or window as the interface for the program.
Graphical user interface - Wikipedia, the free encyclopedia
Try making a two player rock-paper-scissors game. Seems simple enough.
So this how far i came with the rock-paper-scissors game:
I was wondering how can i make it loop?Code: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);
}
}
Ask if they wanna play again and make it go back to the beginning?
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.)
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);
}
}
}