Loading

Java - CIS111 Lab 16 Task #1 Database connection and initialization Copy the file TeamDB.java A recreation director needs to keep track of summer T-ball teams, games, and season records

Availability: In stock

Regular Price: $35.00

Special Price: $21.00

Already Bought 4 times.

Java - CIS111 Lab 16 Task #1 Database connection and initialization Copy the file TeamDB.java A recreation director needs to keep track of summer T-ball teams, games, and season records

Double click on above image to view full picture

Zoom Out
Zoom In

More Views

Quick Overview

A recreation director needs to keep track of summer T-ball teams, games, and season records. He


has hired you to write an computer program to make his life easier. You have created a menu


driven program that allows the director to use a database to easily manipulate teams, games, and


scores. It also allows the database to be refreshed for a new year.


 


Task #1 Database connection and initialization


1. Copy the file TeamDB.java (see code listing 16.1) from the Student CD or as


directed by your instructor.


2. Modify the DRIVER and DB_URL constants at the beginning of the main method


as directed by your instructor to connect with your database correctly.


3. Create and initialize the database by running the program and selecting option 6.


4. If at any point after the initialization, you wish to start over, you can select option


6, which will remove the database tables and recreate and initialize them.


5. The Teams table created and initialized in the database is as follows


 


TeamName Wins Losses Ties


Astros 0 0 0


Brewers 0 0 0


Cubs 0 0 0


Marlins 0 0 0


 


6. The Games table created and initialized in the database is as follows:


GameNumber HomeTeam HomeTeamScore VisitorTeam VisitorTeamScore


1 Astros 0 Brewers 0


2 Brewers 0 Cubs 0


3 Cubs 0 Astros 0


 


Task #2 Retrieve information using SQL


1. Select option 1 to view the teams. Your output should be as follows:


Team Name Win Lose Tie


Astros 0 0 0


Brewers 0 0 0


Cubs 0 0 0


Marlins 0 0 0


2. Write the implementation for the viewSchedule method.


a. Write an SQL statement to select all columns from the Games table.


b. Execute the query by sending the SQL statement to the DBMS.


c. Use a while loop to display the contents of the result set to the monitor.


d. Compile and run the program. Select option 2 and your output should be


as follows:


GameID Home Score Visitor Score


1 Astros 0 Brewers 0


2 Brewers 0 Cubs 0


3 Cubs 0 Astros 0


 


 


Task #3 Add information using SQL


1. Write the body of the loop in the addTeams method. You should prompt the user


for the new team name, write the SQL statement and update the Teams table with


the new team name.


2. Compile and run the program. Select option 3 and enter Braves. Enter N to stop


entering names. Select option 1 again to view the teams. Your output should


now look like:


Team Name Win Lose Tie


Astros 0 0 0


Braves 0 0 0


Brewers 0 0 0


Cubs 0 0 0


Marlins 0 0 0


 


Task #4 Change information in multiple tables using SQL


1. Edit the enterScores method. Execute a query using the appropriate SQL


statement to get the result set containing all information for the gameNumber the


user entered.


2. After the user inputs the scores for both teams, execute updates to the Games


table using the appropriate SQL statements.


3. In each branch of the logic determining winner, loser or tie: retrieve the number


from the appropriate column (losses, wins, or ties) from the Teams table for one


of the teams, increment it, and update the table for that team. Do the same for the


opposing team.


4. Select option 5 to enter scores. Enter scores as follows:


Game 1 Astros 5 Brewers 3


Game 2 Brewers 4 Cubs 4


Game 3 Cubs 1 Astros 6


5. Select option 1 to view the team standings and option 2 to see the scores. Your


output should now be


Team Name Win Lose Tie


Astros 2 0 0


Braves 0 0 0


Brewers 0 1 1


Cubs 0 1 1


Marlins 0 0 0


List of games and scores:


GameID Home Score Visitor Score


1 Astros 5 Brewers 3


2 Brewers 4 Cubs 4


3 Cubs 1 Astros 6

Regular Price: $35.00

Special Price: $21.00

Details

A recreation director needs to keep track of summer T-ball teams, games, and season records. He

has hired you to write an computer program to make his life easier. You have created a menu

driven program that allows the director to use a database to easily manipulate teams, games, and

scores. It also allows the database to be refreshed for a new year.

 

Task #1 Database connection and initialization

1. Copy the file TeamDB.java (see code listing 16.1) from the Student CD or as

directed by your instructor.

2. Modify the DRIVER and DB_URL constants at the beginning of the main method

as directed by your instructor to connect with your database correctly.

3. Create and initialize the database by running the program and selecting option 6.

4. If at any point after the initialization, you wish to start over, you can select option

6, which will remove the database tables and recreate and initialize them.

5. The Teams table created and initialized in the database is as follows

 

TeamName Wins Losses Ties

Astros 0 0 0

Brewers 0 0 0

Cubs 0 0 0

Marlins 0 0 0

 

6. The Games table created and initialized in the database is as follows:

GameNumber HomeTeam HomeTeamScore VisitorTeam VisitorTeamScore

1 Astros 0 Brewers 0

2 Brewers 0 Cubs 0

3 Cubs 0 Astros 0

 

Task #2 Retrieve information using SQL

1. Select option 1 to view the teams. Your output should be as follows:

Team Name Win Lose Tie

Astros 0 0 0

Brewers 0 0 0

Cubs 0 0 0

Marlins 0 0 0

2. Write the implementation for the viewSchedule method.

a. Write an SQL statement to select all columns from the Games table.

b. Execute the query by sending the SQL statement to the DBMS.

c. Use a while loop to display the contents of the result set to the monitor.

d. Compile and run the program. Select option 2 and your output should be

as follows:

GameID Home Score Visitor Score

1 Astros 0 Brewers 0

2 Brewers 0 Cubs 0

3 Cubs 0 Astros 0

 

 

Task #3 Add information using SQL

1. Write the body of the loop in the addTeams method. You should prompt the user

for the new team name, write the SQL statement and update the Teams table with

the new team name.

2. Compile and run the program. Select option 3 and enter Braves. Enter N to stop

entering names. Select option 1 again to view the teams. Your output should

now look like:

Team Name Win Lose Tie

Astros 0 0 0

Braves 0 0 0

Brewers 0 0 0

Cubs 0 0 0

Marlins 0 0 0

 

Task #4 Change information in multiple tables using SQL

1. Edit the enterScores method. Execute a query using the appropriate SQL

statement to get the result set containing all information for the gameNumber the

user entered.

2. After the user inputs the scores for both teams, execute updates to the Games

table using the appropriate SQL statements.

3. In each branch of the logic determining winner, loser or tie: retrieve the number

from the appropriate column (losses, wins, or ties) from the Teams table for one

of the teams, increment it, and update the table for that team. Do the same for the

opposing team.

4. Select option 5 to enter scores. Enter scores as follows:

Game 1 Astros 5 Brewers 3

Game 2 Brewers 4 Cubs 4

Game 3 Cubs 1 Astros 6

5. Select option 1 to view the team standings and option 2 to see the scores. Your

output should now be

Team Name Win Lose Tie

Astros 2 0 0

Braves 0 0 0

Brewers 0 1 1

Cubs 0 1 1

Marlins 0 0 0

List of games and scores:

GameID Home Score Visitor Score

1 Astros 5 Brewers 3

2 Brewers 4 Cubs 4

3 Cubs 1 Astros 6

Additional Information

Programming Language Java

Product Tags

Use spaces to separate tags. Use single quotes (') for phrases.