4 Replies - 739 Views - Last Post: 12 December 2009 - 08:06 PM Rate Topic: -----

#1 Stressed_Programming_Student  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-November 09

Help needed finishing up this code please (It's due Dec. 14)

Posted 12 December 2009 - 06:02 PM

Ok, I have one final assignment left to do in my Advanced Java class this semester. She wants us to create an application that contains graphics and buttons. She said we could pick a business application, or a game, or a web application. So I chose a to attempt to make a game of Rock, Paper, Scissors. I have the basics down, I'm just having a few issues. I will post the code that I have come up with. The things I need help with I included as comments in the code.

import javax.swing.*;
import java.util.*;

public class LauraExamPartOne {

	public static void main(String[] args) {
	   
		String input;					   
		int playerChoice;						
		int compChoice;  
		 
							 
		System.out.println("Laura's CIS 256 Final Exam");
	   
		 //need to implement a background or image for this part
		input = JOptionPane.showInputDialog("This is my CIS 256 Final Exam. Lets play Rock, Paper, Scissors.\n" +
				"Type 1 for Rock, 2 for Paper, and 3 for Scissors, then press OK.\n" + "If you do not wish to play, please press Cancel now.");
		playerChoice = Integer.parseInt(input);
		  
		  
		  
	   
	   
		Random someNum = new Random ();
	   
		autoChoice = someNum.nextInt(3);
	   
	   
	   							 
		  if (playerChoice == 1 && autoChoice == 0)
				JOptionPane.showMessageDialog(null, "It's a Tie! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
					
							 
	 
		else if (playerChoice == 1 && autoChoice == 1)
				JOptionPane.showMessageDialog(null, "Paper covers Rock. You lose! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
	   
		else if (playerChoice == 1 && autoChoice == 2)
				JOptionPane.showMessageDialog(null, "Rock breaks Scissors. You win! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
		
		else if (playerChoice == 2 && autoChoice == 0)
				JOptionPane.showMessageDialog(null, "Paper covers Rock. You win! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
	   
		else if (playerChoice == 2 && autoChoice == 1)
				JOptionPane.showMessageDialog(null, "It's a Tie! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
	   
		else if (playerChoice == 2 && autoChoice == 2)
				JOptionPane.showMessageDialog(null, "Scissors cut Paper. You lose! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
	   
		else if (playerChoice == 3 && autoChoice == 0)
				JOptionPane.showMessageDialog(null, "Rock breaks Scissors. You lose! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
	   
		else if (playerChoice == 3 && autoChoice == 1)
				JOptionPane.showMessageDialog(null, "Scissors cut Paper. You win! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
	   
		else if (playerChoice == 3 && autoChoice == 2)
				JOptionPane.showMessageDialog(null, "It's a Tie! Would you like to play again?");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
					 
					 else if (playerChoice > 3 || autoChoice > 3)
				JOptionPane.showMessageDialog(null, "HEY! That's not a valid choice, please try again.");
					  //needs a "Play Again?" button that starts the game over if pressed
					  //needs an "End Game." button that starts the game over if pressed
					 
	   
	   
	}
   

}


This post has been edited by Stressed_Programming_Student: 12 December 2009 - 07:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Help needed finishing up this code please (It's due Dec. 14)

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help needed finishing up this code please (It's due Dec. 14)

Posted 12 December 2009 - 07:05 PM

You are far from having an Applet or a GUI aapplication
JOptionPane are short cuts for console applications to look like GUI
"Advanced Java semester"... that is scary :)

Applets or GUI applications do not use JOptionPane but JButtons and JTextField to input data
Was This Post Helpful? 0
  • +
  • -

#3 fsloke  Icon User is offline

  • D.I.C Regular

Reputation: 25
  • View blog
  • Posts: 412
  • Joined: 19-December 07

Re: Help needed finishing up this code please (It's due Dec. 14)

Posted 12 December 2009 - 07:22 PM

Work Hard ya!!!
Was This Post Helpful? 0
  • +
  • -

#4 Stressed_Programming_Student  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 15-November 09

Re: Help needed finishing up this code please (It's due Dec. 14)

Posted 12 December 2009 - 07:50 PM

I apologize, I had applet on the brain (studying for another exam). I meant to type application.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Help needed finishing up this code please (It's due Dec. 14)

Posted 12 December 2009 - 08:06 PM

View PostStressed_Programming_Student, on 12 Dec, 2009 - 06:50 PM, said:

I apologize, I had applet on the brain (studying for another exam). I meant to type application.

so you need a class that exends JFrame which has a main() method that create that class object
and you still don't need JOptionPane something like

import javax.swing.*;
public class PrimeGui extends JFrame  {

	PrimeGui() {
		super("Prime Numbers calculator");
		setSize(500, 300);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
	}

	// to start the whole thing
	public static void main(String[] args) {		
		 SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					new PrimeGui().setVisible(true);
				}
			});
	}
	}
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1