1

First Ever Java "Game"

TheGrimGamer14 5/28/15 7:55 am
797
5/29/2015 12:53 pm
So I decided to learn java, and this is my first project after a few tutorial videos.

Click to reveal
import java.util.Random;
import java.util.Scanner;

public class Main {

public static int number, guess, maxValue;
public static Scanner scan;
public static Random rand;

public static void main(String args[]) {
scan = new Scanner(System.in);
rand = new Random();
System.out.println("Please enter a maxiume value too guess from!: ");
maxValue = scan.nextInt();
number = rand.nextInt(maxValue);
System.out.print("Please Enter a guess: ");
while (guess != number) {
guess = scan.nextInt();

if (guess > number) {
System.out.println("Your guess is too high!");
}
if (guess < number) {
System.out.println("Your guess is too low!");
}

}
System.out.println("You Won!");
}

}
Posted by
TheGrimGamer14
Level 1 : New Network
1

  Have something to say?

JoinSign in

6

Pixel
05/29/2015 12:53 pm
Level 43 : Master Mage
thenubslayer2000
ThePixelPony
StackOverflow is a great place to learn.

You mean the first result that comes up when you google 'java how to x'


Yes, although the "How to" is unnecessary. You should be searching using this format: "<subject and sub-subjects> <problem in as few words as possible>". E.g. "minecraft java modding tutorial".
1
Leeberator
05/29/2015 12:34 pm
Level 47 : Master Button Pusher
This makes me want to find out how to program on my calculator. I could make some neat programs on my Ti-83 Plus but this new Nspire CX is a bit more involved, it seems.
1
zoecGxhbmV0bWluZWNyYWZ0
05/29/2015 12:26 pm
Level 21 : Expert Ninja
ThePixelPony
StackOverflow is a great place to learn.

You mean the first result that comes up when you google 'java how to x'
1
Pixel
05/29/2015 11:17 am
Level 43 : Master Mage
You've started learning Java; great!
I'll teach you some things.

"Access" modifiers:
public - Can be accessed from any class
private - Can only be accessed from inside the current class
protected - Can be accessed inside this class and any of its children (classes that extend it) and from inside the same package
nothing - Can be accessed from the same package (folder)

Other modifiers:
final - Once defined, it cannot be changed, use it when possible; it improves performance
static - There is only one of these in the class, try to avoid using this when you can
abstract - It exists but has to be defined by child classes, you won't need this for a while yet
transient - Uhh, you won't need this for ages so forget about it

When you have fields in a class (e.g. "Scanner scanner;") you usually want to make them private. It's good practise. When another class needs them, you create a method called getScanner() that returns the private Scanner object.

If you have any questions, feel free to PM!

http://stackoverflow.com/questions/2154 ... nd-private

StackOverflow is a great place to learn.
1
serdarminecraft
05/29/2015 11:10 am
Level 18 : Journeyman Warrior
RoboShadowHey! I've made that game on my calculator!



Me too!
1
RoboShadow
05/28/2015 10:29 am
Level 34 : Artisan System
Hey! I've made that game on my calculator!
But GJ OP, you're going places.

:C->0
:Disp "Minimum:"
:Prompt X
:Disp "Maximum:"
:Prompt Y
:randInt(X,Y)->A
:Lbl 1
:Disp "Guess"
:Prompt B
:If B>A:Disp "Guess too high":Pause:C+1->C:Goto 1
:If B<A:Disp "Guess too low":Pause:C+1->C:Goto 1
:If B=A:Disp "Correct!":C+1->C:Goto 2
:Lbl 2
:Disp "Number of guesses":Disp {C}
1

Welcome