Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Triggor's Avatar
    Join Date
    Sep 2016
    Gender
    male
    Posts
    7
    Reputation
    10
    Thanks
    5
    My Mood
    Inspired

    Lightbulb The basics of Java

    I decided to write this tutorial, because I found a lot of people are looking to learn Java; this is a very nice language, but that's ofcourse my opinion. In this tutorial I will show you how to create a VAT calculator, and I will make sure that you understand everythingof the code. If you master this, you will master the very basics of Java. Make sure you read everything very carefull, you will learn nothing by copy pasting.
    Feel free to use this tutorial.
    Good luck!

    What do you need?
    - IntelliJ IDEA: I am not going to explain how to set this up for Java SDK etc, this tutorial will only focus on programming itself, assuming that you have everything set up already
    - Java SDK

    Lets start!
    First, create a class file in IntelliJ. Give it a name, for example 'VAT'.
    Once you created the class file, we are going to paste some code:
    Code:
    public class VAT{
    }
    I assume that you now why we need to type this, we are just creating the actual class in the class file. This is most of the time auto generated, so chances are that this is already in your Java class file.

    Once that's done, we are going to create our main. Java requires this Main, because once you start your program, the main will be executed first, and everything in the main will be executed. For a simple program like this, we only need 1 class etc., and nothing besides the Main.
    In intelliJ you can type 'psvm', this will auto give you the main. If psvm does not work, then type this:
    Code:
     public static void main(String[] args) {
    }
    So this is what we already have:
    Code:
     public class VAT {
        public static void main(String[] args) {
    }
    }
    I am not going to explain this, just remember that you always need a Main in Java and ofcourse your class.

    Now comes the real coding. inside you main, type the next code:
    Code:
      double percent;
            double amount;
            double amountEx;
            double amountIn;
            double fixedPercent;
            double choice;
    This is a lot of information. The code exists out of 2 parts: the 'type' and the variable.
    In all of the cases, the type here is double. We could also use int, wich stands for integer, but if we would use int we would not be able to use decimal numbers. double allows us to make use of decimal numbers. But just so you know, int would also work.
    Then we have the variables. for a VAT calculator, we need al these ones, because a VAT calculator follows an algorithm that makes use of these variables. You can rename them, however, I think these names are just very logic and make the most sense. Let's get to the next step.

    Code:
    Scanner Keyboard = new Scanner(System.in);
    Because we need to capture the things people type into our program, we need to create a scanner. A scanner allows us to do this. So we type Scanner Keyboard, this simply means that we are going to define a Scanner called Keyboard. You can call it whatever you want however.
    then we define Keyboard as a new Scanner (so now we create the scanner Keyboard), and to make sure that you capture te input of the keyboard, we set the input as (System.in) <-- wich stands for System.input ofcourse.

    Now that we created our scanner, we want to get some text on the screen. You can do this by using System.out.println
    In this case, type something like:
    Code:
    System.out.println("Give the VAT percentage in procents.");
    println stands obviously for printline, and we use System.out here because we want output and no input.

    What we already have now:

    Code:
    public class VAT {
        public static void main(String[] args) {
    double percent;
            double amount;
            double amountEx;
            double amountIn;
            double fixedPercent;
            double choice;
    Scanner Keyboard = new Scanner(System.in);
    System.out.println("Give the VAT percentage in procents.");
    }
    }
    Now, we asked for some input. We ask the people to input the percentage in procents. We will put this amount into a variable, one that we created at the start of this tutorial. Ofcourse, we will use the variable 'percent', wich is a double, so people can use decimals. The next step is to declare this variable, to give it an amount.
    We type the next code:
    Code:
     percent = Keyboard.nextDouble();
    What this code says is that the variable percent gets the value of the next Double that gets typed at our Scanner Keyboard.
    Now we have the percent, but we also want the amount of money we have and if that amount is inclusive the VAT or exclusive.

    So we add the next code:
    Code:
    System.out.println("Give the amount in Euro's");
           amount = Keyboard.nextDouble();
            System.out.println("Is this including or excluding VAT?\n1 Inc\n2 Exc");
            choice = Keyboard.nextDouble();
    Pretty easy, right?
    Now comes a part that's a bit harder. We asked the people for a choice. If they type 1, we will calculate the amount including the VAT, with 2 excluding. So, we need to make use of 'if'.

    Let's start with choice 1.
    Code:
    if (choice == 1) {
                fixedPercent = 100 - percent;
                amountInc = amount * fixedPercent;
                amountInc = amountInc * 100;
                System.out.println(amountInc);
            }
    That's a lot code don't worry, I will explain everything of it.
    Code:
    if (choice == 1)
    Well, this isn't that hard, right? If the variable choice equals amount 1, then we execute something. But why do we use == instead of =? Well in Java, = means that something is changed into that value , and == means that we check if something is that value. So if we would use if (choice = 1) then variable choice would be changed into 1.

    Code:
     fixedPercent = 100 - percent;
    This is simply needed for the formula of the VAT calculator. fixedPercent = 100 - percent so if the inputted percent was 15 then fixedPercent would be 85.

    Code:
    amountInc = amount * fixedPercent;
    We run the formula, and give the value to variable amountInc.

    Code:
     amountInc = amountInc * 100;
                System.out.println(amountInc);
    Because we worked with percents, the amunt needs to be multiplied by 100. And finally we print the value!


    That was it! I hope you understand the basics of Java now, and I hope you can make the amountExl now yourself
    Last edited by Triggor; 09-28-2016 at 12:08 AM.

  2. The Following 5 Users Say Thank You to Triggor For This Useful Post:

    Greythorne (08-20-2018),Hector (08-02-2018),Katz. (09-29-2016),Tuuuuan (09-28-2016),xBoboy (01-03-2018)

  3. #2
    Mayion's Avatar
    Join Date
    Oct 2012
    Gender
    male
    Location
    Bed
    Posts
    13,504
    Reputation
    4018
    Thanks
    8,372
    My Mood
    Twisted
    Great tutorial; thanks for your contribution.
    I do not use any type of messenger outside of MPGH.
    Inactive but you can reach me through VM/PM.










     

    Donator - 30 August 2013
    Battlefield Minion - 26 October 2013

    Blackshot Minion - 14 January 2014/16 September 2014
    Minecraft Minion - 7 February 2014/16 September 2014
    WarRock Minion - 23 February 2014
    League of Legends Minion - 21 March 2014

    Minion+ - 15 May 2014
    Other Semi-Popular First Person Shooter Minion - 8 August 2014
    CrossFire Minion - 23 October 2014
    Programming Section Minion - 13 November 2014
    Marketplace Minion - 7 December 2014

    Official Middleman - 7 December 2014 - 27 June 2015
    Moderator - 29 December 2014
    Project Blackout Minion - 10 January 2015
    News Force Interviewer - January 2015
    Steam Games Minion - 21 March 2015
    Dragon Nest Minion - 31 March 2015
    Publicist - April 2015 - 21 September 2015
    Global Moderator - 25 August 2015
    Super User - 13 August 2016



  4. The Following User Says Thank You to Mayion For This Useful Post:

    Triggor (09-28-2016)

  5. #3
    Katz.'s Avatar
    Join Date
    Sep 2016
    Gender
    male
    Location
    Posts
    222
    Reputation
    15
    Thanks
    34
    This really helped me thank you sir

  6. #4
    AceStyx's Avatar
    Join Date
    Jun 2016
    Gender
    male
    Location
    Present
    Posts
    476
    Reputation
    56
    Thanks
    132
    My Mood
    Cheerful
    well thanks man
    !

  7. #5
    yar5260's Avatar
    Join Date
    Mar 2015
    Gender
    male
    Posts
    155
    Reputation
    26
    Thanks
    9
    My Mood
    In Love
    many thanks

  8. #6
    ZPCNYref's Avatar
    Join Date
    Sep 2016
    Gender
    male
    Posts
    65
    Reputation
    10
    Thanks
    5
    Great to have such a sharable comrades

  9. #7
    Arid's Avatar
    Join Date
    Sep 2016
    Gender
    male
    Posts
    15
    Reputation
    10
    Thanks
    0
    Very interesting, thanks for making this.

  10. #8
    journeyofflower's Avatar
    Join Date
    Aug 2017
    Gender
    male
    Posts
    24
    Reputation
    10
    Thanks
    7
    great tut, thank u

  11. #9
    MrPerfect's Avatar
    Join Date
    Sep 2015
    Gender
    male
    Posts
    304
    Reputation
    9
    Thanks
    12
    ok sounds good

  12. #10
    Hector's Avatar
    Join Date
    Jul 2018
    Gender
    male
    Location
    Just trying to be a decent being
    Posts
    2,492
    Reputation
    1032
    Thanks
    557
    My Mood
    Hungover
    Very nice really I appreciate the time you have spent in it

  13. #11
    Greythorne's Avatar
    Join Date
    Aug 2018
    Gender
    male
    Posts
    235
    Reputation
    71
    Thanks
    30
    What a fantastic tutorial, this will surely help people learn the basics of java and get right into it.

  14. #12
    korolx147's Avatar
    Join Date
    Jul 2012
    Gender
    male
    Posts
    14
    Reputation
    10
    Thanks
    2
    very basic and informative, thanks!

  15. #13
    sippy98's Avatar
    Join Date
    Jul 2016
    Gender
    male
    Posts
    122
    Reputation
    59
    Thanks
    24
    My Mood
    Buzzed
    I'm learning python now, I want to learn this language next. Thanks

  16. #14
    jak2772's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    13
    Reputation
    10
    Thanks
    0
    helps a lot man thank you!

  17. #15
    3bd0u's Avatar
    Join Date
    Sep 2017
    Gender
    male
    Posts
    36
    Reputation
    10
    Thanks
    7
    thanks for sharing.

Page 1 of 2 12 LastLast

Similar Threads

  1. [Tutorial] Font Tags and the basics.
    By Spookerzz in forum Web Languages
    Replies: 11
    Last Post: 10-10-2011, 12:35 AM
  2. Teach me the basics(if you want)
    By bb009 in forum C++/C Programming
    Replies: 4
    Last Post: 04-08-2010, 05:58 PM
  3. C# Tutorial, starting, learning the basics, and keeping...
    By 'Bruno in forum C++/C Programming
    Replies: 20
    Last Post: 12-30-2009, 04:56 PM
  4. The basics
    By Empire in forum Anime
    Replies: 18
    Last Post: 11-20-2009, 06:56 PM
  5. Tut Getting vb and learning the basics
    By nlowner in forum Visual Basic Programming
    Replies: 3
    Last Post: 08-03-2007, 04:05 PM