Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Please help me out! Newbie in distress  (Read 1507 times)
0 Members and 1 Guest are viewing this topic.
Offline ITz4D3N

Senior Newbie


Medals: 2



« Posted 2013-05-31 14:57:59 »

Hey, I tried to make an if statement just to practice (I know I'm a noob) and the else statement keeps bugging out, Help!
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class integer {

   
   public static void main(String[] args) {
   
       int boy, girl;
       boy = 18;
      girl = 68;
       
     
      if(boy > 10); {
         
         System.out.println("You can enter");
         
      }else{
         
         System.out.println("You are too young");
         
      }
      }
   }    
Offline ITz4D3N

Senior Newbie


Medals: 2



« Reply #1 - Posted 2013-05-31 14:59:20 »

Sorry for wasting your time, I added an extra ; It's fixed now ^^
Offline Andre Lopes
« Reply #2 - Posted 2013-05-31 15:01:34 »

First, change that class name to something else, like : Age
When you change it, be sure to change the file name to that as well, unless you using eclipse or netbeans... you can rename/refactor.

Second, class names starts with UpperCase, as far as im concerned, not 100% sure.

Third, the if is missing the girl variable.


Try this :


if(boy > 10)
{
System.out.println("Boy Can Enter");
}else
{
System.out.println("boy cant enter");
}


if(girl > 10 )
{
System.out.println("Girl Can Enter");
}else
{
System.out.println("Girl cant enter");
}




Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ags1

JGO Wizard


Medals: 67
Projects: 3
Exp: 5 years


Make code not war!


« Reply #3 - Posted 2013-05-31 15:10:51 »

You might like to try these tutorials:

http://docs.oracle.com/javase/tutorial/

They cover the language essentials.

Also try using a proper IDE like Eclipse or IntelliJ. You have to learn how to use the IDE, so there is some effort there, but it will catch simple mistakes for you like missing semicolons and so on. Most programmers rely on an IDE because they really increase your productivity.

If you use IntelliJ, it will give you advice about your code, like "Your class name needs an uppercase letter" or "you can remove the if statement because it is always true". Eclipse does something similar.


Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2013-05-31 16:26:06 »

Yes, use an IDE, and learn basic java before attempting to learn game programming - when you do pick up game programming, it'll be that much easier.
Offline Andre Lopes
« Reply #5 - Posted 2013-05-31 20:20:36 »

1  
2  
3  
4  
5  
www.eclipse.org/‎

or

netbeans.org/
Offline ItzKR15

Senior Newbie


Medals: 1



« Reply #6 - Posted 2013-05-31 20:53:29 »

Oh i didn't realize that was u aden!

Just keep coding, Just keep coding!

http://internetometer.com/image/39407.png Please Give me Internets!
Online matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2013-05-31 21:13:08 »

Oh wow... that's definitely not the right indentation Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public class integer {
   public static void main(String[] args) {
        int boy = 18;
        int girl = 68;
       
        if(boy > 10) {  
            System.out.println("You can enter");      
        }else{
            System.out.println("You are too young");
        }
    }
}

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #8 - Posted 2013-05-31 21:32:53 »

AND INTEGER SHOULD HAVE THE I CAPITALIZED
>code convention n4zi
Online matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #9 - Posted 2013-05-31 21:41:16 »

AND INTEGER SHOULD HAVE THE I CAPITALIZED
>code convention ****

The fun thing is: The newbe will ask you: Now why should I do that?
Coding conventions are there to make reading code easier. But yet he hasn't read code himself a lot, so he didn't find out the problems with not following coding conventions. All coding conventions are there to solve a problem. Let him find out himself. Imagine you're him, you don't know why to capitalize some words and others not. Why shouldn't he introduce all variables at the top and assign values to them later (I changed it when I posted the indented code)?

The answer 'bout the Classes: It makes you see the difference between a method and a class. You know which one you'll be able to call and which one to store or which one to allocate or whatever on the first glance, if your eyes started to recognize such a pattern.

The answer 'bout introducing the variables: Even simpler. You might forget to initialize a variable to '18' or '68'. Also you need to write less code...

<edit>Btw, he can't call his class
Integer
because there is already java.lang.Integer, too, I guess Wink</edit>

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Andre Lopes
« Reply #10 - Posted 2013-06-01 00:03:56 »

I laughed jimmt Tongue

http://www.oracle.com/technetwork/java/codeconv-138413.html
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2013-06-01 06:41:34 »

In This Thread: terrible advice Smiley

1. You have a semicolon after the if statement. That is why the else statement is giving you an error, because it can't find the if statement due to that code block in the middle of two. Remove the semicolon and everything works.

2. DO NOT use an IDE when you are just a beginner with programming. LEARN how to code in Notepad (with proper formatting and code conventions) and compile on the command line.

Offline ReBirth
« Reply #12 - Posted 2013-06-01 07:38:39 »

To add ra4king's advices, because he's nothing without me around:

2. When you look that terrible exception in command line, learn it! Know what it means, every single word. Try to debug based on that. When you move to IDE later you might not find some of them anymore because the IDE takes care it for you, but still you need to get the fundamental.

Offline ags1

JGO Wizard


Medals: 67
Projects: 3
Exp: 5 years


Make code not war!


« Reply #13 - Posted 2013-06-01 12:39:38 »

In This Thread: terrible advice Smiley

1. You have a semicolon after the if statement. That is why the else statement is giving you an error, because it can't find the if statement due to that code block in the middle of two. Remove the semicolon and everything works.

2. DO NOT use an IDE when you are just a beginner with programming. LEARN how to code in Notepad (with proper formatting and code conventions) and compile on the command line.

Yup, I see the advice about 'don't use an IDE as a beginner' all over the place - I just don't happen to agree with it. Notepad will give you zero advice about coding conventions. The compiler will be equally unhelpful.

There's nothing clever about programming in a deliberately obtuse way.

I quite an experienced programmer, but I learn things from IntelliJ every day.

Would you learn to spell better if you switched of your word processor's spell checker, and instead got a list of line numbers containing spelling errors every time you saved? That's just masochism.

IDEs are there to help you. I make dumb mistakes like forgetting semicolons all the time - being a Certified Java Programmer is no insurance!  Wink If I didn't have an IDE to catch the confetti of idiocy I am always sprinkling over my code, I wouldn't get very far at work or at home.

Offline ReBirth
« Reply #14 - Posted 2013-06-01 12:43:28 »

Well if you're Java Certified I believe your need on IDE is triggered by work, you just need to get things done and fast. But for someone who is still on baby step, understanding exceptions through that black command line window is important so no more NullException asking threads get posted anymore.

Offline Sammidysam
« Reply #15 - Posted 2013-06-01 13:51:52 »

I actually started out with an IDE and now I'm switching towards just using Notepad++ (on Windows) and Sublime Text 2 (on Linux) and compiling with an automatic builder that my friend and I are making.  I seem to be doing the complete opposite thing that most people do.  This is probably a horrible reason, but the main reason why I am doing so is because I want people to be able to clone my GitHub repositories and then easily compile them.  When I use Eclipse, they have to open Eclipse to do so, and opening Eclipse sadly takes quite a bit of time.  However, it seems kind of counter-intuitive to force them to install and auto-builder program to compile my programs too.
Offline ags1

JGO Wizard


Medals: 67
Projects: 3
Exp: 5 years


Make code not war!


« Reply #16 - Posted 2013-06-01 13:55:45 »

Auto-builder program? I think you might want to use Ant Cheesy

Offline Sammidysam
« Reply #17 - Posted 2013-06-01 14:00:58 »

I kind of agree, but I kind of feel like it's a bit too much writing.  It's more convenient to just write down the libraries necessary and a minimal amount of rules (probably zero for Java, based on what I think will happen) and be done.

For example, a simple ant buildfile looks like this according to Apache Ant's official tutorials:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
<project name="MyProject" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>


whereas with the program my friend and I are making, an example setup for C (he hates Java and loves C and C++ so the Java compatibility will be purely done by me) would look like this:

This is basically the setup the setup for a project my friend made with it.

.buildifile:
1  
-llua


to build:
1  
buildify


Which I find more convenient.  In the future the .buildifile will likely have LIBS=-llua instead of just -llua to better comply with the new rules that will later be added.  You can see our program here.
Offline ags1

JGO Wizard


Medals: 67
Projects: 3
Exp: 5 years


Make code not war!


« Reply #18 - Posted 2013-06-01 14:11:34 »

All you've done is move the complexity into your build tool. Now to change the build process, I will have to change your build tool.

Ant is a bit verbose I agree, but it is feature-rich and will be able to do anything you want it to. Also, any Java developer will immediately understand your Ant build script, or will at least have recourse to the excellent Ant documentation. None of this is true for your build tool.

Plus... you can run the Ant script from any IDE, or on an automated build server like Team City (I love Team City).

Offline ITz4D3N

Senior Newbie


Medals: 2



« Reply #19 - Posted 2013-06-01 14:13:20 »

I am using eclipse, Just not used to the interface yet, Thanks anyway.
Offline ags1

JGO Wizard


Medals: 67
Projects: 3
Exp: 5 years


Make code not war!


« Reply #20 - Posted 2013-06-01 14:14:10 »

Ha ha! So perhaps I lost the argument Smiley

Offline Sammidysam
« Reply #21 - Posted 2013-06-01 14:20:25 »

I'll look more into Ant.  Maybe the program I'm making would be good for very simple projects as long as I make some more .buildifile rules, and then Ant would be good for bigger projects where you need more control over what is going on.
Offline Danny02
« Reply #22 - Posted 2013-06-01 17:28:43 »

I'm always wondering around here(this forum) why it seems as if nobody ever heard of maven. It's like an industry standard by now.

you have a simple xml like this in your project folder
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.danny02.darwin</groupId>
    <artifactId>ResourceDemo</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>


    <dependencies>
        <dependency>
            <groupId>com.github.danny02.darwin</groupId>
            <artifactId>ResourceHandling</artifactId>
            <version>2.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>


and then you just call "mvn clean install" to build your project
Online matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #23 - Posted 2013-06-01 20:31:33 »

I have to agree with ags1.

When I was starting out with Scala I tried out IntelliJ for the first time. It helped me incredibly, since it's telling me, whenever I'm doing something against the coding conventions. Spell checking is awesome too.

Compiling everytime you want to check whether your code is valid takes much more time than getting immediate results while you type.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!