Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You need to do the previous homework assignment before you start this one. You should continue working on the same project.
- In this assignment we will be using a MySQL-type of database. Technically it is MariaDB.
- 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.
- Getting the JDBC Connector:
- Open the pom.xml file in your project.
- 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.
- ...
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- ...
- 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:
- ...
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
- <groupId>mysql</groupId>
- ...
- <version>8.0.13</version>
- </dependency>
- </dependencies>
- ...
- 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.
- Main class
- 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).
- Connect to the database using the following parameters.
- Host: turing.cs.missouriwestern.edu
- database schedule2
- user: csc254
- password: Given in class
- Query: Select courseId, crn, title, instructor, maximumEnrollment, seatsAvailable from sections WHERE instructor LIKE 'staff%' LIMIT 100
- 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.
- The array
- 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.
- 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.
- Print the sorted array.
- Selection Sort starter code
- This is code adapted from the textbook, page 272 of the 11th edition.
- public static void selectionSort(double[] list, int n){
- for(int i=0;i<n;i++){
- double currentMin = list[i];
- int currentMinIndex = 1;
- for(int j=i+1; j < n; j++){
- if(currentMin > list[j]) {
- currentMin = list[j];
- currentMinIndex = j;
- }
- if(currentMinIndex != i){
- list[currentMinIndex] = list[i];
- list[i] = currentMin;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment