am writing a program that plays rock paper scissor. The user will enter choice manually (rock is1, paper is 2, and scissors is 3) and the computer will chose one at random without letting the user know. The game will run as many times as the player wants. I can use the following: wihile loop, do while loop, if and if else, random.math, int, double, println etc. ( i cant use char, boolean, string and printf). Since I dont have java at home and I have to submit this to my teacher, Plz help me below: ( I want a 100! Plz Help:)). {also my first time writing a program}. Plz give a lot of improvements, I was home schooled and just started a real school, I really want to impress my teacher. THNX:) I know i have a lot of errors:(


Also, output the scores, I have no idea how to do that and this all is due tomoorrow!!

import java.util.scanner;
Public Class Game;
{
Public Class void main (String[]args)
{

int 1 = rock;
int 2 = paper;
int 3 = scissors;

Scanner scan = new scanner (system.in);
System.out.println("Choose 1 for rock, 2 for paper; 3 for scissors");
int choice = scan.nextInt();

int computer = Math.random();
computer = 3 * Math.random;

do
{
while;
if (computer = 1 && player = 2 || computer = 2 && player = 3 || computer = 3 && player = 1)
System.out.println("You win!!");
if ( player = 1 && computer = 2 || [player = 2 && computer = 3 || player = 3 && computer = 1)
System.out.println("You Lose!!");
esle if (computer = player)
System.out.println ("Tryagain!");

}
}

First point: you don't have Java at home? Then it makes no sense trying to learn programming. You got to compile, watch the errors flow, recompile, and improve. That's where you learn.

My tips: download Java and Eclipse (the program you write java in), and 90% of the errors currently in your program will be gone. Eclipse helps you correct your mistakes by giving you autocomplete. Works great.

Line 15: Math.random returns a value >=0, <1 So when you convert it to an int the int will always be zero.
Line 21 etc, the test for two values being equal is ==, not = (that's assignment).
Yes, you should definitely download the JDK at home. However, the general consensus here is that big IDEs like NetBeans or Eclipse are not suitable for beginners, and get in the way of learning the fundamentals properly. However, everyone has their own opinion...

Line 15: Math.random returns a value >=0, <1 So when you convert it to an int the int will always be zero.
Line 21 etc, the test for two values being equal is ==, not = (that's assignment).
Yes, you should definitely download the JDK at home. However, the general consensus here is that big IDEs like NetBeans or Eclipse are not suitable for beginners, and get in the way of learning the fundamentals properly. However, everyone has their own opinion...

I wouldn't say Eclipse is not good for a beginner: There is a lot of autocompletion, and when you hover over a method, Eclipse will tell you exactly what the method does. Very handy.

The main point here is not which IDE you use, but that you do use one. The errors like = and == can be easily avoided. Also, you have to debug a little before posting a question.

Off topic: @hiddepolen discussion on use of professional IDEs like IntelliJ, Eclipse or NetBeans for early stages of learning process would be too long and most likely full of flame war.
Simple example - you advocating use of Eclipse from early stages (that is what I seen from number of your posts), but I would say do not use it at early stage because it has too much functionality you do not need such as autocomplition and autocorrections. Seen too many people failed because they been dependent on IDE and wouldn't understand why compiler was complaining. In my experience IDEs like JCreator or Notepad++ are better for start because beside colour highlights they do only push to you what they get from compiler

So general advice, if you are not asked for IDE advice then please keep it out of discussion. Once there is question on IDE just give your honest opinion and do not try to complain too much about competitor IDE as there is likely somenone on this forum using it :)

You're right. As I said in my last post, the problem is not which IDE he uses (we could discuss for quite some time aobut that :) ), but the fact that he uses one.

Too much off-topic :)

int computer = Math.random();
computer = 3 * Math.random;

I think you forgot the () there. Try

int computer = Math.random()*3;

Also:

esle if (computer = player)

Will not work. Instead of comparing player and computer, you are assigning the value of player to computer.
Change = to ==, and spell 'else' correct.

Good luck!

ok i edited ur code a bit this is what i did

import java.util.Scanner;
public class RockGame {

	private final static int ROCK=1;
	private final static int PAPER =2;
	private final static int SCISSOR =3;
	public static void main(String args[]){
		double playerOneScore = 0;
		double computerScore = 0;
		int userPlay, computerPlay;

		Scanner key = new Scanner(System.in);
		while(playerOneScore <2 && computerScore <2){


			System.out.println("choose 1 for rock 2 for paper 3 for sciscors");
			userPlay = key.nextInt();
			computerPlay = (int)(Math.random()*3) +1;
			if (userPlay==1)
				userPlay = ROCK;
			else if (userPlay==2)
				userPlay =PAPER;
			else if (userPlay==3)
				userPlay=SCISSOR;
			
			
			if (computerPlay==1)
				computerPlay = ROCK;
			if (computerPlay==2)
				computerPlay =PAPER;
			if (computerPlay==3)
				computerPlay=SCISSOR;

			if (computerPlay ==ROCK && userPlay==SCISSOR ){
				System.out.println("computer chose rock you lose");
				computerScore++;
			}
			if (computerPlay ==ROCK && userPlay==PAPER ){
				System.out.println("computer chose rock you win");
				playerOneScore++;
			}
			if (computerPlay ==PAPER && userPlay==SCISSOR ){
				System.out.println("computer chose scissor you win");
				playerOneScore++;
			}
			if (computerPlay ==PAPER && userPlay==ROCK ){
				System.out.println("computer chose paper you lose");
				computerScore++;
			}
			if (computerPlay ==SCISSOR && userPlay==ROCK ){
				System.out.println("computer chose scissor you win");
				playerOneScore++;
			}
			if (computerPlay ==SCISSOR && userPlay==PAPER ){
				System.out.println("computer chose scissor you lose");
				computerScore++;
			}
			if (computerPlay == userPlay ){
				System.out.println("TIE");
				
			}


		}
		if(computerScore > playerOneScore)
			System.out.println("hahaha computer win score is - "+ computerScore + " -" + playerOneScore  );
		else
			System.out.println("congrats you beat a random gen computer score is " + playerOneScore + "-" + computerScore );
		

	}


}

i have put everything in one method
hop u find this help fool

helpful***** typo not help fool lol

Great, the program works for me!

Can you mark this thread as solved?

lol thats up to the person who created the thread

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.