Help on a simple example?
Hi,
I am trying to get my head around java (well actually programming in general) and wondered if anyone could help with a fairly simple example. This isn't 'homework' - this is just something I'm interested in and want to learn. The problem I find is so many examples on the net are just so complicated, I try and follow it but get lost.
I am wanting to create a a dead simple football text based game (on the lines of championship manager but a lot simpler!)
For now I just want to get the code started really.
This code is entirely untested as this has been done at work without a compiler, but can anyone help me out with my question below this code?
Player.java
import java.io.*;
import javax.swing.*;
class Player
{
private String name ="David Healy";
privateint speed = 10;
privateint shooting = 15;
//etc etc I understand that if I add more instance variables they would go below as well in the constructor.
public Player ( String name,int speed,int shooting)
this.name = name;
this.speed = speed;
this.shooting = shooting;
}
public Player ()
{
}
publicvoid getName()
{
return name;
}
publicvoid getSpeed()
{
return speed;
}
publicvoid getShooting()
{
return shooting;
}
Game.java
import java.io.*;
import javax.swing.*;
publicclass Game
{
publicstaticvoid main(String[] args)throws IOException
{
Player p1 =new Player();
p1.getName();
p1.getSpeed();
p1.getShooting();
System.exit(1);
}
}
Now my question is - I want to make this so that instead of me actually setting the instance variables to a name, a text file could do it for me. In the form of:
David Healy
10
12
John Smith
12
12
etc.
Can anyone help? All I want at this time is to be able to print each players details. Eventually I want to assign them to teams but will add this in later
Thank you
Andrew
Message was edited by:
andrewsco1

