Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1.  
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14.  
  15. /**
  16. *
  17. * @author Admin
  18. */
  19. public class Main {
  20.  
  21. /**
  22. * @param args the command line arguments
  23. */
  24. public static void main(String[] args) {
  25.  
  26. int wierzcholekKoncowy = Integer.parseInt(args[1]); //końcowy wierzchołek grafu
  27. int iloscWierzcholkow = 0; //liczba wierzchołków
  28.  
  29.  
  30. try {
  31. String database = args[0];
  32.  
  33. Connection conn = DriverManager.getConnection(database);
  34.  
  35. PreparedStatement stmt = conn.prepareStatement("SELECT x, y, p FROM GTable");
  36. stmt.execute();
  37. ResultSet r = stmt.getResultSet();
  38.  
  39. List<Path.Punkt> pl = new ArrayList<>();
  40.  
  41. while(r.next()){
  42. Path.Punkt p = new Path.Punkt();
  43. p.setX(r.getInt("x"));
  44. p.setY(r.getInt("y"));
  45. p.setP(r.getFloat("p"));
  46. pl.add(p);
  47. }
  48. for(Path.Punkt p : pl){
  49. if(p.getX()>iloscWierzcholkow)
  50. iloscWierzcholkow=p.getX();
  51. if(p.getY()>iloscWierzcholkow)
  52. iloscWierzcholkow=p.getY();
  53. }
  54.  
  55. Path pg = new Path(iloscWierzcholkow, wierzcholekKoncowy-1, pl);
  56.  
  57. pg.obliczKoszt();
  58. float koszt = pg.getKoszty();
  59.  
  60. System.out.format("Koszt: %.3f", koszt);
  61. }
  62. catch(SQLException ex){
  63. ex.printStackTrace();
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement