Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Apr 2012
    Posts
    44
    Tokens
    273

    Default The basics of Java.

    -----------------------------
    Java IDE

    First thing's first, you need to set up an IDE. I'll let Wikipedia explain what an IDE is if you've never come across the term.

    An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development

    http://en.wikipedia.org/wiki/Integra...nt_environment
    Here is a list of Java IDEs:
    • Eclipse
    • Netbeans
    • BlueJ
    • IntelliJ IDEA


    For the purpose of this tutorial, we will be using BlueJ. BlueJ is a fantastic IDE for new Java programmers, it can tell you where things go wrong which is always a plus.

    Here's the direct download link - http://www.bluej.org/download/download.html

    -----------------------------
    Tutorial Notation

    Mutator - A mutator is designed to modify existing fields, see type VOID.
    PHP Code:
    public void editAge() 
    Accessors - Accessors are used to return, display or call values from fields, types include boolean, String, int, double and more - These are data types!
    PHP Code:
    public String getName() 
    Parameters - Parameters are passed through the method, they're added inside of the brackets. See code below.
    PHP Code:
    public void editAge(int age
    What this does is, when the editAge method is called you will be prompted to add an age.

    Constructor - Say your class is called Tutorial, here's the constructor.
    PHP Code:
    public class Tutorial
    {
      
    // The constructor is below 
      
    public Tutorial()
      {

      }
      
    //End constructor

    So there's the notation.

    -----------------------------
    Your first script - Your information. AFTER EACH STEP, COMPILE (press Compile button).

    Hopefully you're now eager to write your first small script, and so we shall.

    1. On your BlueJ document, click New Class and set the Class Name to Me. Once it's created you'll see a small yellow box on your window, double click it and delete everything in there. It's all nonsense.

    2. So you should have a blank document, we need to declare our class and constructor. Here's our code.
    PHP Code:
    public class Me
    {
       public 
    Me()

    3. At present our script does nothing, so let's create some field declarations. Here's a brief overview of what we want our script to hold:
    • First Name
    • Surname
    • Age
    • School
    • Year


    So, we've got our list, it's probably best we assign relevant data types to our fields.

    String - Text that can include numbers e.g. 22 Carb Street.
    int - Whole numbers only, also supports a limited range.
    double - Whole and decimal numbers e.g. £2.50 (minus the £).
    boolean - Returns true or false, nothing else.

    In order to declare our fields, we merely add private 'datatype' 'fieldname';
    For example, First Name would be private String firstName; - I've named it firstName for ease, it can be anything.

    It is imperative you remember the semi-colon at the end of the lines, bar the method title.
    PHP Code:
    public class Me
    {
       private 
    String firstName;

       public 
    Me()
      {

      }

    Add all of your fields, try not to peak at mine, you're here to learn.


    4. Now we need to add data to those fields using parameters, remember those?
    Declare appropriate parameters in your constructor. You can call your parameter variables anything and you must assign them a datatype.
    PHP Code:
    ...
    public 
    Me(String myNameString lastNameint myAgeString mySchoolint myYear)
    {

    }
    .. 
    5. Next, we assign our parameters to our private fields. We simply do that by adding..
    PHP Code:
    firstName myName 
    Match your private fields with your parameter values. Your whole code should look like this:
    PHP Code:
    public class Me
    {
       private 
    String firstName;
       private 
    String surname;
       private 
    int age;
       private 
    String school;
       private 
    int year;

       public 
    Me(String myNameString lastNameint myAgeString mySchoolint myYear)
      {
          
    firstName myName;
          
    surname lastName;
          
    age myAge;
          
    school mySchool;
          
    year myYear;
      }

    What does the above do? - Good question, assuming you've compiled your code. Go onto BlueJ, right click and then click new Me(String myName, String lastName...)

    Once that has appeared, you're prompted to enter values for your parameters. Where you have to enter a String you must wrap it in speech marks, so beside String myName you must put "Tuts" instead of Tuts.

    6. Writing Methods (I've put it in bold because Methods are cool)

    INCREMEN
    Say it's your birthday tomorrow, and in our script your age is 20, you'll want to update it to 21 right? Let's right a method for that. What we want to do is increment (add) 1 to the age every time the method is called.
    PHP Code:
    public void oneYear()
        {
          
    age age 1;
        } 
    Here's how it works, we're using our mutator because we're changing data or existing fields.
    The age = age + 1 simply grabs what's currently inside the age variable and adds 1 to it.
    (Note: Remember we set age = myAge in our constructor?). Similarly you could use the shorthand form
    PHP Code:
    age += 1
    RETURN AGE
    You'll want to see if your age has changed right? Let's create another method. This time we're using accessors because we're not changing fields.

    PHP Code:
        public int getAge()
        {
            return 
    age;
        } 
    You're merely returning what's in the age variable, simples.

    So now your code should be similar to this:
    PHP Code:
    public class Me
    {
       private 
    String firstName;
       private 
    String surname;
       private 
    int age;
       private 
    String school;
       private 
    int year;

       public 
    Me(String myNameString lastNameint myAgeString mySchoolint myYear)
      {
          
    firstName myName;
          
    surname lastName;
          
    age myAge;
          
    school mySchool;
          
    year myYear;
      }
      
        public 
    void oneYear()
        {
          
    age age 1;
        }
        
        public 
    int getAge()
        {
            return 
    age;
        }

    Let's print all of this out in the format of text.
    Declare a mutator called getInformation.

    Inside your mutator add:
    PHP Code:
    System.out.println("Hello my name is " firstName " " surname ". I am " age " years old. I attend " school " and I'm in year " year); 
    Your document should look like this:
    PHP Code:
    public class Me
    {
       private 
    String firstName;
       private 
    String surname;
       private 
    int age;
       private 
    String school;
       private 
    int year;

       public 
    Me(String myNameString lastNameint myAgeString mySchoolint myYear)
      {
          
    firstName myName;
          
    surname lastName;
          
    age myAge;
          
    school mySchool;
          
    year myYear;
      }
      
        public 
    void oneYear()
        {
          
    age age 1;
        }
        
        public 
    int getAge()
        {
            return 
    age;
        }
        
        public 
    void getInformation()
        {
            
    System.out.println("Hello my name is " firstName " " surname ". I am " age " years old. I attend " school " and I'm in year " year);
        }

    In order to run it, through BlueJ, compile it, right click and then do new Me(String myName, String lastName...)

    Input your relevant information, you should see a red box appear at the bottom, right click it and you'll see your three (or more if you wrote your own) methods int getAge(), int oneYear(), void getInformation().

    Sorry for any vagueness, grammatical errors and what not. I've got work in a minute so I tried to get through it quickly. It took me 50 minutes to write out such a small tutorial. When I return I'll go through ArrayLists, Arrays and we will implement a text based interface for our small script we've just written.

    moderator alert Thread moved by Chris (Forum Super Moderator): From "Designing & Development". Great guide, thanks for posting!
    Last edited by Chris; 11-04-2012 at 04:45 PM.

  2. #2
    Join Date
    Oct 2005
    Location
    Spain, Valencia
    Posts
    20,492
    Tokens
    3,575
    Habbo
    GoldenMerc

    Latest Awards:

    Default

    This is brilliant +rep for the guide.

  3. #3
    Join Date
    Apr 2012
    Posts
    44
    Tokens
    273

    Default

    Thanks GoldenMarc!

    -----------------------------
    Let's set up our Command Line Interface

    Here's Wikipedia's definition of a CLI
    A command-line interface (CLI) is an interface or dialog between the user and a program, or between two programs, where a line of text (a command line) is passed between the two.
    In Java we use things called API's or libraries, when the library is implemented into our Java document, we can call methods within the library. For this, we're using Scanner. Here's the API http://docs.oracle.com/javase/1.5.0/...l/Scanner.html

    To import this into our document, we simply declare
    PHP Code:
    import java.util.Scanner 
    The java.util package contains classes that deal with collections, events, date and time, internationalization and various helpful utilities.

    http://java.about.com/od/javautil/java_util.htm
    Say we want to import a number of APIs within java.util, for example
    [PHP]import java.util.Scanner;
    import java.util.HashMap;
    import java.util.???;[PHP]

    We can simply write
    PHP Code:
    import java.util.*; 
    With the latter code, it will look at ALL of the API's within the java.util. So for ease, we're going to use .*

    Now, I'm going to introduce you to a new method declaration which looks like this
    PHP Code:
    public static void main(String[] args)
    {


    This is our main method, and does not need objects (those red boxes on BlueJ).

    For this project we will be using the same Me project in the first post.

    1. Start your document.
    PHP Code:
    public class Me
    {
        public static 
    void main(String[] args)
        {
            
        }

    We don't need a constructor for our project, it's not really important IMO.

    2. Import out Java library - This goes before our 'public class Me', simply add
    PHP Code:
    import java.util.Scanner
    or
    PHP Code:
    import java.util.*; 
    3. We need to set up our Scanner, in order to do that we have to call a Scanner object, so in order to do that we add this code within our public static void main(String[] args)
    PHP Code:
    Scanner scan = new Scanner(System.in); 
    System.out in Java will print out, so System.in will read in, we've declared a Scanner called scan which reads inputs.

    4. Let's set up a menu, in our Me project we had to make an object to input information for firstName, surname, age, school, year. For our CLI, we have to write some manual code.

    Please note: When using System.out.println("hi") (which outputs hi), we use \n within the speech marks to declare a new line. For example
    PHP Code:
    System.out.println("Hello Habbox \n This is my Java Tutorial \n I hope it's good"); 
    Will output:
    Hello Habbox
    This is my Java Tutorial
    I hope it's good

    5. Setting up a menu, we use our System.out.println() method which outputs to the terminal.
    PHP Code:
    import java.util.*;

    public class 
    Me
    {
        public static 
    void main(String[] args)
        {
            
    Scanner scan = new Scanner(System.in);
            
            
    System.out.println("What would you like to do?");
        }

    When run, it'll look like this:


    Now we'll implement a numeric menu which will be used to read changes.

    Add
    PHP Code:
    System.out.println("1. Add first name");
    System.out.println("2. Add surname");
    System.out.println("3. Add age");
    System.out.println("4. Add school");
    System.out.println("5. Add school year"); 
    or, for shorthand you could add
    PHP Code:
    System.out.println("1. Add first name \n 2. Add surname \n 3. Add age \n 4. Add school \n 5. Add school year"); 
    6. IF statement & Java operators - MUST LEARN.

    Now we welcome If statements, here's how an if statment is set out.
    PHP Code:
    If(This) {
    Then do this } ELSE {
    Do 
    this

    So here's a simple If statement, we'll assign the variable Age 3.
    PHP Code:
    If(Age == 3) {
    System.out.println("Yes, the age is 3");
    } else {
    System.out.println("No the age isn't 3");

    Multiple If statements.
    PHP Code:
    If(Age == 3) {
    System.out.println("Yes the age is 3");
    } else if(
    Age == 4) {
    System.out.println("Yes the age is 4");
    } else if (
    Age == 5) {
    System.out.println("Yes the age is 5");
    } else {
    System.out.println("That is not the age");

    Java operators: IMPORTANT.

    Age = 3 - This does NOT mean equal, this means store the value 3 in the variable Age.
    Age == 3 - This does mean equal, this says Age is equal to 3, we only use == for numbers, not Strings.
    > - More than.
    < - Less than.
    != - Does not equal.
    || - Or.
    && - And.

    Similar to PHP and other languages.

    7. Reading the choice.
    In our Scanner API there is a method called nextInt (just as well as nextLine() for String, nextLong() for Long and more). So we're going to be using nextInt() because our menu is numeric "1. Add first name" - We want the user to put 1 if they want to add a first name.

    So just underneath our Scanner declaration add
    PHP Code:
    int choice
    and then, underneath our menu add
    PHP Code:
    choice scan.nextInt() 
    What happens now is that our Scanner called scan will read the next integer put in from the keyboard and it'll store the input into the integer choice.

    Something else I've forgot, we want another choice in the menu to Exit, go back and edit your document to hold a 6th option, quit.

    OK, so now, we've got our choice. Let's set up some if statements.

    8. Determine what to do with each choice.
    PHP Code:
    if(choice == 1)
    {
      
    // Do something that relates to choice 1; firstname.
    } else if(choice == 2) {
      
    // Do something that relates to choice 2; surname.
    } else if(choice == 3) {
     
    // Do something that relates to choice 3; age.
    } else if(choice == 4) {
     
    // Do something that relates to choice 4; school.
    } else if(choice == 5) {
     
    // Do something that relates to choice 5; year.

    Now, we've forgot our 6th step; quit.

    We need to wrap our if statement in a loop.
    Loops will continue to be executed until the condition is not met.
    PHP Code:
    int i 0;
            while(
    5)
            {
                
    System.out.println("hi");
                
    i+1// or i++;
            

    OK so we've declared integer i to equal 0, the code says that WHILE I is less than 5, print out "hi" and then add 1 to i. So on the first run, i = 0. Then after the first loop adds 1 to i, i = 1. It happens until i is not less than 5 anymore. It should print out hi 4 times.

    We need this while loop, however our condition isn't the same, we need to say, well, while the choice does not equal 6 (which is exit) perform this code
    PHP Code:
    while(choice != 6)
    {
     
    // Input our long IF statement(s).

    There we go, that's our While loop.

    Your code should now look similar to this;
    PHP Code:
    import java.util.*;

    public class 
    Me
    {
        public static 
    void main(String[] args)
        {
            
    Scanner scan = new Scanner(System.in);
            
    int choice;
            
            
    System.out.println("What would you like to do?");
            
    System.out.println("1. Add first name");
            
    System.out.println("2. Add surname");
            
    System.out.println("3. Add age");
            
    System.out.println("4. Add school");
            
    System.out.println("5. Add school year");
            
    System.out.println("6. Quit");
            
            
    choice scan.nextInt();
            
            while(
    choice != 6)
            {
                if(
    choice == 1)
                {
                    
                } else if(
    choice == 2) {
                    
                } else if(
    choice == 3) {
                    
                } else if(
    choice == 4) {
                    
                } else if(
    choice == 5) {
                    
                }
            }
            
            
        }

    9. Adding our fields.

    Just like in our first project, we had firstName, surname, age, school, year. We need to declare those again within our new program. It's similar to before. Here's my declarations.

    PHP Code:
    Scanner scan = new Scanner(System.in);
            
    int choice;
            
    //Start new declarations.
            
    String firstName;
            
    String surname;
            
    int age;
            
    String school;
            
    int year
    Note: For shorthand you could have,
    PHP Code:
    int choiceageyear;
    String firstNamesurnameschool
    10. Let's write some methods.

    Add name
    PHP Code:
    if (choice == 1) {
     
    // Implement this method below.

    So we want to add a name (first name), let's have the CLI ask us what our name is.
    [PHP]if (choice == 1) {
    System.out.println("What is your name? \n");
    }

    Now we want to read that input, because name is String we want to use the method nextLine(); (See API method list for more information).
    PHP Code:
    if (choice == 1) {
    System.out.println("What is your name? \n");
    firstName scan.nextLine();

    We could add a confirmation output if we want.
    [PHP]if (choice == 1) {
    System.out.println("What is your name? \n");
    firstName = scan.nextLine();
    System.out.println("I knew it was you " + firstName);
    }[PHP]

    Our output will look like this:
    What is your name?
    Dan (my input)
    I knew it was you Dan

    Add surname

    We can duplicate our Add first name code and edit the variables
    PHP Code:
    } else if (choice == 2) {
     
    System.out.println("What is your surname? \n");
     
    surname scan.nextLine();

    Add age

    PHP Code:
    } else if (choice == 3) {
     
    System.out.println("How old are you? \n");
     
    age scan.nextInt();
     
    System.out.println("I was " age " years old when I was your age");

    I will let you add School and Year - It is similar to the already stated methods.

    So right now your program should be similar to this
    PHP Code:
    import java.util.*;

    public class 
    Me
    {
        public static 
    void main(String[] args)
        {
            
    Scanner scan = new Scanner(System.in);
            
    int choice;
            
    String firstName;
            
    String surname;
            
    int age;
            
    String school;
            
    int year;
            
            
    System.out.println("What would you like to do?");
            
    System.out.println("1. Add first name");
            
    System.out.println("2. Add surname");
            
    System.out.println("3. Add age");
            
    System.out.println("4. Add school");
            
    System.out.println("5. Add school year");
            
    System.out.println("6. Quit");
            
            
    choice scan.nextInt();
            
            while(
    choice != 6)
            {
                if(
    choice == 1)
                {
                    
    System.out.println("What is your name?");
                    
    firstName scan.nextLine();
                    
    System.out.println("I knew it was you " firstName);
                   
                } else if(
    choice == 2) {
                    
    System.out.println("What is your surname?");
                    
    surname scan.nextLine();
                } else if(
    choice == 3) {
                    
    System.out.println("How old are you?");
                    
    age scan.nextInt();
                    
    System.out.println("I was " age " years old when I was your age");
                } else if(
    choice == 4) {
                    
    System.out.println("What school do you attend?");
                    
    school scan.nextLine();
                } else if(
    choice == 5) {
                    
    System.out.println("What year are you in?");
                    
    year scan.nextInt();
                }
            }
           
            
            
        }

    However, when it's run and the first method is called (one to add your first name) you will notice that you're not given the chance to input anything as it'll print "What is your name" and then print "I knew it was you .." straight after.

    The only way I've found around it is implementing another scan.nextLine() which will read your enter key.

    PHP Code:
    if(choice == 1)
                {
                    
    System.out.println("What is your name?");
                    
    enter scan.nextLine();
                    
    firstName scan.nextLine();
                    
    System.out.println("I knew it was you " firstName);
                   
                } 
    This should be used after every print that requires an input, implement it into all of your methods.

    We also need to include the menu and choice reading in every method we're using, for every choice.
    We can copy and paste
    PHP Code:
    System.out.println("What would you like to do?");
            
    System.out.println("1. Add first name");
            
    System.out.println("2. Add surname");
            
    System.out.println("3. Add age");
            
    System.out.println("4. Add school");
            
    System.out.println("5. Add school year");
            
    System.out.println("6. Quit");
            
            
    choice scan.nextInt(); 
    Into all of our methods too.

    Your code should now look like this:
    PHP Code:
    import java.util.*;

    public class 
    Me
    {
        public static 
    void main(String[] args)
        {
            
    Scanner scan = new Scanner(System.in);
            
    int choice;
            
    String firstName;
            
    String surname;
            
    int age;
            
    String school;
            
    int year;
            
    String enter;
            
                
    System.out.println("What would you like to do?");
                
    System.out.println("1. Add first name");
                
    System.out.println("2. Add surname");
                
    System.out.println("3. Add age");
                
    System.out.println("4. Add school");
                
    System.out.println("5. Add school year");
                
    System.out.println("6. Quit");
            
                
    choice scan.nextInt();
            
            
            while(
    choice != 6)
            {
                if(
    choice == 1)
                {
                    
    System.out.println("What is your name?");
                    
    enter scan.nextLine();
                    
    firstName scan.nextLine();
                    
                    
    System.out.println("I knew it was you " firstName);
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. Quit");
            
                    
    choice scan.nextInt();
            
                   
                } else if(
    choice == 2) {
                    
    System.out.println("What is your surname?");
                    
    enter scan.nextLine();
                    
    surname scan.nextLine();
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 3) {
                    
    System.out.println("How old are you?");
                    
    enter scan.nextLine();
                    
    age scan.nextInt();
                    
    System.out.println("I was " age " years old when I was your age");
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 4) {
                    
    System.out.println("What school do you attend?");
                    
    enter scan.nextLine();
                    
    school scan.nextLine();
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 5) {
                    
    System.out.println("What year are you in?");
                    
    enter scan.nextLine();
                    
    year scan.nextInt();
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. Quit");
            
                    
    choice scan.nextInt();
            
                }
            }
           
            
            
        }

    Outside of our While loop, we want to issue a goodbye message, this will then stop the user from being able to interact further with our project.

    BlueJ users, if you can see the colours on your document, outside of the purple box add something like
    PHP Code:
    System.out.println("Thank you for using the program, goodbye"); 
    11. AAHHHHHHHHHHHH.

    You need to go back and initialize all of your fields. For example:
    PHP Code:
            String firstName null;
            
    String surname null;
            
    int age 0;
            
    String school null;
            
    int year 0
    Because we'll be calling on them in our next step, they need a default value even before we edit anything.

    12. My Information

    This method is entirely up to you to complete.

    Edit the existing code so that we can introduce a choice called My Information which is displayed before Quit.

    So it'll be
    ..
    6. My Information
    7. Quit

    You must edit the menu and the while loop.

    Once you've edited all of that, we'll print out all of your details
    PHP Code:
    } else if(choice == 6) {
                    
    System.out.println("Your name is " firstName " " surname ". You are " age " years old. You attend " school " and you're in year " year);
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
                } 
    We're done!!

    133 lines of code, and we're done.

    Your code should look like this:
    PHP Code:
    import java.util.*;

    public class 
    Me
    {
        public static 
    void main(String[] args)
        {
            
    Scanner scan = new Scanner(System.in);
            
    int choice;
            
    String firstName null;
            
    String surname null;
            
    int age 0;
            
    String school null;
            
    int year 0;
            
    String enter;
            
                
    System.out.println("What would you like to do?");
                
    System.out.println("1. Add first name");
                
    System.out.println("2. Add surname");
                
    System.out.println("3. Add age");
                
    System.out.println("4. Add school");
                
    System.out.println("5. Add school year");
                
    System.out.println("6. My information");
                
    System.out.println("7. Quit");
            
                
    choice scan.nextInt();
            
            
            while(
    choice != 7)
            {
                if(
    choice == 1)
                {
                    
    System.out.println("What is your name?");
                    
    enter scan.nextLine();
                    
    firstName scan.nextLine();
                    
                    
    System.out.println("I knew it was you " firstName);
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
            
                   
                } else if(
    choice == 2) {
                    
    System.out.println("What is your surname?");
                    
    enter scan.nextLine();
                    
    surname scan.nextLine();
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 3) {
                    
    System.out.println("How old are you?");
                    
    enter scan.nextLine();
                    
    age scan.nextInt();
                    
    System.out.println("I was " age " years old when I was your age");
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 4) {
                    
    System.out.println("What school do you attend?");
                    
    enter scan.nextLine();
                    
    school scan.nextLine();
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 5) {
                    
    System.out.println("What year are you in?");
                    
    enter scan.nextLine();
                    
    year scan.nextInt();
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
            
                } else if(
    choice == 6) {
                    
    System.out.println("Your name is " firstName " " surname ". You are " age " years old. You attend " school " and you're in year " year);
                    
                    
    System.out.println("What would you like to do?");
                    
    System.out.println("1. Add first name");
                    
    System.out.println("2. Add surname");
                    
    System.out.println("3. Add age");
                    
    System.out.println("4. Add school");
                    
    System.out.println("5. Add school year");
                    
    System.out.println("6. My information");
                    
    System.out.println("7. Quit");
            
                    
    choice scan.nextInt();
                }
            }
                    
    System.out.println("Goodbye");
           
            
            
        }

    and here's the visual output:


    When you press 7 it just says Goodbye and stops any text input.
    Last edited by Tuts; 11-04-2012 at 11:31 PM.

  4. #4
    Join Date
    Apr 2012
    Posts
    44
    Tokens
    273

    Default

    Nobody seems to be posting

    Here's a small bot I programmed which will type "thanks" into the Habbox reply box, and submit it.

    I'm using 1366 x 768, and I'm using the Non-Habbo Light skin.

    PHP Code:
    import java.awt.*;
    import java.awt.event.*;

    public class 
    Post
    {
        public static 
    void main(String[] argsthrows Exception
        
    {
            
    Robot post = new Robot();
            
            
    post.mouseMove(226339);
            
    post.delay(1000);
            
    post.mousePress(KeyEvent.BUTTON1_MASK);
            
    post.delay(50);
            
    post.mouseRelease(KeyEvent.BUTTON1_MASK);
            
            
    post.delay(2000);
            
            
    post.keyPress(KeyEvent.VK_T);
            
    post.delay(50);
            
    post.keyRelease(KeyEvent.VK_T);
            
            
    post.keyPress(KeyEvent.VK_H);
            
    post.delay(50);
            
    post.keyRelease(KeyEvent.VK_H);
            
            
    post.keyPress(KeyEvent.VK_A);
            
    post.delay(50);
            
    post.keyRelease(KeyEvent.VK_A);
            
            
    post.keyPress(KeyEvent.VK_N);
            
    post.delay(50);
            
    post.keyRelease(KeyEvent.VK_N);
            
            
    post.keyPress(KeyEvent.VK_K);
            
    post.delay(50);
            
    post.keyRelease(KeyEvent.VK_K);
            
            
    post.keyPress(KeyEvent.VK_S);
            
    post.delay(50);
            
    post.keyRelease(KeyEvent.VK_S);
            
            
    post.mouseMove(982558);
            
    post.delay(5);
            
    post.mousePress(KeyEvent.BUTTON1_MASK);
            
    post.delay(50);
            
    post.mouseRelease(KeyEvent.BUTTON1_MASK);
            
            
    System.out.println("Thank you for commenting");
            
        }

    Last edited by Tuts; 13-04-2012 at 09:46 AM.

  5. #5
    Join Date
    Oct 2006
    Posts
    9,900
    Tokens
    26,832
    Habbo
    Zak

    Latest Awards:

    Default

    This is excellent for beginners. I myself have studied Java for three years. You've put a lot of work into this and it shows, even scanning through it looks exceptional, I recommend this to people on here who study low-end languages (html,css,php). Java is a step up, though I prefer C++!

    +REP

  6. #6
    Join Date
    Apr 2012
    Posts
    44
    Tokens
    273

    Default

    Thanks for the feedback Zak, I'm glad you appreciate it.

  7. #7
    Join Date
    Feb 2012
    Location
    Philadelphia
    Posts
    46
    Tokens
    0
    Habbo
    Cornholio!.

    Default

    This is great! I'm sure it will help a ton of people! If it hasn't already. ;D
    open to see my signature! It's worth it, trust me. ;D


  8. #8
    Join Date
    Jul 2009
    Posts
    14,747
    Tokens
    55,541
    Habbo
    lawrawrrr

    Latest Awards:

    Default

    Oh this is going to be so useful! Only read about half but it's really comprehensive. Great guide for beginners, thank you!! +rep





  9. #9
    Join Date
    Oct 2006
    Posts
    9,900
    Tokens
    26,832
    Habbo
    Zak

    Latest Awards:

    Default

    I myself are making a personal darts application in Java atm

  10. #10
    Join Date
    Apr 2012
    Posts
    44
    Tokens
    273

    Default

    Hey @Zak;, how's your application going? It's been 5 months since I last updated this thread, I'll produce a new and more extensive tutorial regarding GUIs.
    Last edited by Tuts; 25-01-2013 at 06:29 PM.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •