Free £25 Bet!
Free £50 Bet at VCBet!
Free £25 Bet!

In association with Sports-Punter Free Bets Odds Comparison BetHelp Limso

We are the Official Forum of FreeBetting.net & FCBet.com


Sports News Sports Stats Live Scores OddsChecker Place Bets Suggest a Site


Go Back   The Punters Lounge - The World's Best Betting Forum > Systems, Strategy and General Betting Help > Punters Tools & General Betting Help Forum

Punters Tools & General Betting Help Forum Everyone has tools that use to help them bet. Match reports, odds comparison services, tipster services, betting calculators, selection software - discuss them here.

UK & Irish Football Forum | Western European Football Forum | UEFA Cup & Champions League Football Forum | International Football Forum | Eastern & Southern European Football Forum | Nordic & Scandinavian Football Forum | Non European Football Forum | At The Races Forum | At The Races Systems Forum | Other Sports Forum | USA Sports Forum | Fantasy & Fun Comps Forum | Free Bets Forum | Systems & Strategy Forum | Glory Hunter's Forum | Tipster's Challenge Forum | Daily Racing Comp Forum | Euro & Worldwide Comp Forum | Poker Tourneys Forum | Poker Strategy Forum | Poker Chat Forum | Poker Live Forum | Poker Challenges Forum | Poker Staking Forum | e-Sport Poker League Forum | Bookmakers & Exchanges Forum | Punter's Tools/Betting Help Forum | General Chat Forum | Tech & Gaming Forum | Sports Banter Forum | Live Sports Feeds Forum

Closed Thread
 
Thread Tools Display Modes
Old 29-04-2004, 20:54   #1 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,330
Default Lesson 2 - Language, a few calculations

Lesson 2 ( Word document )

Punters Lounge JAVA programming course.

Lesson 2 - Learning the language, a few calculations

Now we are going to start learning the JAVA language. For those of you in the ROOKIE class I suggest you follow my lead here. Feel free to have a look at the tutorials I will include for the SCHOLAR class but beware that for beginners the technical language used may give you a headache.

For those in the SCHOLAR class you can use this tutorial:
java.sun.com/docs/books/tutorial/java/index.html

All I'm doing here is a simplified version of that tutorial. It all depends on your level and type of experience how fast you pick things up. Don't be afraid to change class, even I still get headaches from reading some of those tutorials.



2.1 Object Oriented Programming

What is Object Oriented Programming? Well first what does an object mean here? An object is simply the representation of a real-life object. You can look at the whole world as a collection of objects: the world, inside that are continents, cities, a house, and a table, right down to molecules and atoms. Each object consists of a collection of smaller objects. Objects are not limited to simple physical items but can get complex like a country or an army. Basically it is a way of looking at things. How does it relate to programming? Well it is simply a way of programming where the programmer chooses to look at the world as a collection of objects and then applies that way of looking at things to the programming itself.

There are two things you need to know about objects and that is that they have a state and behaviour. As an example lets look at a simple motorbike.

Our motorbike has a throttle and a brake. That's it. The throttle and the brake are called methods. The behaviour is throttle up, throttle down and brake. The state is the speed of the motorbike. You as a user use the methods of the object to change its state. So you use the throttle and brake to change the objects speed.

This is what you do in object oriented programming. You write a piece of software, consisting of objects that have methods and state. This short explanation is enough for now. It gives you an idea of what's involved. We will come back to the subject later.

2.2 Variables

In a Java program you use variables to store information. A variable is a container you put something in and you give the container a name. A bit like a card board box, you put something in and write on the box what's in it.


2.3 Operators

An operator is a command. You use an operator to tell the program to do something. The plus sign + is an operator. You use it to tell the program to add two values together.

Here are some simple mathematical operators.
+ addition
- subtraction
* multiplication
/ division

2.4 Control flow statements

Is a statement telling the program to proceed in a certain direction depending on a condition being met or not. For example the IF THEN statement. It reads like this:

IF (condition met) THEN (proceed here) ELSE (proceed here).

Or something like this:

IF (beerglas is empty) THEN (goto fridge and get more) ELSE (drink up).

Some conditional operators that can be used in the IF statement
> greater then
< less then
== equal
!= not equal


2.5 Example program

Lets look at a small program and see if we can identify all of the above and explain a bit more as we go along.


public class Lesson2 {
public static void main(String[ ] arguments) {



  • int Bank = 1000;
  • int Bet = 100;
    int Odds = 3;
    int WinLose = 0;

    if (WinLose == 0)
    {


    • Bank = Bank - Bet;
    }


    else
    {


    • Bank = (Bank - Bet) + (Bet * Odds);
    }



    System.out.println(Bank);
}

}

First line
public class Lesson2 {

Second line
public static void main(String[ ] arguments) {

These first 2 lines create a class called Lesson2. A class is a definition of an object. In our case it's our entire program. The word public tells Java that it is a publicly accessible object. To be able to do anything our object must have at least one method and that is defined in the second line. The method is called main and it is run automatically when the program is run. For now ignore public static void and (String[ ] args). That will be explained later in the course.


Lines 3 - 6
int Bank = 1000;
int Bet = 100;
int Odds = 3;
int WinLose = 0;

Now these lines define 4 new objects. The type of object is int, short for integer; the names of the objects are Bank, Bet, Odds and WinLose. You could say these are 4 card board boxes big enough to contain an integer value and the names Bank, Bet, Odds and WinLose have been written on the boxes. The = sign is used to assign values to the object. The = sign is called an operator, it tells the computer to do something. The whole of a line is called a statement.

Note that you must end the line with a ; sign so Java knows where the statement ends.


Line 7
if (WinLose == 0)

Here we have an IF THEN ELSE statement. Note the command is called IF THEN but we do not actually write the THEN word. The part between the round brackets is the condition we check. In this case we use the == sign to check if the contents of WinLose is 0 or not. If it is 0, the condition is true and the program will proceed with the next line. If WinLose is not 0, the condition is false and the program will continue after the ELSE statement.


Line 8 – 10
{
Bank = Bank - Bet;
}

Since WinLose is 0 that means out bet lost so we subtract the stake from the bank to get a new value for the bank.


Line 11
else

This is where the program continues if the condition after IF was not true.


Line 12 – 14
{
Bank = (Bank - Bet) + (Bet * Odds);
}

Since WinLose was 0 this line is never executed. If you change the value of WinLose to 1 and compile and run the program again then this line will be executed. In this case we have a winning bet so we subtract the bet from the bank and then add the return from the bet back to the bank.


Line 15
System.out.println(Bank);

This line is the primary command for writing something to the screen and it prints the current contents of the bank.


Line 16 and 17
}
}
Note now the usage of brackets. When we as human beings read a text we depend on punctuation, comma's, capital letters, paragraphs to give us an indication of how we should read the text. In case of a computer program you must not give the computer an indication, you have to tell it EXACTLY how to read the text or in this case the program.

The opening bracket of the first line has a closing bracket on the last line. The opening bracket on the second line has a closing bracket on the last but one line. All the actions done when the condition after the IF statement is met are enclosed in a pair of brackets. Just like all the actions done after the else part are enclosed in brackets.

These brackets tell the computer how the program must be read. Round brackets are part of statements or are used to group operators. Pointed brackets group pieces of commands and statements so they are executed as a block.

To run this program create a new file in the C:\JAVA directory called Lesson2.java. Make sure you get the upper and lower case characters the same. The name of the program must be the same as the name on the first line of the program. Type the program in as above or copy and paste. Compile the program using this command C:\JAVA>JAVAC Lesson2.java and then run the program using C:\JAVA>JAVA Lesson2

When typed as above you should get 900 on your screen. Change the value of WinLose to anything but 0 and you should get 1200.

Downloading the program is possible here :
Lesson2.java



2.6 Using a program editor.

So far you have been using a simple text editor. And there is nothing wrong with that, but there are more specialised editors about. One is JCREATOR.

It can be downloaded for free from this site: www.jcreator.com
goto the site, click on download and select the second one called JCreator LE version
(the professional version you have to pay for)

I am not recommending this specific editor and there are others about just as good, maybe even better, but it works for me.

What a program editor does is make life a lot easier by helping out in the writing of the program. For example this editor displays different elements in the program in different colours. Or when you move the cursor to a start bracket like ( { [ it automatically highlights the corresponding ending bracket. Saves a lot of aggrevation and searching for simple typing errors. Just download it and have a look at the programs we’ve made so far.

Check out the basic functions like:
File - Open, File - Save,
Build – Compile, Build – Execute file.
The rest you can look at later, these will do for now. You can check out the rest of the gooddies later.

It's important to note here that later in the course you will need to be able to run Java programs from within a msdos box. So the editor does not replace that, it only adds to it.

2.7 Adding comments to your program.

The problems with computer programs is that when you want to change or expand them after a while, you usually haven't got a clue anymore what you where thinking when you wrote it in the first place. This is why we add comments and documentation all over the place. You can add a single line of comments by starting a line with 2 backslashes, like this:

// all of this is commenting on the program

Or you can add a whole block of comments like this:

/* starting to comment
*
* i could write my life story here
*
* end the block of comments on the next line
*/





Assignment 2.1 ( Lesson21.java )
Play about a bit with this program. See what happens if a bracket is missing. Try and add some calculations. Or change the IF condition.


Assignment 2.2 ( Lesson22.java )
Change the program so that when WinLose is 0 then Bet loses, when WinLose is 1 the bet wins but when WinLose is anything more than 1 the bet is void. And have it display the correct Bank.


Assignment 2.3 ( Lesson23.java )
Add a variable called Winnings. Calculate the winnings (or losses) and at the end of the program display the Bank and the amount lost or won.
Datapunter is offline  
Old 01-05-2004, 02:01   #2 (permalink)
agend
Guest
 
Posts: n/a
Default Lesson 2 - Language, a few calculations

Hi everybody - if you find the subject of Object Oriented Programming a little confusing (it really is) have a look at a great book about OOP and Java "Thinking in Java" by Bruce Eckel - it's available for free, and is really good. Good luck . Just visit : www.mindview.net/Books/TIJ/
 
Old 01-05-2004, 04:07   #3 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,330
Default Re: Lesson 2 - Language, a few calculations

Thanks agend, good tip.

Perhaps a note for the rookies here. Nobody, and i do mean NOBODY, has learnt Object Oriented Programming and Java overnight. If you get the general idea at this moment, thats fine. The details and specifics you'll pick up along the way. You will have to come back to the subject many more times before you really get it.
Datapunter is offline  
Old 07-05-2004, 16:21   #4 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,330
Default Re: Lesson 2 - Language, a few calculations

Assignment solutions :

Assignment 2.1 Lesson21.java

Assignment 2.2 Lesson22.java

Assignment 2.3 Lesson23.java

Click on the filename to open, or use the right-click and then Save Target As... to save the file on your PC.
Datapunter is offline  
Old 08-05-2004, 07:09   #5 (permalink)
Danish crap punter
 
cains's Avatar
 
Join Date: 26 Oct 2004
Location: Aarhus, DK
Age: 31
Posts: 725
Default lesson23

Hey...

The solution you have made for lesson23, When bets lose.. Then you first get 900, that it your bank now. And then you get 100, that is your winnings / lose...
Should that not be -100 instead???

I have made it like this instead:

public class Lesson2 {
public static void main(String[ ] arguments) {


int Bank = 1000;
int Bet = 100;
int Odds = 3;
int WinLose = 0;
int Winnings = 0;

if (WinLose == 0)
{
Bank = Bank - Bet;
}
else if (WinLose == 1)
{
Bank = (Bank - Bet) + (Bet * Odds);
}
System.out.println(Bank);
if (WinLose == 0)
{
Winnings = Winnings - Bet;
}
else if (WinLose == 1)
{
Winnings = (Bet * Odds) - Bet;
}
System.out.println(Winnings);
}
}

So it will show -100...

Was just wondering...

btw... sorry beeing so late out... Have been busy all week, so just started.. But i will try to catch up with the rest of you..

/ cains



Yes, you passed the test,
cains is offline  
Old 12-05-2004, 16:48   #6 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,330
Default Re: lesson23

Original question by Oddsfellow, moved here


Datapunter

I am afraid some of us are still on assignment 2.3 as i have not had much spare time of late. However i cannot seem to print out the Winnings. Could you possibly advise where i went wrong. I know the answers are there but i would just like to know what i did really. Heres my program


public class Lesson2 {
public static void main(String[ ] arguments) {

int Bank = 1000;
int Bet = 100;
int Odds = 3;
int WinLose = 0;
int Winnings = 0;

if (WinLose == 0)
{
Bank = Bank - Bet;
}
else
{
    if (WinLose== 1)
    {
    Bank = (Bank - Bet) + (Bet * Odds);
    }
    else
    {
    Bank = Bank;
    }
}

System.out.println(Bank);
if (WinLose == 0 )
{
Winnings = Winnings - Bet;
}
else
{
    if (WinLose ==1)
    {
    Winnings = (Bet * Odds) - Bet;
    }
    else
    {
    Winnings = Winnings;
    System.out.println(Winnings);
    }
}

} // this bracket is end of method main, see second line
} // this bracket is end of the program, see first line

Thanks


First a note on the brackets.
Java executes the parts after IF and ELSE that are enclosed in the brackets. We use the brackets to group the commands that are part of the IF or ELSE. Now in this case it is not neccesary since there is only one command done. In case of more than one command the brackets in bold should also be there.



lets look at the program from top to bottom
so in this case WinLose is 0,
in the first IF ELSE the part about the bank is done,
the part after the ELSE is skipped,
then we print the Bank,
so far so good,

in the second IF ELSE the first part is done,
winnings = winnings - bet
and then the part after ELSE is skipped.

as you can see, printing winnings on the screen is inside the ELSE part and is therefore not done. move it down one line and it will work.

Also the lines Bank = Bank; and Winnings = Winnings; do not do anything and can be removed. In fact the whole ELSE can be removed and the second IF can even be removed. Have left it for now so you can have a look. If the condition WinLose == 0 is not true then Java continues after ELSE, but you do not need to repeat checking the condition, thats already done.

So the ending becomes like this:


System.out.println(Bank);
if (WinLose == 0 )
{
Winnings = Winnings - Bet;
}
else
{
    if (WinLose ==1)
    {
    Winnings = (Bet * Odds) - Bet;
    }
    else
    {
    Winnings = Winnings;
    }
}
System.out.println(Winnings);
}
}



but this does the same:

System.out.println(Bank);
if (WinLose == 0 )
{
Winnings = Winnings - Bet;
}
else
{
Winnings = (Bet * Odds) - Bet;
}

System.out.println(Winnings);
}
}
Datapunter is offline  
Old 12-05-2004, 17:18   #7 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,330
Default Re: lesson23

Datapunter

Further to the above i have just tried your solution to 2.3 in JCreator, saved the file as c java\Lesson23, compiled it and then executed it but it to did not print the values on screen.



First, don't worry about where you are in the course, everybody does it in his own time, some fast and some take a bit longer. Doesn't matter.

The problem you had is simply a matter getting to know the language and learn how to think as a programmer. Perfectly normal.

Please check Lesson23.java again, just tried it and it showed 900 and 100 , did you get an error ? mail me.
Datapunter is offline  
Old 29-10-2004, 16:09   #8 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,330
Default Re: Lesson 2 - Language, a few calculations

empty post, done to re-order all the sticky topics.
Datapunter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts



All times are GMT. The time now is 09:59.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

Free £100 Bet!
Online Bookmakers
Free £100 Bet!

Recommended Bookies: Bet365 | BetDirect | | Blue Square | Canbet | Centrebet | Coral | Eurobet | Ladbrokes | Paddy Power | Party Bets | Pinnacle Sports | Skybet | SportingBet | Stan James | ToteSport | VCBet

Recommended Betting Exchanges: | Betfair | WBX

Recommended for Spread Betting: Sporting Index |
Partner Sites
Football Betting Tips Free Bets Australian Free Bets HOT Odds Comparison Soccer Punter
Bookmakers Livescore SoccerVista Asian Handicap Betting Guide

Contact Us | Disclaimer


© 2008 PuntersLounge.Com Ltd | Gambling Problems?

Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.