Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- importjava.sql.*;
- importjava.util.*;
- class Main
- {
- public static void main(String a[])
- {
- //Creating the connection
- String url = "jdbc:oracle:thin:@localhost:1521:xe";
- String user = "system";
- String pass = "12345";
- //Entering the data
- Scanner k = new Scanner(System.in);
- System.out.println("enter name");
- String name = k.next();
- System.out.println("enter roll no");
- int roll = k.nextInt();
- System.out.println("enter class");
- String cls = k.next();
- //Inserting data using SQL query
- String sql = "insert into student1 values('"+name+"',"+roll+",'"+cls+"')";
- Connection con=null;
- try
- {
- DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
- //Reference to connection interface
- con = DriverManager.getConnection(url,user,pass);
- Statement st = con.createStatement();
- int m = st.executeUpdate(sql);
- if (m == 1)
- System.out.println("inserted successfully : "+sql);
- else
- System.out.println("insertion failed");
- con.close();
- }
- catch(Exception ex)
- {
- System.err.println(ex);
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////
- import java.io.*;
- class BankWork
- {
- // initialize and declare objects.
- final int max_limit=20;
- final int min_limit=1;
- final double min_bal=500;
- private String name[]=new String[20];
- private int accNo[]=new int[20];
- private String accType[]=new String[20];
- private double balamount[]=new double[20];
- static int totRec=0;
- // create a constructor here of Bank.
- BankWork()
- {
- for(int i=0;i<max_limit;i++)
- {
- name[i]="";
- accNo[i]=0;
- accType[i]="";
- balamount[i]=0.0;
- }
- }
- // Create method to create New entry.
- public void newEntry()
- {
- String str;
- int account;
- double amount;
- boolean permit;
- permit=true;
- if (totRec>max_limit)
- {
- System.out.println("\n\n\nSorry we cannot admit you in our bank...\n\n\n");
- permit=false;
- }
- // create new entry.
- if(permit = true)
- {
- totRec++;
- // Incrementing Records
- System.out.println("\n\n\n=====SAVING NEW ENTRY=====");
- try
- {
- accNo[totRec]=totRec; //Created AutoNumber to accNo so no invalid id occurs
- System.out.println("Account Number : "+accNo[totRec]);
- // create object.
- BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
- // enter the name of customer here.
- System.out.print("Enter the name of the Customer : ");
- System.out.flush();
- name[totRec]=obj.readLine();
- // enter the type of account.
- System.out.print("Enter Account Type : ");
- System.out.flush();
- accType[totRec]=obj.readLine();
- do
- {
- // enter the starting amount.
- // minimum amount must be 1000.
- System.out.print("Enter Initial Amount to be deposited : ");
- System.out.flush();
- str=obj.readLine();
- balamount[totRec]=Double.parseDouble(str);
- }
- while(balamount[totRec]<min_bal);
- System.out.println("\n\n\n");
- }
- catch(Exception e)
- {
- System.out.println("Exception in Entering a record.....");
- }
- }
- }
- // create method to display records.
- public void display()
- {
- String str;
- int account=0;
- boolean valid=true;
- System.out.println("\n\n=====DISPLAYING THE RECORDS=====\n");
- try
- {
- // create object.
- BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
- // enter account number.
- System.out.print("Enter the account number for display record : ");
- System.out.flush();
- str=obj.readLine();
- account=Integer.parseInt(str);
- // check for valid account number
- if (account<min_limit || account>totRec)
- {
- System.out.println("\n\n\nInvalid Account Number \n\n");
- valid=false;
- }
- if (valid==true)
- {
- System.out.println("\n\nAccount Number : "+accNo[account]);
- System.out.println("Name : "+name[account]);
- System.out.println("Account Type : "+accType[account]);
- System.out.println("Balance Amount : "+balamount[account]+"\n\n\n");
- }
- }
- catch(Exception e)
- {
- System.out.println("Exception in Displaying record.....");
- }
- }
- // create method to deposit amount.
- public void deposit()
- {
- String str;
- double amount;
- int account;
- boolean valid=true;
- System.out.println("\n\n\n=====DEPOSIT AMOUNT=====");
- try
- {
- // create object.
- BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
- System.out.print("Enter Account No : ");
- System.out.flush();
- str=obj.readLine();
- account=Integer.parseInt(str);
- // check valid account number.
- if (account<min_limit || account>totRec)
- {
- System.out.println("\n\n\nInvalid Account Number \n\n");
- valid=false;
- }
- if (valid==true)
- {
- System.out.print("Enter Amount you want to Deposit : ");
- System.out.flush();
- str=obj.readLine();
- amount=Double.parseDouble(str);
- balamount[account]=balamount[account]+amount;
- //Displaying Depsit Details
- System.out.println("\nAfter Updation...");
- System.out.println("Account Number : "+account);
- System.out.println("Balance Amount : "+balamount[account]+"\n\n\n");
- }
- }
- catch(Exception e)
- {
- System.out.println("Exception in Depositing record.....");
- }
- }
- // creating method for withdraw money.
- public void withdraw()
- {
- String str;
- double amount,checkamount;
- int account;
- boolean valid=true;
- System.out.println("\n\n\n=====WITHDRAW MONEY=====");
- try
- {
- // create object.
- BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
- // enter account number for entering money
- System.out.print("Enter the account number to deposit money : ");
- System.out.flush();
- str=obj.readLine();
- account=Integer.parseInt(str);
- // check for valid account number.
- if (account<min_limit || account>totRec)
- {
- System.out.println("\n\n\nInvalid Account Number \n\n");
- valid=false;
- }
- if (valid==true)
- {
- System.out.println("Balance is : "+balamount[account]);
- System.out.print("Enter Amount you want to withdraw : ");
- System.out.flush();
- str=obj.readLine();
- amount=Double.parseDouble(str);
- checkamount=balamount[account]-amount;
- if(checkamount >= min_bal)
- {
- balamount[account]=checkamount;
- // Updating the amount after withdraw.
- System.out.println("\nAfter Updation...");
- System.out.println("Account Number : "+account);
- System.out.println("Balance Amount : "+balamount[account]+"\n\n\n");
- }
- else
- {
- System.out.println("\n\nAs per Bank Rule you should maintain minimum balance of Rs 500\n\n\n");
- }
- }
- }
- catch(Exception e)
- {
- System.out.println("Exception in Withdrawing record.....");
- }
- }
- };
- class Bank
- {
- public static void main(String args[])
- {
- String str;
- int choice;
- choice=0;
- BankWork BW_obj = new BankWork();
- do
- {
- // creating Menu.
- System.out.println("Choose Your Choices ...");
- System.out.println("1) New Record Entry ");
- System.out.println("2) Display Record Details ");
- System.out.println("3) Deposit...");
- System.out.println("4) Withdraw...");
- System.out.println("5) Exit");
- System.out.print("Enter your choice : ");
- System.out.flush();
- try
- {
- // creating objects.
- BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
- str=obj.readLine();
- choice=Integer.parseInt(str);
- switch(choice)
- {
- case 1 :
- // for new entry.
- BW_obj.newEntry();
- break;
- case 2 :
- // for display.
- BW_obj.display();
- break;
- case 3 :
- // for deposit.
- BW_obj.deposit();
- break;
- case 4 :
- // for display.
- BW_obj.withdraw();
- break;
- case 5 :
- System.out.println("\n\n.....THANKS FOR VISITING.....");
- break;
- default : System.out.println("\nInvalid Choice \n\n");
- }
- }
- catch(Exception e)
- {
- System.out.println("Exception in Main....");
- }
- }
- while(choice!=5);
- }
- }
- //////////////////////////////////////////////////////////////////////
- import java.io.*;
- class DecisionTree {
- private class BinTree {
- private int nodeID;
- private String questOrAns = null;
- private BinTree yesBranch = null;
- private BinTree noBranch = null;
- public BinTree(int newNodeID, String newQuestAns) {
- nodeID = newNodeID;
- questOrAns = newQuestAns;
- }
- }
- /* OTHER FIELDS */
- static BufferedReader keyboardInput = new
- BufferedReader(new InputStreamReader(System.in));
- BinTree rootNode = null;
- public DecisionTree() {
- }
- public void createRoot(int newNodeID, String newQuestAns) {
- rootNode = new BinTree(newNodeID,newQuestAns);
- System.out.println("Created root node " + newNodeID);
- }
- public void addYesNode(int existingNodeID, int newNodeID, String newQuestAns) {
- // If no root node do nothing
- if (rootNode == null) {
- System.out.println("ERROR: No root node!");
- return;
- }
- // Search tree
- if (searchTreeAndAddYesNode(rootNode,existingNodeID,newNodeID,newQuestAns)) {
- System.out.println("Added node " + newNodeID +
- " onto \"yes\" branch of node " + existingNodeID);
- }
- else System.out.println("Node " + existingNodeID + " not found");
- }
- private boolean searchTreeAndAddYesNode(BinTree currentNode,
- int existingNodeID, int newNodeID, String newQuestAns) {
- if (currentNode.nodeID == existingNodeID) {
- // Found node
- if (currentNode.yesBranch == null) currentNode.yesBranch = new
- BinTree(newNodeID,newQuestAns);
- else {
- System.out.println("WARNING: Overwriting previous node " +
- "(id = " + currentNode.yesBranch.nodeID +
- ") linked to yes branch of node " +
- existingNodeID);
- currentNode.yesBranch = new BinTree(newNodeID,newQuestAns);
- }
- return(true);
- }
- else {
- // Try yes branch if it exists
- if (currentNode.yesBranch != null) {
- if (searchTreeAndAddYesNode(currentNode.yesBranch,
- existingNodeID,newNodeID,newQuestAns)) {
- return(true);
- }
- else {
- // Try no branch if it exists
- if (currentNode.noBranch != null) {
- return(searchTreeAndAddYesNode(currentNode.noBranch,
- existingNodeID,newNodeID,newQuestAns));
- }
- else return(false);
- }
- }
- return(false);
- }
- }
- public void addNoNode(int existingNodeID, int newNodeID, String newQuestAns) {
- if (rootNode == null) {
- System.out.println("ERROR: No root node!");
- return;
- }
- if (searchTreeAndAddNoNode(rootNode,existingNodeID,newNodeID,newQuestAns)) {
- System.out.println("Added node " + newNodeID +
- " onto \"no\" branch of node " + existingNodeID);
- }
- else System.out.println("Node " + existingNodeID + " not found");
- }
- private boolean searchTreeAndAddNoNode(BinTree currentNode,
- int existingNodeID, int newNodeID, String newQuestAns) {
- if (currentNode.nodeID == existingNodeID) {
- if (currentNode.noBranch == null) currentNode.noBranch = new
- BinTree(newNodeID,newQuestAns);
- else {
- System.out.println("WARNING: Overwriting previous node " +
- "(id = " + currentNode.noBranch.nodeID +
- ") linked to yes branch of node " +
- existingNodeID);
- currentNode.noBranch = new BinTree(newNodeID,newQuestAns);
- }
- return(true);
- }
- else {
- if (currentNode.yesBranch != null) {
- if (searchTreeAndAddNoNode(currentNode.yesBranch,
- existingNodeID,newNodeID,newQuestAns)) {
- return(true);
- }
- else {
- if (currentNode.noBranch != null) {
- return(searchTreeAndAddNoNode(currentNode.noBranch,
- existingNodeID,newNodeID,newQuestAns));
- }
- else return(false); // Not found here
- }
- }
- else return(false); // Not found here
- }
- }
- public void queryBinTree() throws IOException {
- queryBinTree(rootNode);
- }
- private void queryBinTree(BinTree currentNode) throws IOException {
- // Test for leaf node (answer) and missing branches
- if (currentNode.yesBranch==null) {
- if (currentNode.noBranch==null) System.out.println(currentNode.questOrAns);
- else System.out.println("Error: Missing \"Yes\" branch at \"" +
- currentNode.questOrAns + "\" question");
- return;
- }
- if (currentNode.noBranch==null) {
- System.out.println("Error: Missing \"No\" branch at \"" +
- currentNode.questOrAns + "\" question");
- return;
- }
- // Question
- askQuestion(currentNode);
- }
- private void askQuestion(BinTree currentNode) throws IOException {
- System.out.println(currentNode.questOrAns + " (enter \"Yes\" or \"No\")");
- String answer = keyboardInput.readLine();
- if (answer.equals("Yes")) queryBinTree(currentNode.yesBranch);
- else {
- if (answer.equals("No")) queryBinTree(currentNode.noBranch);
- else {
- System.out.println("ERROR: Must answer \"Yes\" or \"No\"");
- askQuestion(currentNode);
- }
- }
- }
- public void outputBinTree() {
- outputBinTree("1",rootNode);
- }
- private void outputBinTree(String tag, BinTree currentNode) {
- if (currentNode == null) return;
- System.out.println("[" + tag + "] nodeID = " + currentNode.nodeID +
- ", question/answer = " + currentNode.questOrAns);
- outputBinTree(tag + ".1",currentNode.yesBranch);
- outputBinTree(tag + ".2",currentNode.noBranch);
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement