Luninariel

Homework 7 - Instructions

Nov 8th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. You need to do the previous homework assignment before you start this one. You should continue working on the same project.
  2.  
  3.  
  4.  
  5. In this assignment we will be using a MySQL-type of database. Technically it is MariaDB.
  6.  
  7.  
  8.  
  9. The problem is that Java does not have the "connector" needed to use MariaDB or MySQL databases. We have to incorporate an outside ".jar" file. Maven makes this relatively easy.
  10.  
  11. Getting the JDBC Connector:
  12. Open the pom.xml file in your project.
  13.  
  14. Look through the pom.xml file. If you set up the file using the archetype specified in Homework 6, then you should find a block that looks something like the following. Notice that the outer tag <dependencies> is plural.
  15.  
  16. ...
  17. <dependencies>
  18. <dependency>
  19. <groupId>junit</groupId>
  20. <artifactId>junit</artifactId>
  21. <version>4.11</version>
  22. <scope>test</scope>
  23. </dependency>
  24. </dependencies>
  25.  
  26. ...
  27. Now search the Internet for something like "Maven mysql connector." It should take you to the mvnrepository.com Pick the most recent version of the connector. Copy/Pasta the tag into the <dependencies> section of the pom.xm. file. You will have something like this:
  28.  
  29. ...
  30. <dependencies>
  31. <dependency>
  32. <groupId>junit</groupId>
  33. <artifactId>junit</artifactId>
  34. <version>4.11</version>
  35. <scope>test</scope>
  36. </dependency>
  37. <dependency>
  38. <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
  39. <groupId>mysql</groupId>
  40. ...
  41. <version>8.0.13</version>
  42. </dependency>
  43. </dependencies>
  44.  
  45. ...
  46. If you have clicked on the "allow automatic updates" Intellij should now pull the jar file and configuration from the Internet the next time you build your program.
  47.  
  48. Main class
  49. In your Main or App class, Ask the user for an instructor's name. Read the name from the keyboard. If the name typed by the user does not contain "%" then concatenate "%" to the end of the string. (% is the mysql wildcard).
  50.  
  51.  
  52.  
  53. Connect to the database using the following parameters.
  54.  
  55. Host: turing.cs.missouriwestern.edu
  56. database schedule2
  57. user: csc254
  58. password: Given in class
  59.  
  60. Query: Select courseId, crn, title, instructor, maximumEnrollment, seatsAvailable from sections WHERE instructor LIKE 'staff%' LIMIT 100
  61. In the above query the user typed "staff" as the faculty name. Note that the word staff has a % appended and ' ' around it. This is a good situation to use a String.format(...) command.
  62.  
  63. The array
  64. Create an array that can hold up to 100 sections. For each class found in the array, create a Section object and put it in the array.
  65.  
  66.  
  67.  
  68. Sort the array using a selection sort. Do not use Arrays.sort or any other build-in sort. Also, don't use MySQL's ORDER BY clause Adapt the sort shown on page 272 of the textbook.
  69.  
  70. Print the sorted array.
  71.  
  72. Selection Sort starter code
  73. This is code adapted from the textbook, page 272 of the 11th edition.
  74.  
  75. public static void selectionSort(double[] list, int n){
  76. for(int i=0;i<n;i++){
  77. double currentMin = list[i];
  78. int currentMinIndex = 1;
  79.  
  80. for(int j=i+1; j < n; j++){
  81. if(currentMin > list[j]) {
  82. currentMin = list[j];
  83. currentMinIndex = j;
  84. }
  85.  
  86. if(currentMinIndex != i){
  87. list[currentMinIndex] = list[i];
  88. list[i] = currentMin;
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment