OOP Demo-in-progress

I’m including an example of an OOP demonstration in progress with the idea of getting feedback from people who are using this tutorial.  I’m still new to OOP in Java and I’d appreciate feedback from tutorial users.

I have adapted some code that I found on the web that I understood and I was able to create an Ahthete class that would return assessment of performance based on user input:

// All comments for this class have been removed

class Athlete {

String owner;

String accountNumber;

double balance;

double h,ab;   // hits and atbats

double ba;     // batting average

double ga,gp; // goals against / games played

double gaa;  //goals against average

double plusminus;

double gf;  //goals for

// Method for calculating a batting average

void batave(double h,double ab){

ba=(h / ab);

}

double getBatAve(){

return(ba);

}

// Method for calcualting a goaltender's average

void goalieavg(double ga, double gp){

gaa=(ga / gp);

}

double getGoalieAve(){

return(gaa);

}

// Method for calcualting a hockey defenseman's +-

void calcplusminus(double gf, double ga){

plusminus = gf - ga;

}

double getPlusMinus(){

return(plusminus);

}

double getBalance(){

return(balance);

}

void setOwner(String o){

owner=o;

}

String getOwner(){

return(owner);

}

void setAccountNumber(String a){

accountNumber=a;

}

String getAccountNumber(){

return(accountNumber);

}

}

Next, I created a UseAthlete.class that would generate output depending on user input:

import java.text.DecimalFormat;

import java.util.Locale;

// We create and use instances of the Account class here

class UseAthlete {

public static void main(String [] args){

// So far no instances of Athlete exist,

// we create a reference to the class Athlete.

// This can be used to hold the address of an Athlete

Athlete batter;

// No athlete exists yet

Athlete goalie;

// Still no Athlete exists yet

Athlete defenseman;

// The following creates a new Athlete, but there is no

// way to use it!!

new Athlete();

// Create a new Athlete and give its address to the

// reference chequeing

batter=new Athlete();

goalie=new Athlete();

defenseman=new Athlete();

batter.batave(5,10);

System.out.println(batter.getBatAve());

// had to import libraries above to get formatting to work

DecimalFormat fmt = new DecimalFormat("0.000");

System.out.println("\n Batting Average " + fmt.format(batter.getBatAve()));

batter.batave(9,13);

System.out.println(batter.getBatAve());

goalie.goalieavg(13,8);

System.out.println(goalie.getGoalieAve());

defenseman.calcplusminus(9,13);

System.out.println(defenseman.getPlusMinus());

}

}

The original code involved a Bank Account class that included methods for deposit, withdraw and so on.  I found the code very helpful, however, I’m not certain that this is an example of true OOD.   It would probably be a good idea to create a discussion on OOD and share project ideas…….