Computer science homework
package.bluej
#BlueJ package file objectbench.height=76 objectbench.width=657 package.editor.height=427 package.editor.width=559 package.editor.x=39 package.editor.y=155 package.numDependencies=0 package.numTargets=1 package.showExtends=true package.showUses=true project.charset=UTF-8 target1.editor.height=700 target1.editor.width=1075 target1.editor.x=175 target1.editor.y=86 target1.height=50 target1.name=SportsTeam target1.naviview.expanded=true target1.showInterface=false target1.type=ClassTarget target1.typeParameters= target1.width=90 target1.x=70 target1.y=10
__MACOSX/._package.bluej
README.TXT
------------------------------------------------------------------------ This is the project README file. Here, you should describe your project. Tell the reader (someone who does not know anything about this project) all he/she needs to know. The comments should usually include at least: ------------------------------------------------------------------------ PROJECT TITLE: PURPOSE OF PROJECT: VERSION or DATE: HOW TO START THIS PROJECT: AUTHORS: USER INSTRUCTIONS:
__MACOSX/._README.TXT
SportsTeam.class
public synchronized class SportsTeam { private java.util.Vector opponent; private java.util.Vector home; private java.util.Vector teamPoints; private java.util.Vector oppPoints; private String teamName; private String sportName; public void SportsTeam(); public void changeSport(String); public void changeName(String); public void addGame(String, boolean, int, int); public void updateGame(int, String, boolean, int, int); public double getWinLoss(boolean); public void displayRecord(); public void addRandomGames(int, int); }
__MACOSX/._SportsTeam.class
SportsTeam.ctxt
#BlueJ class context comment0.params= comment0.target=SportsTeam() comment0.text=\r\n\ Constructor\ for\ objects\ of\ class\ SportsTeam\r\n comment1.params=newSport comment1.target=void\ changeSport(java.lang.String) comment1.text=\r\n\ Method\ to\ change\ sport.\ \r\n comment2.params=newName comment2.target=void\ changeName(java.lang.String) comment2.text=\r\n\ Method\ to\ change\ team\ name.\ \r\n comment3.params=otherTeam\ homeGame\ ourPoints\ theirPoints comment3.target=void\ addGame(java.lang.String,\ boolean,\ int,\ int) comment3.text=\r\n\ Method\ to\ add\ a\ new\ game.\ Attempts\ to\ add\ a\ game\ with\ either\ score\ negative\r\n\ should\ be\ rejected\ with\ an\ error\ message\ in\ the\ terminal\ wondow.\r\n comment4.params=position\ otherTeam\ homeGame\ ourPoints\ theirPoints comment4.target=void\ updateGame(int,\ java.lang.String,\ boolean,\ int,\ int) comment4.text=\r\n\ Method\ to\ update\ data\ for\ a\ game\ that\ wwas\ entered\ in\ error.\ The\ game\ data\ at\ the\ position\r\n\ provided\ will\ be\ replaced\ with\ the\ data\ provided.\ Aagin,\ negative\ scores\ should\ be\ rjected\ \r\n\ with\ an\ error\ message,\ as\ should\ any\ invalid\ position.\r\n comment5.params=printRequested comment5.target=double\ getWinLoss(boolean) comment5.text=\r\n\ When\ this\ method\ is\ called,\ the\ win/loss\ poercentage\ for\ the\ team\ will\ always\ be\ computed\ \r\n\ and\ returned.\r\n\ \r\n\ In\ addition,\ if\ the\ printRequested\ parameter\ is\ true,\ team's\ overall\ win-loss\ record\ \r\n\ should\ be\ displayed\ in\ the\ terminal\ window\ in\ the\ following\ format\:\ \r\n\ \ \ \ \ \ \ Win-Loss\ Record\:\ games_won-games_lost\ (%\ won)\r\n\ \ \ \ \ \ \ \r\n\ \ Example\:\r\n\ \ \ \ \ \ \ Win-Loss\ Record\:\ 38-26\ (59.375%)\r\n comment6.params= comment6.target=void\ displayRecord() comment6.text=\r\n\ Dpisplay\ the\ team's\ current\ record,\ one\ line\ per\ game.\ Each\ line\ should\ begin\ with\ four\r\n\ spaces,\ then\ display\ the\ following\:\ the\ game\ number\ followed\ by\ a\ colon,\ the\ opposing\ \r\n\ team\ name\ (with\ "@"\ proceeding\ the\ name\ for\ away\ games),\ "W"\ or\ "L"\ indicating\ win\ or\ \r\n\ loss,\ and\ the\ score\ of\ each\ team,\ separated\ by\ a\ hyphen.\ NOTE\:\ The\ home\ team\ score\ is\ \r\n\ always\ dosplayed\ last.\ After\ all\ games\ are\ displayed,\ the\ win-loss\ record\ should\ be\ \r\n\ displayed.\ (Call\ the\ method\ above\ to\ include\ this.)\r\n\ \r\n\ Here\ is\ an\ example\:\r\n\ \r\n\ Record\ for\ the\ Greens\ baseball\ team\:\r\n\ \ \ \ \ 0\:\ @Flyers\ L\ 5-7\r\n\ \ \ \ \ 1\:\ Raiders\ W\ 2-7\r\n\ \ \ \ \ 2\:\ Vikings\ W\ 5-6\r\n\ \ \ \ \ 3\:\ @Cardinals\ W\ 5-3\r\n\ \ \ \ \ Win-loss\ Record\:\ 3-1\ (75.0%)\r\n\ \r\n comment7.params=numGames\ maxScore comment7.target=void\ addRandomGames(int,\ int) comment7.text=\r\n\ Create\ ramdom\ simulated\ game\ data\ for\ the\ team.\ Parameters\ are\ used\ to\ specify\ the\ nuimber\r\n\ of\ games\ to\ generate\ and\ the\ maximum\ score\ expected\ in\ each\ game\ (as\ this\ would\ vary\ by\r\n\ sport.\r\n numComments=8
__MACOSX/._SportsTeam.ctxt
SportsTeam.java
SportsTeam.java
import
java
.
util
.
*
;
/**
* A SportsTeam object will track the record of a sports team, using several "paralell
* vectors". For each of these vectors, position i will contain the information for
* the ith game played by the team. Those vectors are:
*
* opponent - Contains the name of the opposing team.
* home - Is true if the game is a home game, false if the game is an away game.
* teamPoints - The number of points acored by the team.
* oppPoints - The number of points scored by the opposing team.
*
*
@author
(your name)
*
@version
(a version number or a date)
*/
public
class
SportsTeam
{
// These vectors will be used to track games. For each, position i will contain
// the information for game i;
private
Vector
<
String
>
opponent
;
private
Vector
<
Boolean
>
home
;
private
Vector
<
Integer
>
teamPoints
;
private
Vector
<
Integer
>
oppPoints
;
// Fields to hold name of team and sport.
private
String
teamName
;
private
String
sportName
;
/**
* Constructor for objects of class SportsTeam
*/
public
SportsTeam
()
{
// Create all the vectors.
opponent
=
new
Vector
<
String
>
();
home
=
new
Vector
<
Boolean
>
();
teamPoints
=
new
Vector
<
Integer
>
();
oppPoints
=
new
Vector
<
Integer
>
();
// Default team name and sport.
teamName
=
"Greens"
;
sportName
=
"baseball"
;
}
/**
* Method to change sport.
*/
public
void
changeSport
(
String
newSport
)
{
// Your code goes here.
}
/**
* Method to change team name.
*/
public
void
changeName
(
String
newName
)
{
// Your code goes here.
}
/**
* Method to add a new game. Attempts to add a game with either score negative
* should be rejected with an error message in the terminal wondow.
*/
public
void
addGame
(
String
otherTeam
,
boolean
homeGame
,
int
ourPoints
,
int
theirPoints
)
{
// Your code goes here.
}
/**
* Method to update data for a game that wwas entered in error. The game data at the position
* provided will be replaced with the data provided. Aagin, negative scores should be rjected
* with an error message, as should any invalid position.
*/
public
void
updateGame
(
int
position
,
String
otherTeam
,
boolean
homeGame
,
int
ourPoints
,
int
theirPoints
)
{
// Your code goes here.
}
/**
* When this method is called, the win/loss poercentage for the team will always be computed
* and returned.
*
* In addition, if the printRequested parameter is true, team's overall win-loss record
* should be displayed in the terminal window in the following format:
* Win-Loss Record: games_won-games_lost (% won)
*
* Example:
* Win-Loss Record: 38-26 (59.375%)
*/
public
double
getWinLoss
(
boolean
printRequested
)
{
// Your code goes here. (The line below will be replaced.)
return
0.0
;
}
/*
* Dpisplay the team's current record, one line per game. Each line should begin with four
* spaces, then display the following: the game number followed by a colon, the opposing
* team name (with "@" proceeding the name for away games), "W" or "L" indicating win or
* loss, and the score of each team, separated by a hyphen. NOTE: The home team score is
* always dosplayed last. After all games are displayed, the win-loss record should be
* displayed. (Call the method above to include this.)
*
* Here is an example:
*
* Record for the Greens baseball team:
* 0: @Flyers L 5-7
* 1: Raiders W 2-7
* 2: Vikings W 5-6
* 3: @Cardinals W 5-3
* Win-loss Record: 3-1 (75.0%)
*
*/
public
void
displayRecord
()
{
// Display heading.
System
.
out
.
println
(
"Record for the "
+
teamName
+
" "
+
sportName
+
" team:"
);
// Your code goes here.
}
/**
* Create ramdom simulated game data for the team. Parameters are used to specify the nuimber
* of games to generate and the maximum score expected in each game (as this would vary by
* sport.
*/
public
void
addRandomGames
(
int
numGames
,
int
maxScore
)
{
String
[]
teams
=
{
"Flyers"
,
"Raiders"
,
"Vikings"
,
"Cardinals"
};
boolean
[]
trueFalse
=
{
true
,
false
};
int
i
,
pos1
,
pos2
,
score1
,
score2
;
System
.
out
.
println
(
"Adding the following games:"
);
for
(
i
=
0
;
i
<
numGames
;
i
++
)
{
pos1
=
(
int
)(
Math
.
random
()
*
4
);
pos2
=
(
int
)(
Math
.
random
()
*
2
);
score1
=
(
int
)(
Math
.
random
()
*
(
maxScore
+
1
));
score2
=
score1
;
while
(
score2
==
score1
)
score2
=
(
int
)(
Math
.
random
()
*
(
maxScore
+
1
));
System
.
out
.
println
(
" "
+
teams
[
pos1
]
+
" "
+
trueFalse
[
pos2
]
+
" "
+
score1
+
" "
+
score2
);
addGame
(
teams
[
pos1
],
trueFalse
[
pos2
],
score1
,
score2
);
}
}
}