联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-11-01 09:57

WESTERN UNIVERSITY - CANADA

FACULTY OF ENGINEERING,

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

SE 2203A – SOFTWARE DESIGN

Laboratory 5: Databases

Due Date: November 2, 2018

For these exercises, no need to physically attend the lab, but If you get stuck on something in the

following lab requirements, you should ask your TA in person during the designated lab hours in

Three C+ 4440. The designated lab hours are mentioned in the Lab schedule document in OWL.

1 Goal

Be able to write SQL statements.

Be able to add and retrieve information from a database.

Be able to change information in multiple tables of the database.

2 Introduction

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

you to write a 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. Complete the tasks below to enable all the functionality that is required for this

application.

3 Directed Lab Work

3.1 Task 1: Database Connection and Initialization

Download the Lab5.zip from OWL. Unzip Lab5.zip into

a new folder “Lab5”. Open IntelliJ IDE and import the

given Java project from this new folder. Follow the screen

instructions and select the default options until the

project is created.

If it is not there already, add the required JAR files. Use

File?Project Structure then choose Library from the

right-side panel. Click the plus symbol and choose Java

option to open a file browser.

Browse to the DB folder in your JDK, for example “C:\Program Files\Java\jdk1.8.0_73\db\lib”. Choose

“derby.jar” and Click Ok, and then click Ok to be added into your project file,

then Click apply.

Create and initialize the database by running the program and selecting Menu

Item “Begin New Session”.

Figure 1

Figure 2

SE 2203a – Software Design Laboratory 5

Abdelkader Ouda page 2 Fall 2018

The following alert window should display.

If, at any point after the initialization, you wish to start over, you can select “Begin New Session”, which will

remove the database tables and recreate and initialize them.

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

The Games table created an initialized in the database is as follows:

Now, your task is to explore the given Java code and understand the code style, the purpose of the defined

field, and the usages of the given methods. This is a very important step that will help you to complete the

rest of tasks in this lab and finishing the programming part of the coming assignments successfully.

3.2 Task 2: Retrieve Information Using SQL

Select the Menu Item View Teams Standings.

Your output should be as follows:

GameNumber HomeTeam HomeTeamScore VisitorTeam VisitorTeamScore

1 Astros 0 Brewers 0

2 Brewers 0 Cubs 0

3 Cubs 0 Astros 0

SE 2203a – Software Design Laboratory 5

Abdelkader Ouda page 3 Fall 2018

Write the implementation for the getMatchesList() method in MatchesAdapter.java

1. Write an SQL statement to select all columns from the Matches table.

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

3. Use a while loop to add the contents of the result set to matchesList.

4. Compile and run the program. Select the Menu Item View ? Matches.

5. Your output should be as follows:

3.3 Task 3: Add Information Using SQL

Click Add Team menu option, and add a new team “Braves” and

then click Save.

Check whether this team is added to the database. Click View ?

Teams Standings. Braves team should be added to the list.

Develop a new form to add a new Match information:

1. Right-Click the TennisBallGames package to create a new

Empty FXML java class named it AddMatch.fxml.

2. Right-Click the TennisBallGames package again to create a

new Java class (a controller to your fxml)

file and named it AddMatchController.

3. Using Scene Builder open

AddMatch.fxml and make your form to

have three Labels, two ComboBox

controls, and two buttons as follows:

SE 2203a – Software Design Laboratory 5

Abdelkader Ouda page 4 Fall 2018

4. Write the body of the AddMatchController class, add all methods needed to read the two teams

names from the existing names in the Teams table using the two ComboBox controls and then save

a new record in the Matches table.

5. Hint: You may use the below code skeleton to build your AddMatchController class or build your

own code:

package TennisBallGames;

// import the required libraries

public class AddMatchController implements Initializable {

// Some @FXML declarations

// Some local variable declarations

// The data variable is used to populate the ComboBoxs

final ObservableList<String> data = FXCollections.observableArrayList();

// To reference the models inside the controller

private MatchesAdapter matchesAdapter;

private TeamsAdapter teamsAdapter;

public void setModel(MatchesAdapter match, TeamsAdapter team) {

matchesAdapter = match;

teamsAdapter = team;

buildComboBoxData();

}

@FXML

public void cancel() {

Stage stage = (Stage) cancelBtn.getScene().getWindow();

stage.close();

}

@FXML

public void save() {

// Do some work here

}

public void buildComboBoxData() {

try {

data.addAll(teamsAdapter.getTeamsNames());

} catch (SQLException ex) {

displayAlert("ERROR: " + ex.getMessage());

}

}

@Override

public void initialize(URL url, ResourceBundle rb) {

homeTeamBox.setItems(data);

visitorTeamBox.setItems(data);

}

}

6. Note that, the matchNumber is a serial number generated automatically and equal to the maximum

match number in the table plus one. Hint, you need to write a new method in the MatchesAdapter

class (you may name it getMax() that you will invoke from the AddMatchController class to

generate the serial number, it uses the SQL command: SELECT MAX(MatchNumber) FROM

Matches

7. Write the getTeamsNames() method in the TeamAdapter class.

SE 2203a – Software Design Laboratory 5

Abdelkader Ouda page 5 Fall 2018

8. Uncomment the code of the method addMatch() n the MainFormController.java. Compile and run

the program. Add a match between “Braves” and “Cubs” and then show the list of matches from the

menu View ? Matches. Your output should now look like:

3.4 Task 4: Change Information in Multiple Tables Using SQL

Develop a new form to add a match score information:

1. Create a new Empty FXML java class in the package TennisBallGames and named it

AddScore.fxml.

2. Make sure to create a controller to your fxml file and named it AddScoreController.

3. Using Scene Builder open AddMatch.fxml and generate your form to have four Labels, one

ComboBox, two TextFields, and two buttons as follows.

4. Write the AddScoreController class to do the following:

Define all necessary @FXML variables and methods

Reference to the matchAdapter and teamAdapter classes and write the setModel method as

we did in the previous task.

Write the save method that get the match number, home team name, and visitor team name

from the selected value of the comboBox field, then call both the

matchesAdapter.setTeamsScore and teamsAdapter.setStatus methods.

Close the stage.

SE 2203a – Software Design Laboratory 5

Abdelkader Ouda page 6 Fall 2018

5. Write the setTeamsScore in the MatchesAdapter class that execute updates to the Matches table

using the appropriate SQL statements.

6. Write the setStatus in the TeamsAdapter class that will have the logic to determine whether the team

is 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.

7. Uncomment the code of the method addScore() n the MainFormController.java. Compile and run

the program. Add the following match score using the menu option Add ? Score.

GameNumber HomeTeam HomeTeamScore VisitorTeam VisitorTeamScore

1 Astros 5 Brewers 3

2 Brewers 4 Cubs 4

3 Cubs 1 Astros 6

8. Select the menu option View Teams Standings to view the team standings and the menu option

View Matches to see the scores. Your output should now be:

Notice: If you are unable to get this exercise run successfully, you should talk to lab hours).

4 Hand In

From the IntelliJ main menu, select File? Export to Zip File…, the Save as pop-up window appears,

click OK to save your project as yourUwoId_Lab5.zip. For example, if yourUWOId is aouda then name the

archive file as aouda_Lab5.zip.

Submit your zip file through OWL by the due date mentioned above, to be graded out of 20


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp