Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.sql.*;
- import java.util.*;
- public class GPA {
- private final static Map<String, Double> map = new HashMap<>();
- public static void main(String args[]) throws Exception {
- if (args.length != 1) {
- System.out.println("[Usage]: java GPA [query]");
- System.exit(0);
- }
- map.put("A+", 4.3);
- map.put("A", 4.0);
- map.put("A-", 3.7);
- map.put("B+", 3.3);
- map.put("B", 3.0);
- map.put("B-", 2.7);
- map.put("C+", 2.3);
- map.put("C", 2.0);
- map.put("C-", 1.7);
- map.put("F", 0.0);
- Class.forName("org.sqlite.JDBC");
- String url = "jdbc:sqlite:/Users/host/Documents/Personal/Courses.db";
- Connection con = DriverManager.getConnection(url);
- Statement stm = con.createStatement();
- ResultSet rs = stm.executeQuery(args[0]);
- double sum = 0;
- int credits = 0;
- while (rs.next()) {
- String grades = rs.getString("成績");
- if (!map.keySet().contains(grades))
- continue;
- sum += map.get(grades) * rs.getInt("學分");
- credits += rs.getInt("學分");
- }
- System.out.println(sum / credits);
- con.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement