Listing 1. The Sports base class.
import java.text.DecimalFormat;
public class Sports {
private String team;
private int win;
private int loss;
private int tie;
private double pct;
public Sports() {
setTeam("Team");
setWin(0);
setLoss(0);
setTie(0);
setPct(0,0,0);
}
public Sports(String team,int win,int loss,int tie) {
setTeam(team);
setWin(win);
setLoss(loss);
setTie(tie);
setPct(win,loss,tie);
}
public String getTeam() {
return team;
}
public void setTeam(String team) {
this.team = team;
}
public int getWin() {
return win;
}
public void setWin(int win) {
this.win = win;
}
public int getLoss() {
return loss;
}
public void setLoss(int loss) {
this.loss = loss;
}
public int getTie() {
return tie;
}
public void setTie(int tie) {
this.tie = tie;
}
public double getPct() {
return pct;
}
public void setPct(int win,int loss,int tie) {
if(win == 0 && loss == 0) {
this.pct = 0.0;
}
else {
this.pct = (double)win /
((double)win + (double)loss + (double)tie);
}
}
public String toString() {
DecimalFormat df = new DecimalFormat("0.000");
return String.format("%-25s",getTeam())
+ String.format("%5d",getWin())
+ String.format("%5d",getLoss())
+ String.format("%5d",getTie()) + "\t"
+ df.format(getPct());
}
}
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.