Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

4/4/12

COMPILING AND RUNNING YOUR JAVA FILES USING COMMAND PROMPT (CMD WINDOW) – for WINDOWS


Step 1:
a.       Go to Start Menu -> Click ‘Run’ or
b.    Press Window Logo on your keyboard + R
*If you can’t find  the ‘Run’ on your Start Menu, right click the ‘Start Menu logo’ à Properties à choose ‘Customize’ button à put a tick on ‘Run command’ and hit OK and ‘Apply’.
Step 2:
                Type ‘cmd’ on the Run window.











Step 3:
                The command window will appear after.
a.       Type: cd C:\java\bin                                    to go to the directory  C:\java\bin> where your
java files (.java) are saved.   

b.       Compiling your java file. This will create a .CLASS file when compiling is done               . 

Type this:
javac myJavaFile.java       

*If no errors were found, proceed to running your java file.
*In compiling your java program, always remember that it translates the code line by line.

             c.       Running your java file.
Type,

 java myJavaFile.java



*Java is case-sensitive;
*Don’t forget to include the file extension (.JAVA) of your java file when compiling and running them.


PHP with MySQL



There are simple 5 steps on how your PHP interacts (connects) to your MySQL database (via PHPMyAdmin). Here are php code snippets you can use.
1.       Create a connection.

<php?
                //Declares variables.
                $DBHOST = “localhost”;
                $USERNAME = “root”;
                $PASSWORD = “”;  //if your Dbase has a password, put it between the two double quotes; otherwise leave it blank.

                //creates connection
                $connection = mysql_connect(“DBHOST”,”USERNAME”,””); or die(“Database connection failed” . mysql_error());
?>

The die() function will execute if the connection has failed.

2.       Selecting a database
<php?
                $select_db = mysql_select_db(dbMyDatabase”, $connection); or die(“Database selection failed” .  mysql_error());
?>

3.       Perform a database query.
<php?
                $query_result = mysql_query(“SELECT * FROM tbMyTable
WHERE id = 1
ORDER BY 1 ASC”, $connection); or die(“Database selection has failed” . mysql_error());
?>

4.       Use returned data (if any)
<php?
                while($row=mysql_fetch_array($query_result)){
                                echo $row[1] . “ “ . row[2] . “<br />”; //prints the records from tablerow1 and tablerow2 simultaneously
}
?>

5.       Close the connection.
<php?
                mysql_close($connection);
?>





Putting all the steps in your PHP as one  will look like this:
1.  Create a connection
//Your Codes here
2.  Database selection
<html>
<head>
<title>My PHP File < /title>
</head>
<body>
3.  Performing  a query selection
//Your Codes here

4.  Use returned a data
//Your Codes here

</body>
</html>
5.  Close a connection.
//Your Codes here
                
     
                
     

9/27/10

Divisors of a Number (Java Program)

import javax.swing.JOptionPane;

public class DivisorsOfANumber{

public static void main(String[] args){
String input;
int number;
int numberDivisors = 0;
int moduloAnswer;

here:
do{
input = JOptionPane.showInputDialog(null, "Enter a positive real number:", "Divisors of A Number", JOptionPane.INFORMATION_MESSAGE);
number = Integer.parseInt(input);

if(number<0){
JOptionPane.showMessageDialog(null, "Invalid number! A positive number should be needed to enter", "Error!", JOptionPane.ERROR_MESSAGE);
continue here;
}
if(number == 0)
JOptionPane.showMessageDialog(null, "Error! No possible divisor for zero.", "Error!", JOptionPane.ERROR_MESSAGE);
continue here;
}while(number<=0);

System.out.print("The divisors of " + number + " are : ");

for(int possibleDivisors = 1; possibleDivisors<=number; possibleDivisors++){

if((number % possibleDivisors)==0)
System.out.print(possibleDivisors + " ");
}

}

}

9/23/10

"WithDraw Deposit" - Java Code

import java.util.Scanner;


public class WithDrawDeposit{


public static void main (String[] args){


Scanner input = new Scanner(System.in);


double transact;
double balance = 20000;
double finalBal = 0;


System.out.println("Your current balance is Php 20,000.00");
System.out.println("A Postive number means Deposit");
System.out.println("A Negative number means Withdraw");
System.out.println("Press 0 to end transaction.\n\n");


here:


do{


System.out.print("Enter amount to transact: ");
transact = input.nextDouble();


if(transact==0) {
System.out.println("Program will now exit...\n");
System.out.println("Current Balance now: " + "Php " + balance);
System.exit(0);
}
else if(transact>0){
finalBal = balance + transact;
System.out.println("Current Balance: " + "Php " + finalBal);
}
else{
if(-(transact)>finalBal){
System.out.println("Insufficient Funds!");
continue here;
}
finalBal = balance + (transact);
System.out.println("Current Balance: " + "Php " + finalBal);


}


balance = finalBal;


}while(transact<0||transact>0);


}




}

9/19/10

Converting Peso-Dollar and Vice- versa (Java Code)

//Conversion: $1=Php 46.00

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PesoDollar extends JFrame{

    private JTextField pesoTF, dollarTF;
    private JLabel pesoL, dollarL;
   
    private static final int JFRAME_WIDTH = 400;
    private static final int JFRAME_LENGTH = 100;

    private CalculatePesoTextField cpHandler;
    private CalculateDollarTextField cdHandler;

    public PesoDollar(){       
       
        super("PESO-DOLLAR CONVERTER");       
        pesoL = new JLabel("Amount of Peso:", SwingConstants.RIGHT);
        dollarL = new JLabel("Amount of Dollar: ", SwingConstants.RIGHT);
   
        pesoTF = new JTextField(10);
        dollarTF = new JTextField(10);
       
        Container con = getContentPane();

        con.add(pesoL);
        con.add(pesoTF);
       
        con.add(dollarL);
        con.add(dollarTF);
       
        con.setLayout(new GridLayout(2,2));
       
        cpHandler = new CalculatePesoTextField();   
        pesoTF.addActionListener(cpHandler);

        cdHandler = new CalculateDollarTextField();   
        dollarTF.addActionListener(cdHandler);

        setSize(JFRAME_WIDTH, JFRAME_LENGTH);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);


    }

    public class CalculatePesoTextField implements ActionListener{

        public void actionPerformed(ActionEvent e){
   
            double peso = Double.parseDouble(pesoTF.getText());
            double answer= (peso/46);
            dollarTF.setText("$" + "" + answer);
       
        }

    }

    public class CalculateDollarTextField implements ActionListener{

        public void actionPerformed(ActionEvent e){
   
            double dollar = Double.parseDouble(dollarTF.getText());
            double answer= (dollar * 46);
            pesoTF.setText("Php" + "" + answer);
       
        }

    }

    public static void main(String[] args){
       
        setDefaultLookAndFeelDecorated(true);

        PesoDollar pesodollarObject = new PesoDollar();
   
    }

}

FEATURE

 

© 2013 andyfgo. All rights reserved. Designed by Templateism. Powered by Blogger
Protected by Copyscape DMCA Takedown Notice Violation Search

Back To Top