Advertisement
Guest User

Untitled

a guest
Mar 7th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.86 KB | None | 0 0
  1. package timetable2;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.LinkedList;
  10. import java.util.Queue;
  11. import java.util.Scanner;
  12.  
  13.  
  14. public class Timetable2 {
  15. static int a2[]=new int[35];
  16. static int a[]=new int[35];
  17. static int a1[]=new int[35];
  18. static int flag=0;
  19.  
  20. static void INPUT()
  21. {
  22. flag=1;
  23. /* try{
  24. Class.forName("com.mysql.jdbc.Driver");
  25.  
  26. try (Connection con = DriverManager.getConnection(
  27. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  28.  
  29.  
  30. String query="delete * from SE ";
  31.  
  32. PreparedStatement prepStmt = con.prepareStatement(query);
  33.  
  34. prepStmt.executeQuery();
  35.  
  36. String query1 ="delete * from TE";
  37.  
  38. PreparedStatement repStmt = con.prepareStatement(query1);
  39.  
  40. repStmt.executeQuery();
  41.  
  42. String quer2= "delete * from BE ";
  43.  
  44. PreparedStatement epStmt = con.prepareStatement(quer2);
  45.  
  46. epStmt.executeQuery();
  47.  
  48. con.close();
  49.  
  50.  
  51. }
  52.  
  53. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}*/
  54. /////////////////////// SE INPUT ////////////////////////////
  55. System.out.println("--------Enter Your Details-------- ");
  56. Scanner in = new Scanner(System.in);
  57. System.out.print("Enter the Number of subjects for SE:");
  58. int iq = in.nextInt();
  59. int k=1;
  60. int m=101;
  61. for(int j=0;j<iq;j++)
  62. {
  63.  
  64. System.out.println("Enter subject name:");
  65. Scanner a = new Scanner(System.in);
  66. String subname=a.next();
  67.  
  68. System.out.println("Enter Teacher name:");
  69.  
  70. String teachname=a.next();
  71.  
  72. System.out.println("Enter Number of lectures per week:");
  73.  
  74. int lecno=a.nextInt();
  75.  
  76. System.out.println("Enter Subject status ('pr' for practical and 'th' for theory) ");
  77. String status=a.next();
  78. int an;
  79. int kk=m;
  80. try{
  81. Class.forName("com.mysql.jdbc.Driver");
  82.  
  83. try (Connection con = DriverManager.getConnection(
  84. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  85.  
  86. Statement stmt=con.createStatement();
  87. String query="select Teacher_id from SE where Teacher_name=?";
  88.  
  89. PreparedStatement prepStmt = con.prepareStatement(query);
  90. prepStmt.setString(1,teachname);
  91. ResultSet rs = prepStmt.executeQuery();
  92. while(rs.next())
  93. {an = rs.getInt(1);
  94. m=an;
  95. kk=kk-1;
  96. }
  97. String sql1 ="insert into SE values(?,?,?,?,?,?)";
  98. try (PreparedStatement s = con.prepareStatement(sql1)) {
  99. s.setInt(1,k);
  100. s.setString(2, subname);
  101. s.setInt(3,m);
  102. s.setString(4,teachname);
  103. s.setInt(5,lecno);
  104. s.setString(6,status);
  105. s.executeUpdate();
  106.  
  107.  
  108. s.close();
  109. }
  110. con.close();
  111.  
  112.  
  113. }
  114.  
  115. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  116. m=kk;
  117. k=k + 1;
  118. m=m+1;
  119. }
  120.  
  121. ///////////////////////////////// TE INPUT ////////////////////////////////////////
  122.  
  123. Scanner aa = new Scanner(System.in);
  124. System.out.print("Enter the Number of subjects for TE:");
  125. int ab = aa.nextInt();
  126. int x=11;
  127. int y=111;
  128. for(int j=0;j<ab;j++)
  129. {
  130.  
  131. System.out.println("Enter subject name:");
  132. Scanner a1 = new Scanner(System.in);
  133. String subname1=a1.next();
  134.  
  135. System.out.println("Enter Teacher name:");
  136.  
  137. String teachname1=a1.next();
  138.  
  139. System.out.println("Enter Number of lectures per week:");
  140.  
  141. int lecno1=a1.nextInt();
  142.  
  143. System.out.println("Enter Subject status ('pr' for practical and 'th' for theory) ");
  144. String status1=a1.next();
  145. int ac;
  146. String teach="";
  147. int yy=y;
  148. try{
  149. Class.forName("com.mysql.jdbc.Driver");
  150.  
  151. try (Connection con = DriverManager.getConnection(
  152. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  153.  
  154. Statement stmt=con.createStatement();
  155. String query="select Teacher_id from SE where Teacher_name=?";
  156.  
  157. PreparedStatement prepStmt = con.prepareStatement(query);
  158. prepStmt.setString(1,teachname1);
  159. ResultSet rs = prepStmt.executeQuery();
  160. while(rs.next())
  161. {ac = rs.getInt(1);
  162. y=ac;
  163.  
  164. }
  165.  
  166.  
  167. String query1="select Teacher_id from TE where Teacher_name=?";
  168. int acc;
  169. PreparedStatement Stmt = con.prepareStatement(query1);
  170. Stmt.setString(1,teachname1);
  171. ResultSet rs1 = Stmt.executeQuery();
  172. while(rs1.next())
  173. {acc = rs1.getInt(1);
  174. y=acc;
  175.  
  176. }
  177.  
  178.  
  179. String sql1 ="insert into TE values(?,?,?,?,?,?)";
  180. try (PreparedStatement s = con.prepareStatement(sql1)) {
  181. s.setInt(1,x);
  182. s.setString(2, subname1);
  183. s.setInt(3,y);
  184. s.setString(4,teachname1);
  185. s.setInt(5,lecno1);
  186. s.setString(6,status1);
  187. s.executeUpdate();
  188.  
  189.  
  190. s.close();
  191. }
  192. con.close();
  193.  
  194.  
  195. }
  196.  
  197. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  198. y=yy;
  199. x=x + 1;
  200. y=y+1;
  201. }
  202.  
  203.  
  204. ////////////////////////////////// BE INPUT /////////////////////////////////////////
  205.  
  206. Scanner aa1 = new Scanner(System.in);
  207. System.out.print("Enter the Number of subjects for BE:");
  208. int ab1 = aa1.nextInt();
  209. int x1=21;
  210. int y1=121;
  211. for(int j=0;j<ab1;j++)
  212. {
  213.  
  214. System.out.println("Enter subject name:");
  215. Scanner a2 = new Scanner(System.in);
  216. String subname2=a2.next();
  217.  
  218. System.out.println("Enter Teacher name:");
  219.  
  220. String teachname2=a2.next();
  221.  
  222. System.out.println("Enter Number of lectures per week:");
  223.  
  224. int lecno2=a2.nextInt();
  225.  
  226. System.out.println("Enter Subject status ('pr' for practical and 'th' for theory) ");
  227. String status2=a2.next();
  228. int ac1;
  229.  
  230. int yy1=y1;
  231. try{
  232. Class.forName("com.mysql.jdbc.Driver");
  233.  
  234. try (Connection con = DriverManager.getConnection(
  235. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  236.  
  237.  
  238. String query="select Teacher_id from SE where Teacher_name=?";
  239.  
  240. PreparedStatement prepStmt1 = con.prepareStatement(query);
  241. prepStmt1.setString(1,teachname2);
  242. ResultSet rs2 = prepStmt1.executeQuery();
  243. while(rs2.next())
  244. {ac1 = rs2.getInt(1);
  245. y1=ac1;
  246.  
  247. }
  248.  
  249.  
  250. String query1="select Teacher_id from TE where Teacher_name=?";
  251.  
  252. PreparedStatement Stmt = con.prepareStatement(query1);
  253. Stmt.setString(1,teachname2);
  254. ResultSet rs3 = Stmt.executeQuery();
  255. while(rs3.next())
  256. {ac1 = rs3.getInt(1);
  257. y1=ac1;
  258.  
  259. }
  260.  
  261.  
  262. String query2="select Teacher_id from BE where Teacher_name=?";
  263.  
  264. PreparedStatement Stmt1 = con.prepareStatement(query2);
  265. Stmt1.setString(1,teachname2);
  266. ResultSet rs4 = Stmt1.executeQuery();
  267. while(rs4.next())
  268. {ac1 = rs4.getInt(1);
  269. y1=ac1;
  270.  
  271. }
  272.  
  273. String sql2 ="insert into BE values(?,?,?,?,?,?)";
  274. try (PreparedStatement s = con.prepareStatement(sql2)) {
  275. s.setInt(1,x1);
  276. s.setString(2, subname2);
  277. s.setInt(3,y1);
  278. s.setString(4,teachname2);
  279. s.setInt(5,lecno2);
  280. s.setString(6,status2);
  281. s.executeUpdate();
  282.  
  283.  
  284. s.close();
  285. }
  286. con.close();
  287.  
  288.  
  289. }
  290.  
  291. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  292. y1=yy1;
  293. x1=x1 + 1;
  294. y1=y1+1;
  295. }
  296. /////////////////////////////INSERT DEFAULT 0 FOR NO LECTURE/////////////////////////////////////////
  297. /* try{
  298. Class.forName("com.mysql.jdbc.Driver");
  299. try (Connection con = DriverManager.getConnection(
  300. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  301.  
  302.  
  303. String sql1 ="insert into SE values(?,?,?,?,?,?)";
  304. try (PreparedStatement s = con.prepareStatement(sql1)) {
  305. s.setInt(1,0);
  306. s.setString(2,"NO LECTURE");
  307. s.setInt(3,0);
  308. s.setString(4,"");
  309. s.setInt(5,0);
  310. s.setString(6,"");
  311. s.executeUpdate();
  312.  
  313.  
  314. s.close();
  315. }
  316. String sql2 ="insert into TE values(?,?,?,?,?,?)";
  317. try (PreparedStatement s = con.prepareStatement(sql2)) {
  318. s.setInt(1,0);
  319. s.setString(2,"NO LECTURE");
  320. s.setInt(3,0);
  321. s.setString(4,"");
  322. s.setInt(5,0);
  323. s.setString(6,"");
  324. s.executeUpdate();
  325.  
  326.  
  327. s.close();
  328. }String sql3 ="insert into BE values(?,?,?,?,?,?)";
  329. try (PreparedStatement s = con.prepareStatement(sql3)) {
  330. s.setInt(1,0);
  331. s.setString(2,"NO LECTURE");
  332. s.setInt(3,0);
  333. s.setString(4,"");
  334. s.setInt(5,0);
  335. s.setString(6,"");
  336. s.executeUpdate();
  337.  
  338.  
  339. s.close();
  340. }
  341. con.close();
  342.  
  343.  
  344. }
  345.  
  346. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  347. */
  348. }
  349.  
  350.  
  351.  
  352. static void CREATE()
  353. {
  354.  
  355. Queue<Integer> q = new LinkedList<>();
  356. int mr3=0;
  357. try{
  358. Class.forName("com.mysql.jdbc.Driver");
  359.  
  360. try (Connection con = DriverManager.getConnection(
  361. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  362.  
  363.  
  364. String query="select subject_id,No_of_lectures from SE";
  365.  
  366. PreparedStatement pStmt1 = con.prepareStatement(query);
  367.  
  368. ResultSet rs5 = pStmt1.executeQuery();
  369. while(rs5.next())
  370. {
  371.  
  372. int a1 = rs5.getInt(1);
  373. int a2= rs5.getInt(2);
  374. for(int ll=0;ll<a2;ll++)
  375. {
  376. q.add(a1);
  377. }
  378. }
  379. String queryj="select sum(No_of_lectures) from SE where status=?";
  380. ResultSet rpv1;
  381. try(PreparedStatement eprStmt2 = con.prepareStatement(queryj)){
  382. eprStmt2.setString(1,"th");
  383. rpv1 = eprStmt2.executeQuery();
  384. while(rpv1.next())
  385. {
  386. mr3 = rpv1.getInt(1);
  387. }}
  388.  
  389. }
  390.  
  391. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  392. int kk=q.size();
  393.  
  394. int i=0;
  395. for(int l=0;l<q.size();l++)
  396. {
  397. a[l]=0;
  398.  
  399. }
  400. while(!q.isEmpty())
  401. {
  402. if(a[i]==0)
  403. {
  404. int r=q.remove();
  405. try{
  406. Class.forName("com.mysql.jdbc.Driver");
  407.  
  408. try (Connection con = DriverManager.getConnection(
  409. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  410. String abd="";
  411.  
  412. String query="select status from SE where subject_id=?";
  413.  
  414. PreparedStatement mt1 = con.prepareStatement(query);
  415.  
  416. mt1.setInt(1,r);
  417.  
  418. ResultSet rs2 = mt1.executeQuery();
  419. while(rs2.next()){
  420. abd=rs2.getString(1);}
  421.  
  422. if(abd.equals("pr")&&mr3==0)
  423. {
  424. if(i>9&&i<15)
  425. {
  426. q.add(r);
  427. }
  428. else
  429. {
  430. a[i]=r;
  431. i=i+5;
  432. if(!q.isEmpty()){
  433. int w=q.remove();
  434. a[i]=w;
  435. i=i-4;}
  436.  
  437. }
  438. }
  439. else
  440. {
  441. a[i]=r;
  442. i++;
  443. mr3--;
  444. }
  445.  
  446. }}catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  447.  
  448. }
  449.  
  450.  
  451.  
  452. }
  453.  
  454. //////////////////////////////TE///////////////////////////////
  455.  
  456. Queue<Integer> q1 = new LinkedList<>();
  457. int mm3=0;
  458. try{
  459. Class.forName("com.mysql.jdbc.Driver");
  460.  
  461. try (Connection con = DriverManager.getConnection(
  462. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  463.  
  464.  
  465. String query5="select subject_id,No_of_lectures from TE";
  466.  
  467. PreparedStatement epStmt1 = con.prepareStatement(query5);
  468.  
  469. ResultSet rp = epStmt1.executeQuery();
  470. while(rp.next())
  471. {
  472.  
  473. int a1 = rp.getInt(1);
  474. int a2= rp.getInt(2);
  475. for(int kl=0;kl<a2;kl++)
  476. {
  477. q1.add(a1);
  478. }
  479. }
  480. String queryj="select sum(No_of_lectures) from TE where status=?";
  481. ResultSet rpv1;
  482. try(PreparedStatement eprStmt2 = con.prepareStatement(queryj)){
  483. eprStmt2.setString(1,"th");
  484. rpv1 = eprStmt2.executeQuery();
  485. while(rpv1.next())
  486. {
  487. mm3 = rpv1.getInt(1);
  488. }}
  489. }
  490.  
  491. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  492. int kkk=q1.size();
  493.  
  494. int h=0;
  495. for(int l=0;l<q.size();l++)
  496. {
  497. a1[l]=0;
  498. }
  499. while(!q1.isEmpty())
  500. {
  501.  
  502. if(a1[h]==0)
  503. {
  504. int r=q1.remove();
  505. int j=a[h];
  506. try{
  507. Class.forName("com.mysql.jdbc.Driver");
  508. //here sonoo is database name, root is username and password
  509. try (Connection con = DriverManager.getConnection(
  510. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  511.  
  512. int z=1;
  513. String query="select Teacher_id from SE where subject_id=?";
  514.  
  515. PreparedStatement mt1 = con.prepareStatement(query);
  516.  
  517. mt1.setInt(1,j);
  518.  
  519. ResultSet rs2 = mt1.executeQuery();
  520. while(rs2.next()){
  521. z=rs2.getInt(1);
  522. }
  523. String query1="select Teacher_id from TE where subject_id=?";
  524.  
  525. PreparedStatement mt2 = con.prepareStatement(query1);
  526.  
  527. mt2.setInt(1,r);
  528. int l=1;
  529. ResultSet rs3 = mt2.executeQuery();
  530. while(rs3.next()){
  531. l=rs3.getInt(1);}
  532.  
  533. if(l==z)
  534. {
  535. q1.add(r);
  536. }
  537. else
  538. {
  539. try{
  540. Class.forName("com.mysql.jdbc.Driver");
  541.  
  542. try (Connection con1 = DriverManager.getConnection(
  543. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  544. String abd="";
  545.  
  546. String queryq="select status from TE where subject_id=?";
  547.  
  548. PreparedStatement mtt1 = con1.prepareStatement(queryq);
  549.  
  550. mtt1.setInt(1,r);
  551.  
  552. ResultSet rss2 = mtt1.executeQuery();
  553. while(rss2.next()){
  554. abd=rss2.getString(1);}
  555.  
  556. if(abd.equals("pr")&&mm3==0)
  557. {
  558. if(h>9&&h<15)
  559. {
  560. q1.add(r);
  561. }
  562. else{
  563. a1[h]=r;
  564. h=h+5;
  565. if(!q1.isEmpty()){
  566. q1.remove();}
  567. a1[h]=r;
  568. h=h-4;
  569. }
  570. }
  571. else
  572. {
  573. a1[h]=r;
  574. h++;
  575. mm3--;
  576. }
  577. }
  578. }
  579.  
  580. catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  581.  
  582. }}
  583.  
  584. } catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  585.  
  586.  
  587.  
  588. }else{h++;}
  589.  
  590. }
  591.  
  592. ///////////////////////////BE//////////////////////////////////
  593.  
  594. Queue<Integer> q2 = new LinkedList<>();
  595. int m3=0;
  596. try{
  597. Class.forName("com.mysql.jdbc.Driver");
  598.  
  599. try (Connection con = DriverManager.getConnection(
  600. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  601.  
  602.  
  603. String query5="select subject_id,No_of_lectures from BE";
  604.  
  605. PreparedStatement epStmt2 = con.prepareStatement(query5);
  606.  
  607. ResultSet rp1 = epStmt2.executeQuery();
  608. while(rp1.next())
  609. {
  610.  
  611. int a3 = rp1.getInt(1);
  612. int a4= rp1.getInt(2);
  613. for(int kl=0;kl<a4;kl++)
  614. {
  615. q2.add(a3);
  616. }
  617. }
  618. String queryj="select sum(No_of_lectures) from BE where status=?";
  619. ResultSet rpv1;
  620. try(PreparedStatement eprStmt2 = con.prepareStatement(queryj)){
  621. eprStmt2.setString(1,"pr");
  622. rpv1 = eprStmt2.executeQuery();
  623. while(rpv1.next())
  624. {
  625. m3 = rpv1.getInt(1);
  626. }}
  627. }
  628.  
  629. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  630. int bb=q2.size();
  631.  
  632. for(int t=0;t<35;t++)
  633. {
  634. a2[t]=0;
  635. }
  636. int hh=0;
  637. while(!q2.isEmpty())
  638. {
  639.  
  640. if(a2[hh]==0){
  641. int r=q2.remove();
  642. int j=a[hh];
  643. int c=a1[hh];
  644. try{
  645. Class.forName("com.mysql.jdbc.Driver");
  646.  
  647. try (Connection con = DriverManager.getConnection(
  648. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  649.  
  650. int z=1;
  651. String query="select Teacher_id from SE where subject_id=?";
  652.  
  653. PreparedStatement mt1 = con.prepareStatement(query);
  654.  
  655. mt1.setInt(1,j);
  656.  
  657. ResultSet rs2 = mt1.executeQuery();
  658. while(rs2.next()){
  659. z=rs2.getInt(1);
  660. }
  661. String query1="select Teacher_id from TE where subject_id=?";
  662.  
  663. PreparedStatement mt2 = con.prepareStatement(query1);
  664.  
  665. mt2.setInt(1,c);
  666. int l=1;
  667. ResultSet rs3 = mt2.executeQuery();
  668. while(rs3.next()){
  669. l=rs3.getInt(1);}
  670.  
  671. String query2="select Teacher_id from BE where subject_id=?";
  672.  
  673. PreparedStatement mt3 = con.prepareStatement(query2);
  674.  
  675. mt3.setInt(1,r);
  676. int p=1;
  677. ResultSet rb = mt3.executeQuery();
  678. while(rb.next()){
  679.  
  680. p=rb.getInt(1);}
  681.  
  682.  
  683. if(p==z)
  684. {
  685. q2.add(r);
  686. }
  687. else if(p==l){
  688. q2.add(r);
  689. }
  690. else
  691. {
  692. try{
  693. Class.forName("com.mysql.jdbc.Driver");
  694.  
  695. try (Connection con1 = DriverManager.getConnection(
  696. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  697. String abd="";
  698.  
  699. String queryq="select status from BE where subject_id=?";
  700.  
  701. PreparedStatement mtt1 = con1.prepareStatement(queryq);
  702.  
  703. mtt1.setInt(1,r);
  704.  
  705. ResultSet rss2 = mtt1.executeQuery();
  706. while(rss2.next()){
  707. abd=rss2.getString(1);}
  708.  
  709. if(abd.equals("pr"))
  710. {
  711. if(hh>9&&hh<15)
  712. {
  713. q2.add(r);
  714. }
  715. else{
  716. a2[hh]=r;
  717. hh=hh+5;
  718. if(!q2.isEmpty()){
  719. q2.remove();}
  720. a2[hh]=r;
  721. hh=hh-4;
  722. m3=m3-2;
  723. }
  724. }
  725. else if(m3==0)
  726. {
  727. a2[hh]=r;
  728. hh++;
  729. }
  730. else
  731. {
  732. q2.add(r);
  733. }
  734. }
  735. }
  736.  
  737. catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  738. }}
  739.  
  740. } catch(ClassNotFoundException | SQLException e){ System.out.println(e);} }
  741. else{hh++;}
  742.  
  743.  
  744.  
  745. }
  746.  
  747.  
  748. System.out.println("TIMETABLE CREATED SUCCESSFULLY.....");
  749. }
  750. static void SE()
  751. {
  752. if(flag==1){
  753. int f=1;
  754.  
  755. System.out.println("");
  756.  
  757. System.out.println("SECOND YEAR:\n");
  758. System.out.println("Lec.No. MONDAY\t\t\tTUESDAY\t\t\tWEDNESDAY\t\tTHURSDAY\t\tFRIDAY");
  759. System.out.println("________________________________________________________________________________________________________________\n");
  760. System.out.print("1)\t");
  761. int fp=2;
  762. int ss=1;
  763. for(int t=0;t<35;t++){
  764.  
  765. int a3=a[t];
  766. try{
  767. Class.forName("com.mysql.jdbc.Driver");
  768.  
  769. try (Connection con = DriverManager.getConnection(
  770. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  771. String z="";
  772. String zz="";
  773.  
  774. String query="select subject_name,Teacher_name from SE where subject_id=?";
  775.  
  776. PreparedStatement mt1 = con.prepareStatement(query);
  777.  
  778. mt1.setInt(1,a3);
  779.  
  780. ResultSet rs2 = mt1.executeQuery();
  781. while(rs2.next()){
  782. z=rs2.getString(1);
  783. zz=rs2.getString(2);
  784.  
  785. }
  786.  
  787. if(ss%5==0)
  788. {
  789.  
  790. System.out.print(z+"("+zz+")\t\t");
  791. System.out.println("\n");
  792. if(ss==15)
  793. {
  794. System.out.print("************************************************ R E C E S S **************************************************");
  795. System.out.println("\n");
  796. }
  797. if(fp<=7)
  798. System.out.print(fp+")\t");
  799. fp++;
  800. ss++;
  801. }
  802. else
  803. {
  804. System.out.print(z);
  805. System.out.print("("+zz+")\t\t");
  806. ss++;
  807. }
  808.  
  809. }
  810.  
  811. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  812.  
  813.  
  814. }
  815. System.out.print("________________________________________________________________________________________________________________\n");
  816. }
  817. else{
  818. System.out.println("TIMETABLE NOT CREATED YET !!!!");
  819. }
  820. }
  821.  
  822. static void TE(){
  823. if(flag==1){
  824. System.out.println("\n\n\n");
  825. System.out.println("THIRD YEAR:\n");
  826. System.out.println("Lec.No. MONDAY\t\t\tTUESDAY\t\t\tWEDNESDAY\t\tTHURSDAY\t\tFRIDAY");
  827. System.out.println("_______________________________________________________________________________________________________________\n");
  828.  
  829. System.out.print("1)\t");
  830. int ftt=2;
  831. int st=1;
  832. for(int t=0;t<35;t++){
  833. int a3=a1[t];
  834. try{
  835. Class.forName("com.mysql.jdbc.Driver");
  836.  
  837. try (Connection con = DriverManager.getConnection(
  838. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  839.  
  840. String z="";
  841. String zz="";
  842. String query="select subject_name,Teacher_name from TE where subject_id=?";
  843.  
  844. PreparedStatement mt1 = con.prepareStatement(query);
  845.  
  846. mt1.setInt(1,a3);
  847.  
  848. ResultSet rs2 = mt1.executeQuery();
  849. while(rs2.next()){
  850. z=rs2.getString(1);
  851. zz=rs2.getString(2);
  852. }
  853.  
  854. if(st%5==0)
  855. {
  856. System.out.print(z+"("+zz+")\t\t");
  857. System.out.println("\n");
  858. if(st==15)
  859. {
  860. System.out.print("************************************************ R E C E S S **************************************************");
  861. System.out.println("\n");
  862. }
  863. if(ftt<=7)
  864. System.out.print(ftt+")\t");
  865. ftt++;
  866. st++;
  867. }
  868. else
  869. {
  870. System.out.print(z+"("+zz+")\t\t");
  871. st++;
  872. }
  873. }
  874.  
  875. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  876.  
  877.  
  878. }
  879. System.out.println("_______________________________________________________________________________________________________________");
  880.  
  881. }
  882. else{
  883. System.out.println("TIMETABLE NOT CREATED YET !!!!");
  884. }
  885. }
  886.  
  887. static void BE()
  888. {
  889. if(flag==1){
  890. System.out.println("\n\n\n");
  891. System.out.println("FOURTH YEAR:\n");
  892. System.out.println("Lec.No. MONDAY\t\t\tTUESDAY\t\t\tWEDNESDAY\t\tTHURSDAY\t\tFRIDAY");
  893. System.out.println("_______________________________________________________________________________________________________________\n");
  894. System.out.print("1)\t");
  895. int stt=1;
  896. int ft=2;
  897. for(int t=0;t<35;t++){
  898. int a3=a2[t];
  899. try{
  900. Class.forName("com.mysql.jdbc.Driver");
  901.  
  902. try (Connection con = DriverManager.getConnection(
  903. "jdbc:mysql://localhost:3306/Timetable?autoReconnect=true&useSSL=false","root","shivdas@123")) {
  904.  
  905. String z="";
  906. String zz="";
  907. String query="select subject_name,Teacher_name from BE where subject_id=?";
  908.  
  909. PreparedStatement mt1 = con.prepareStatement(query);
  910.  
  911. mt1.setInt(1,a3);
  912.  
  913. ResultSet rs2 = mt1.executeQuery();
  914. while(rs2.next()){
  915. z=rs2.getString(1);
  916. zz=rs2.getString(2);
  917. }
  918.  
  919. if(stt%5==0)
  920. {
  921. System.out.print(z+"("+zz+")\t\t");
  922. System.out.println("\n");
  923. if(stt==15)
  924. {
  925. System.out.print("************************************************ R E C E S S **************************************************");
  926. System.out.println("\n");
  927. }
  928. if(ft<=7)
  929. System.out.print(ft+")\t");
  930. ft++;
  931. stt++;
  932. }
  933. else
  934. {
  935. System.out.print(z+"("+zz+")\t\t");
  936. stt++;
  937. }
  938. }
  939.  
  940. }catch(ClassNotFoundException | SQLException e){ System.out.println(e);}
  941.  
  942.  
  943. }
  944. System.out.println("_______________________________________________________________________________________________________________");
  945.  
  946. }
  947. else{
  948. System.out.println("TIMETABLE NOT CREATED YET !!!!");
  949. }
  950.  
  951. }
  952.  
  953.  
  954.  
  955. public static void main(String[] args) {
  956. int n;
  957. do{
  958. System.out.println("****************************************MENU***********************************************");
  959. System.out.println("1) CREATE TIMETABLE \n2) DISPLAY SE TIMETABLE \n3) DISPLAY TE TIMETABLE \n4) DISPLAY BE TIMETABLE \n5) EXIT");
  960. System.out.println("ENTER YOUR CHOICE");
  961. Scanner av = new Scanner(System.in);
  962. n=av.nextInt();
  963. switch(n)
  964. {
  965. case 1:
  966. INPUT();
  967. CREATE();
  968. break;
  969.  
  970. case 2:
  971. SE();
  972. break;
  973.  
  974. case 3:
  975. TE();
  976. break;
  977.  
  978. case 4:
  979. BE();
  980. break;
  981.  
  982. case 5:break;
  983.  
  984. default:System.out.println("Wrong choice!!!!!!!");
  985. }
  986. }while(n!= 5);
  987.  
  988.  
  989. }}
  990.  
  991.  
  992. ////////////////////////////////OUTPUT//////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement