Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* package whatever; // don't place package name! */
- import java.awt.List;
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.sql.*;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- class myCode
- {
- boolean exit = false;
- //main driver
- public static void main(String[] args) throws SQLException {
- String jdbcClassName="org.postgresql.Driver";
- String url="jdbc:postgresql://comp421.cs.mcgill.ca:5432/cs421";
- String user="cs421g29";
- String password="nurture123@CS";
- // Register the driver. You must register the driver before you can use it.
- try {
- DriverManager.registerDriver ( new org.postgresql.Driver() ) ;
- } catch (Exception cnfe){
- System.out.println("Class not found");
- }
- // This is the url you must use for Postgresql.
- //Note: This url may not valid now !
- Connection con = DriverManager.getConnection (url,user, password) ;
- Statement statement = con.createStatement ( ) ;
- /*
- Connection connection = null;
- try {
- //Load class into memory
- Class.forName(jdbcClassName);
- //Establish connection
- connection = DriverManager.getConnection(url, user, password);
- System.out.println("CONNECTING");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }finally{
- if(connection!=null){
- System.out.println("Connected successfully.");
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- */
- // Local variable
- boolean exit = false;
- while (!exit)
- {
- // Display menu graphics
- System.out.println(" __________________________");
- System.out.println("| NURTURE BACKEND TOOL |");
- System.out.println("|..........................|");
- System.out.println("| Select option: |");
- System.out.println("| 1. Add new product |");
- System.out.println("| 2. Replenish |");
- System.out.println("| 3. Check Work Schedule |");
- System.out.println("| 4. Customer History |");
- System.out.println("| 5. Exit |");
- System.out.println("|__________________________|");
- selectionMenu();
- }
- }
- public static void addProduct() {
- Scanner scan = new Scanner(System.in);
- System.out.println("----Add new product----");
- System.out.println("Please fill out: ");
- System.out.print("ProductID: ");
- int id = scan.nextInt();
- System.out.print("Price: ");
- int price = scan.nextInt();
- System.out.print("Description: ");
- String desc = scan.next();
- System.out.print("Quantity in stock: ");
- int qty = scan.nextInt();
- System.out.println("INSERT SUCCESSFUL");
- anythingelse();
- }
- public static void replenish() {
- Scanner scan = new Scanner(System.in);
- System.out.println("-------Replenish-------");
- System.out.print("ProductID: ");
- int id = scan.nextInt();
- ArrayList<String> companies = new ArrayList<String>();
- companies = getSuppliers(id);
- String company;
- if (companies.size() <= 0)
- {
- System.out.println("ERROR: No company available for this item, sorry.");
- }
- else
- {
- System.out.println("Choose company to replenish:");
- for(int i=0; i < companies.size(); i++)
- {
- System.out.println((i+1) + ". " +companies.get(i));
- }
- System.out.print(">> ");
- int selected = scan.nextInt();
- if (selected <= companies.size() && selected > 0)
- {
- company = companies.get(selected-1);
- }
- else
- {
- System.out.println("Invalid selection, transaction not complete.");
- }
- }
- anythingelse();
- }
- public static void schedule() {
- Scanner scan = new Scanner(System.in);
- System.out.println("-----Check Schedule-----");
- System.out.print("EmployeeID: ");
- int id = scan.nextInt();
- ArrayList<String> shifts = new ArrayList<String>();
- shifts = getShifts(id);
- String company;
- if (shifts.size() <= 0)
- {
- System.out.println("No shifts assigned.");
- }
- else
- {
- System.out.println("Choose company to replenish:");
- for(int i=0; i < shifts.size(); i++)
- {
- System.out.println((i+1) + ". " +shifts.get(i));
- }
- System.out.print(">> ");
- int selected = scan.nextInt();
- if (selected <= shifts.size() && selected > 0)
- {
- company = shifts.get(selected-1);
- }
- else
- {
- System.out.println("Invalid selection, transaction not complete.");
- }
- }
- anythingelse();
- }
- public static void history() {
- System.out.println("-View Customer History-");
- anythingelse();
- }
- public static void anythingelse(){
- System.out.println(" __________________________");
- System.out.println("| Anything else? |");
- System.out.println("| 1. Add new product |");
- System.out.println("| 2. Replenish |");
- System.out.println("| 3. Check Work Schedule |");
- System.out.println("| 4. Customer History |");
- System.out.println("| 5. Exit |");
- System.out.println("|__________________________|");
- selectionMenu();
- }
- // MAIN MENU
- public static void selectionMenu(){
- @SuppressWarnings("resource")
- Scanner scan = new Scanner(System.in);
- System.out.print(">> ");
- int selected = scan.nextInt();
- switch (selected) {
- case 1:
- addProduct();
- break;
- case 2:
- replenish();
- break;
- case 3:
- schedule();
- break;
- case 4:
- history();
- break;
- case 5:
- System.out.println("Exit. Thanks for working with Nurture.");
- break;
- default:
- System.out.println("Invalid selection. TRY AGAIN.");
- selectionMenu();
- break; // This break is not really necessary
- }
- }
- // for replenishing stock
- public static ArrayList<String> getSuppliers(int id){
- ArrayList<String> sup = new ArrayList<>();
- // TODO: add to sup.
- return sup;
- }
- public static ArrayList<String> getShifts(int id){
- ArrayList<String> shft = new ArrayList<>();
- // TODO: add to shft.
- return shft;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement