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, 21:27   #1 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,408
Default Lesson 3 - Language, a bit more about objects

Lesson 3 ( Word document )

Punters Lounge JAVA programming course.
Lesson 3 - Learning the language, a bit more about objects.

3.1 Scoreboard object

Imagine a scoreboard as an object. In our case let's take a football scoreboard. It can contain 2 values being the score for each team. Its declaration looks like this:

File: Scoreboard.java

public class Scoreboard {
    public int home = 0;
    public int away = 0;

    public Scoreboard(int home, int away)
    {
      this.home = home;
      this.away = away;
    }
}


Now in our program we can use this line to create a scoreboard object:

Scoreboard Localgame = new Scoreboard(0,0);

This line consists of 3 parts: Declaration, Instantiation and Initialisation.

Scoreboard Localgame is the declaration telling Java that the name Localgame is going to be used for an object of the type Scoreboard. That's all, you tell Java that you intend to use that name for that type of object.

new Scoreboard will actually create an object of the type Scoreboard. So the new command will take the class Scoreboard as example or template and from that create a new object of the type Scoreboard.

Scoreboard(0,0) is a call to a constructor inside the object Scoreboard. In the above code it's the last 3 lines. This will initialise the newly formed object and set its initial values to 0.


So the line Scoreboard Localgame = new Scoreboard(0,0); creates a new object of the type Scoreboard gives it the name Localgame and sets its initial values to 0.

3.2 Scoreboard object, state

How do we get at an object values or state ? By calling it by name like this:

Localgame.home and Localgame.away

This way we use the object Localgame and inside that object the integers home and away.


Let's put this in a program. First you need a file called Scoreboard.java containing the above code. That is the program or class for a scoreboard object. Then we create our program called Lesson3.java. When we compile and run our program Lesson3.java Java will recognise that Scoreboard is used and automatically include that in the overall compilation. So the only thing we need to do to compile is: CJAVA>JAVAC Lesson3.java
(Remember there is a difference between upper/lower case characters!)


File Lesson3.java

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

    Scoreboard Localgame = new Scoreboard(0,0);

    System.out.println(Localgame.home);
    System.out.println(Localgame.away);
}
}


When we run our second program it displays 0 twice.
During the course of our program we can set the values of our scoreboard like this:

Localgame.home = 1;
Localgame.away = 2;


Full program becomes:

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

    Scoreboard Localgame = new Scoreboard(0,0);

    Localgame.home = 1;
    Localgame.away = 2;

    System.out.println(Localgame.home);
    System.out.println(Localgame.away);
}
}


When we now run the program it will display a 1 and 2.


3.3 Scoreboard object, method

Now let's include a method. Suppose we want our scoreboard to tell us the total number of goals scored. The Scoreboard class becomes this:

File: Scoreboard.java

public class Scoreboard {
    public int home = 0;
    public int away = 0;

    public Scoreboard(int home, int away)
    {
      this.home = home;
      this.away = away;
    }

    public int goals()
    {
      return home + away;
    }
}


The method adds the value of home and away and returns this to the calling program as an integer value.

public int goals()

declares the method named goals and tells the compiler it will return a value of the type int. The brackets are empty but required. We'll come to that later.

return home + away;

This will execute the + operator adding the values of home and away and the return statement will return the result to the calling program.

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

    Scoreboard Localgame = new Scoreboard(0,0);

    Localgame.home = 1;
    Localgame.away = 2;

    System.out.println(Localgame.home);
    System.out.println(Localgame.away);

    System.out.println(Localgame.goals());
}
}



Will display 1, 2 and 3 as values.


3.4 Printing text to the screen

Later in the course we will look at text. For now here's how to display text on the screen:

System.out.println("This is text");

Normally you cannot combine integers and text. You can however combine integers and text using the System.out.println method. It will recognise both and handle them separately. Like this:

System.out.println("Home team goals : " + Localgame.home);

Will display following text on the screen:

Home team goals : 1






Assignment 3.1 ( Lesson31.java )
Modify the Lesson3 so it displays Under or Over based on the value of the number of goals.


Assignment 3.2 ( Lesson32.java )
Modify the Lesson3 so it displays the words Home win or Away win or Draw game based on the values of the scoreboard.


Assignment 3.3 ( Lesson33.java )
Tkae the previous program and make it look at bit nicer, like this:
Today's game ended in a Home Win with a total of 3 goals scored
Make sure that when you change only the score at the beginning of the program, like 0 - 0 it displays the change at the end:
Today's game ended in a Draw with 0 goals for each team


Assignment 3.4 ( Lesson34.java )
Combine the Lesson2 and the Lesson3 programs into Lesson34 such that a Home win will be a winning bet and an Away win or Draw is a losing bet.

So a draw score displays: Draw game , bank = 900
And an Away win display: Away win , bank = 900
And a home win displays: Home win , bank = 1200

So the end result looks like this for a 1 - 0 Home win:
1
0
Today's game ended in a Home Win with a total of 1 goals scored
Home win , Bank = 1200
Datapunter is offline  
Old 02-05-2004, 17:15   #2 (permalink)
Muppet Punter
 
muppet77's Avatar
 
Join Date: 26 Oct 2004
Posts: 1,935
Default Lesson 3 - Language, a bit more about objects

datapunter - what's the edit you made?


I'm using html in these posts to get all the indenting right, but thats a monks work, so easy to make a little mistake, nobody noticed then thought i got away with that one

This was wrong,

public class Scoreboard {
    public int home = 0;
    public int away = 0;

    public Scoreboard(int home, int away)
    {
      this.home = home;
      this.away = away;

    .................................................. .... <-- closing bracket is missing

    public int goals()
    {
      return home + away;
    } .................................................. .... <-- closing bracket is in wrong place
    }
}


This is right,
public class Scoreboard {
    public int home = 0;
    public int away = 0;

    public Scoreboard(int home, int away)
    {
      this.home = home;
      this.away = away;
    }

    public int goals()
    {
      return home + away;
    }
}
muppet77 is offline  
Old 07-05-2004, 16:24   #3 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,408
Default Re: Lesson 3 - Language, a bit more about objects

Assignment solutions :

Assignment 3.1 Lesson31.java

Assignment 3.2 Lesson32.java

Assignment 3.3 Lesson33.java

Assignment 3.4 Lesson34.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 29-10-2004, 16:07   #4 (permalink)
Pro Punter
 
Datapunter's Avatar
 
Join Date: 23 Oct 2003
Location: Westdorpe
Age: 43
Posts: 5,408
Default Re: Lesson 3 - Language, a bit more about objects

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 04:27.


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.