JPQL/ JPA Activity 3

3
Data Aware and SQL Test Sample Questions Information Technology Grade 12 SECTION A - JAVA In this section, you will be working with the project PetAppDemoProject. A backup project is also provided in the zBackup folder. Note that you will be a missing resource (derby.jar) error at the start. This error does not need to be resolved for the project to work. However, there is a copy of derby.jar in your project folder. If you want to resolve this error you can point Netbeans to that derby.jar. Important: There should be no need to edit code outside the location specify by the questions. Modification outside the location specified by the questions may not result in any marks being allocated if your solution does not work. Question 1 Edit the toString methods of both Pet and Owner classes so that they reflect the following format in the corresponding JLists in the “Edit Pets” tab and the “Owner Analysis” tab: Pet Format: Pet Name (Pet Breed) Example: Paul (Canary) Owner Format: firstname lastname Example: Emma Fouche Question 2 In the “Edit Pets” Tab, clicking on a list entry should display all of its information (except for ID) in the appropriate components on the right hand side. Bind the different components to the appropriate item so that this happens. You should be working in Netbeans and not via any Java code for this question. Question 3 Still in the “Edit Pets” Tab, the following action has already been provided when a user clicks on “Add New Pet >>> ” button: All other components not relevant to adding are blocked Any list entry has been deselected The components on the right are reset to blank or default values. The OK button’s text changes to ‘Add’ There add code should therefore be done in the code to process btnOK. Write code in btnOKActionPerformed method (in the Add part of the if statement) to allow the user to add a new Pet. The detail of the new pet should be retrieved from the various components on the frame. The new Pet should be added to the database as well as the JList. Question 4 Still in the “Edit Pets” Tab, the following action has already been provided when a user clicks on “Update Selected ” button (when there is an entry selected): All other components not relevant to updated are blocked The OK button’s text changes to ‘Update’ There update code should therefore be done in the code to process btnOK. Write code in btnOKActionPerformed method (in the Update part of the if statement) to allow the user to update a selected Pet. The updated detail of the selected pet should be retrieved from the various components on the frame. The selected Pet should be updated in the database as well as the JList.

Transcript of JPQL/ JPA Activity 3

Page 1: JPQL/ JPA  Activity 3

Data Aware and SQL Test – Sample Questions Information Technology Grade 12    SECTION A - JAVA In this section, you will be working with the project PetAppDemoProject. A backup project is also provided in the zBackup folder. Note that you will be a missing resource (derby.jar) error at the start. This error does not need to be resolved for the project to work. However, there is a copy of derby.jar in your project folder. If you want to resolve this error you can point Netbeans to that derby.jar. Important: There should be no need to edit code outside the location specify by the questions. Modification outside the location specified by the questions may not result in any marks being allocated if your solution does not work. Question 1 Edit the toString methods of both Pet and Owner classes so that they reflect the following format in the corresponding JLists in the “Edit Pets” tab and the “Owner Analysis” tab: Pet Format: Pet  Name  (Pet  Breed)   Example: Paul  (Canary)  Owner Format: firstname  lastname Example: Emma  Fouche      Question 2 In the “Edit Pets” Tab, clicking on a list entry should display all of its information (except for ID) in the appropriate components on the right hand side. Bind the different components to the appropriate item so that this happens. You should be working in Netbeans and not via any Java code for this question.

Question 3 Still in the “Edit Pets” Tab, the following action has already been provided when a user clicks on “Add New Pet >>> ” button:

• All other components not relevant to adding are blocked

• Any list entry has been deselected • The components on the right are reset

to blank or default values. • The OK button’s text changes to ‘Add’

There add code should therefore be done in the code to process btnOK. Write code in btnOKActionPerformed method (in the Add part of the if statement) to allow the user to add a new Pet. The detail of the new pet should be retrieved from the various components on the frame. The new Pet should be added to the database as well as the JList. Question 4 Still in the “Edit Pets” Tab, the following action has already been provided when a user clicks on “Update Selected ” button (when there is an entry selected):

• All other components not relevant to updated are blocked

• The OK button’s text changes to ‘Update’

There update code should therefore be done in the code to process btnOK. Write code in btnOKActionPerformed method (in the Update part of the if statement) to allow the user to update a selected Pet. The updated detail of the selected pet should be retrieved from the various components on the frame. The selected Pet should be updated in the database as well as the JList.

Page 2: JPQL/ JPA  Activity 3

Question 5 Still in the “Edit Pets” Tab, the method to handle Deletion of Pet must still be coded. This should be done in the btnDeleteSelectedPetActionPerformed method. A confirmation window should be popped up to confirm deletion. The message should mention the Pet by name and offer Yes/No option. The selected Pet should be deleted from both the database and the JList. Question 6 In the “Owner Analysis” tab, clicking on the “Top” button (btnTop) will take you to the top of the interface list (lstOwners). Write code to do this in btnTopActionPerformed method. Note that your code must not crash if the list is empty. Question 7 In the “Owner Analysis” tab, clicking on the “Bottom” button (btnBottom) will take you to the top of the interface list (lstOwners). Write code to do this in btpBottomActionPerformed method. Note that your code must not crash if the list is empty. Question 8 In the “Owner Analysis” tab, there is a section called “City Analysis”. This panel allows you to select a city from the combobox (cmbCities) and then click Analyse (btnAnalyse). When this button is clicked the number of the owners, pets and registered pets from that selected city. Write code for this button. Note that you should only be working with the OwnerList to obtain the answer to this question.

Question 9 In the “Owner Analysis” tab, there is a section called “Top Debter”. The ‘Find Top Debter’ in this panel allows for the display of the top debter, the amount he/she owes as well as his/her city. Write code for this button. Note that you should only be working with the OwnerList to obtain the answer to this question.  SECTION B - SQL  In this section, you will need to create an Embedded Java DB connection to the PETDB2 folder located in your test folder. Instructions on how to do this are on Moodle. The database is the same in structure and data as the one used in Section A. Type out your answers for each questions in a text file with each question number clearly labeled. Write SQL statement to display the information requested in each question. Question 10 Pet name, breed and their owner name, surname and location. Question 11 The total number of owners in Cape Town. Rename this column ‘CptOwnerNum’ Question 12 The total number of owners in each city. (Also display the city name)

Page 3: JPQL/ JPA  Activity 3

Question 13 The total number of pets in each city. (Also display the city name) Question 14 The total number of unregistered Pets in each city. (Also display the city name) Question 15 The total number of pets in each city but only list those cities with more than 5 pets.

Question 16 The total number of unregistered pets in each city but only list those cities with more than 5 pets. Question 17 The highest outstanding amount Question 18 The name, amount and city of the person who has the highest outstanding amount.