SHARE
TWEET

Untitled

a guest Mar 20th, 2016 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.awt.List;
  4. import java.util.ArrayList;
  5. import java.util.Scanner;
  6. import java.sql.*;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.SQLException;
  10.  
  11.  
  12. class myCode
  13. {
  14.     boolean exit = false;
  15.     //main driver
  16.     public static void main(String[] args) throws SQLException {
  17.        
  18.         String jdbcClassName="org.postgresql.Driver";
  19.         String url="jdbc:postgresql://comp421.cs.mcgill.ca:5432/cs421";
  20.         String user="cs421g29";
  21.         String password="nurture123@CS";
  22.        
  23.         // Register the driver.  You must register the driver before you can use it.
  24.         try {
  25.         DriverManager.registerDriver ( new org.postgresql.Driver() ) ;
  26.         } catch (Exception cnfe){
  27.         System.out.println("Class not found");
  28.         }
  29.        
  30.         // This is the url you must use for Postgresql.
  31.         //Note: This url may not valid now !
  32.         Connection con = DriverManager.getConnection (url,user, password) ;
  33.         Statement statement = con.createStatement ( ) ;
  34.        
  35.        
  36.        
  37.  /*
  38.         Connection connection = null;
  39.         try {
  40.             //Load class into memory
  41.             Class.forName(jdbcClassName);
  42.             //Establish connection
  43.             connection = DriverManager.getConnection(url, user, password);
  44.             System.out.println("CONNECTING");
  45.  
  46.         } catch (ClassNotFoundException e) {
  47.             e.printStackTrace();
  48.         } catch (SQLException e) {
  49.             e.printStackTrace();
  50.         }finally{
  51.             if(connection!=null){
  52.                 System.out.println("Connected successfully.");
  53.                 try {
  54.                     connection.close();
  55.                 } catch (SQLException e) {
  56.                     e.printStackTrace();
  57.                 }
  58.             }
  59.         }
  60.         */
  61.         // Local variable
  62.         boolean exit = false;
  63.        
  64.         while (!exit)
  65.         {
  66.             // Display menu graphics
  67.             System.out.println(" __________________________");
  68.             System.out.println("|   NURTURE BACKEND TOOL   |");
  69.             System.out.println("|..........................|");
  70.             System.out.println("| Select option:           |");
  71.             System.out.println("|   1. Add new product     |");
  72.             System.out.println("|   2. Replenish           |");
  73.             System.out.println("|   3. Check Work Schedule |");
  74.             System.out.println("|   4. Customer History    |");
  75.             System.out.println("|   5. Exit                |");
  76.             System.out.println("|__________________________|");
  77.            
  78.             selectionMenu();
  79.         }
  80.     }
  81.    
  82.     public static void addProduct() {
  83.         Scanner scan = new Scanner(System.in);
  84.        
  85.         System.out.println("----Add new product----");
  86.         System.out.println("Please fill out: ");
  87.         System.out.print("ProductID: ");
  88.         int id = scan.nextInt();
  89.         System.out.print("Price: ");
  90.         int price = scan.nextInt();
  91.         System.out.print("Description: ");
  92.         String desc = scan.next();
  93.         System.out.print("Quantity in stock: ");
  94.         int qty = scan.nextInt();
  95.         System.out.println("INSERT SUCCESSFUL");
  96.         anythingelse();
  97.     }
  98.     public static void replenish() {
  99.         Scanner scan = new Scanner(System.in);
  100.        
  101.         System.out.println("-------Replenish-------");
  102.         System.out.print("ProductID: ");
  103.         int id = scan.nextInt();
  104.         ArrayList<String> companies = new ArrayList<String>();
  105.         companies = getSuppliers(id);
  106.         String company;
  107.        
  108.         if (companies.size() <= 0)
  109.         {
  110.             System.out.println("ERROR: No company available for this item, sorry.");
  111.         }
  112.         else
  113.         {
  114.             System.out.println("Choose company to replenish:");
  115.             for(int i=0; i < companies.size(); i++)
  116.             {
  117.                 System.out.println((i+1) + ". " +companies.get(i));
  118.             }
  119.             System.out.print(">> ");
  120.             int selected = scan.nextInt();
  121.             if (selected <= companies.size() && selected > 0)
  122.             {
  123.                 company = companies.get(selected-1);
  124.             }
  125.             else
  126.             {
  127.                 System.out.println("Invalid selection, transaction not complete.");
  128.             }
  129.         }
  130.        
  131.         anythingelse();
  132.     }
  133.     public static void schedule() {
  134.         Scanner scan = new Scanner(System.in);
  135.        
  136.         System.out.println("-----Check Schedule-----");
  137.        
  138.         System.out.print("EmployeeID: ");
  139.         int id = scan.nextInt();
  140.         ArrayList<String> shifts = new ArrayList<String>();
  141.         shifts = getShifts(id);
  142.         String company;
  143.        
  144.         if (shifts.size() <= 0)
  145.         {
  146.             System.out.println("No shifts assigned.");
  147.         }
  148.         else
  149.         {
  150.             System.out.println("Choose company to replenish:");
  151.             for(int i=0; i < shifts.size(); i++)
  152.             {
  153.                 System.out.println((i+1) + ". " +shifts.get(i));
  154.             }
  155.             System.out.print(">> ");
  156.             int selected = scan.nextInt();
  157.             if (selected <= shifts.size() && selected > 0)
  158.             {
  159.                 company = shifts.get(selected-1);
  160.             }
  161.             else
  162.             {
  163.                 System.out.println("Invalid selection, transaction not complete.");
  164.             }
  165.         }
  166.         anythingelse();
  167.     }
  168.     public static void history() {
  169.         System.out.println("-View Customer History-");
  170.         anythingelse();
  171.     }
  172.     public static void anythingelse(){
  173.         System.out.println(" __________________________");
  174.         System.out.println("| Anything else?           |");
  175.         System.out.println("|   1. Add new product     |");
  176.         System.out.println("|   2. Replenish           |");
  177.         System.out.println("|   3. Check Work Schedule |");
  178.         System.out.println("|   4. Customer History    |");
  179.         System.out.println("|   5. Exit                |");
  180.         System.out.println("|__________________________|");
  181.  
  182.         selectionMenu();
  183.     }
  184.    
  185.     // MAIN MENU
  186.     public static void selectionMenu(){
  187.         @SuppressWarnings("resource")
  188.         Scanner scan = new Scanner(System.in);
  189.        
  190.         System.out.print(">> ");
  191.         int selected = scan.nextInt();
  192.        
  193.         switch (selected) {
  194.         case 1:
  195.           addProduct();
  196.           break;
  197.         case 2:
  198.           replenish();
  199.           break;
  200.         case 3:
  201.           schedule();
  202.           break;
  203.         case 4:
  204.           history();
  205.           break;
  206.         case 5:
  207.           System.out.println("Exit. Thanks for working with Nurture.");
  208.           break;
  209.         default:
  210.           System.out.println("Invalid selection. TRY AGAIN.");
  211.           selectionMenu();
  212.           break; // This break is not really necessary
  213.         }
  214.     }
  215.    
  216.     // for replenishing stock
  217.     public static ArrayList<String> getSuppliers(int id){
  218.         ArrayList<String> sup = new ArrayList<>();
  219.      // TODO: add to sup.
  220.         return sup;
  221.     }
  222.     public static ArrayList<String> getShifts(int id){
  223.         ArrayList<String> shft = new ArrayList<>();
  224.         // TODO: add to shft.
  225.         return shft;
  226.     }
  227. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top