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
Results 1 to 10 of 10
Thread: Simple java program?
- 08 Mar. 2013 05:32am #1
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 0.25
- Awards
Simple java program?
Last edited by Taz; 08 Mar. 2013 at 05:37am.
- 08 Mar. 2013 06:54am #2
lol make me a Java calculator with advanced functions and/or make a Java calculator that has a GUI.
- 08 Mar. 2013 01:08pm #3
Make a browser with bookmarks.
Ya Bish
__________Contributions-
[How to make a FMP] • [FLP Guide] • [Gaia Gold FLP] • [Exchanging Guide]
[My Store] • [My Forum]
- 08 Mar. 2013 02:13pm #4
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 1.09
- Awards
- 08 Mar. 2013 04:49pm #5
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.
- 08 Mar. 2013 07:30pm #6
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 0.59
- Awards
- 08 Mar. 2013 08:43pm #7
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 7.85
- Awards
So this how far i came with the rock-paper-scissors game:
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?
- 08 Mar. 2013 09:11pm #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.)
- 09 Mar. 2013 05:41am #9
- Age
- 97
- Join Date
- Nov. 2009
- Location
- In the computer
- Posts
- 11,186
- Reputation
- 1029
- LCash
- 0.47
- Awards
- 09 Mar. 2013 05:51am #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);
}
}
}