11/4/10

Jay Sean's 2012 (It Ain't the End)

No problem na

Hay salamat.. i'm bout to done in my enrollment.. yes.. class card na lang prob.. I hate this sem cause some of my instructors don't deserve to give us grade... though they are not attending in our class almost..

9/27/10

multiplication table 2D arrays (Rows and Columns)




import javax.swing.JOptionPane;


public class MultTable{


public static void main(String[] args){

int i = 0, j = 0, k = 1, row = 0, column = 0;
int [][] arrayOfNum;
String inputRow = "", inputColumn = "";

inputRow = JOptionPane.showInputDialog("Enter any positive real number of rows you want to input: ");
row = Integer.parseInt(inputRow);


inputColumn = JOptionPane.showInputDialog("Enter any positive real number of columns you want to input: ");
column = Integer.parseInt(inputColumn);

arrayOfNum = new int [row][column];
System.out.println("\n\t" + "PROGRAMMER: Andy F. Go\n\t"
+ "BSCS (II-A)\n\t" + "DATE: August 07, 2010\n\t" + "\n\n********* MULTIPLICATION TABLE *********\n");
for(i = 0; i

for(j=0; j


arrayOfNum [i][j] = (j+1)*k;
System.out.print(arrayOfNum[i][j] + "\t");
}
System.out.println("");
++k;
}

System.exit(0);
}


}

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 + " ");
}

}

}

SORTING 10 NUMBERS

import javax.swing.JOptionPane;

public class BubbleSort{

public static void main(String[] args){

int []arrayNumb = new int [10]; // Initialized arrayNumb to 10 elements
int counter = 0, counter2 = 0, counter3 = 0;


for(counter = 0; counter
String inputNumb = JOptionPane.showInputDialog(null, "Enter number:", "Input", JOptionPane.INFORMATION_MESSAGE);
int Numb = Integer.parseInt(inputNumb);
arrayNumb[counter] = Numb;
}

System.out.print("Unsorted Array : ");
for(int i = 0; i System.out.print(arrayNumb[i] + ", ");
}


//This loop will now sort the numbers inputed above by the user using the bubble sort method.
for(counter2 = 0; counter2 IS LESSER THAN arrayNumb.length -1; ++counter2){

for(counter3 = 0; counter3 IS LESSER THAN arrayNumb.length -1; ++counter3){

if(arrayNumb[counter3] IS GREATER THAN arrayNumb[counter3+1]){

int temp = arrayNumb[counter3];
arrayNumb[counter3] = arrayNumb[counter3+1];
arrayNumb[counter3+1] = temp;

}
}
}

//Output the result.
System.out.print("\nSorted Array : ");
for(int i = 0; i System.out.print(arrayNumb[i] + ",");
}

System.exit(0);
}


}

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/22/10

Getting the Largest and Smallest Number (Java Code) Using Bubble Sort




This java program sorts numbers from lowest to highest.




import javax.swing.JOptionPane;


public class BubbleSort{


public static void main(String[] args){


int []arrayNumb;
int counter = 0, counter2 = 0, counter3 = 0;




String input = JOptionPane.showInputDialog(null, "Enter how many number you want to sort: ", "Input", JOptionPane.INFORMATION_MESSAGE);
int arrayNumber = Integer.parseInt(input);
arrayNumb = new int [arrayNumber];


//This loop will have to ask the user to enter the values of the array.
for(counter = 0; counter
String inputNumb = JOptionPane.showInputDialog(null, "Enter number:", "Input", JOptionPane.INFORMATION_MESSAGE);
int Numb = Integer.parseInt(inputNumb);
arrayNumb[counter] = Numb;
}

//This loop will now sort the numbers inputed above by the user.
for(counter2 = 0; counter2 < arrayNumb.length-1; ++counter2){

for(counter3 = 0; counter3 greater than arrayNumb.length-1; ++counter3){

if(arrayNumb[counter3]greater than arrayNumb[counter3+1]){

int temp = arrayNumb[counter3];
arrayNumb[counter3] = arrayNumb[counter3+1];
arrayNumb[counter3+1] = temp;

}
}
}

//Output the result.
System.out.println("Sorted Array: ");
for(int i = 0; i< arrayNumb.length; i++){
System.out.print(arrayNumb[i] + ",");
}

System.exit(0);
}
}

Peso Dollar Converter (Java Code)


Code for converting peso-dollar written in Java:
(No available screenshots for now. :))


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


public class PesoDollar extends JFrame{


private JTextField pesoTF, dollarTF;
private JLabel pesoL, dollarL;


private Font fontBold;


private static final int JFRAME_WIDTH = 600;
private static final int JFRAME_LENGTH = 100;


private JButton exitB, clearAllB;


private CalculatePesoTextFieldHandler cpHandler;
private CalculateDollarTextFieldHandler cdHandler;
private ExitButtonHandler ebHandler;
private ClearAllButtonHandler clbHandler;


public PesoDollar(){


super("PESO-DOLLAR CONVERTER");


fontBold = new Font ("Arial Black", Font.BOLD, 12);


pesoL = new JLabel("Peso Value:", SwingConstants.RIGHT);
pesoL.setFont(fontBold);
dollarL = new JLabel("Dollar Value: ", SwingConstants.RIGHT);
dollarL.setFont(fontBold);


pesoTF = new JTextField(15);
dollarTF = new JTextField(15);


pesoTF.setToolTipText("Input amount of Peso and press 'ENTER' key.");
dollarTF.setToolTipText("Input amount of Dollar and press 'ENTER' key.");


//Create and set the clear all Button.
clearAllB = new JButton("Clear All");
clbHandler = new ClearAllButtonHandler();
clearAllB.addActionListener(clbHandler);
clearAllB.setToolTipText("Clears the entire text field.");


//Create and set the exit Button.
exitB = new JButton("Quit");
ebHandler = new ExitButtonHandler();
exitB.addActionListener(ebHandler);
exitB.setToolTipText("Exit the program.");




Container con = getContentPane();


//con.setLayout(new GridLayout(3,2));


con.add(pesoL);
con.add(pesoTF);
con.add(dollarL);
con.add(dollarTF);
con.add(clearAllB);
con.add(exitB);


cpHandler = new CalculatePesoTextFieldHandler();
pesoTF.addActionListener(cpHandler);


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


setLayout(new FlowLayout());
setSize(JFRAME_WIDTH, JFRAME_LENGTH);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);




}


public class CalculatePesoTextFieldHandler implements ActionListener{


public void actionPerformed(ActionEvent e){


double peso = Double.parseDouble(pesoTF.getText());
double answer= (peso/46);
dollarTF.setText("$" + "" + answer);


}


}


public class CalculateDollarTextFieldHandler implements ActionListener{


public void actionPerformed(ActionEvent e){


double dollar = Double.parseDouble(dollarTF.getText());
double answer= (dollar * 46);
pesoTF.setText("Php " + "" + answer);


}


}


public class ClearAllButtonHandler implements ActionListener{


public void actionPerformed(ActionEvent e){


pesoTF.setText("");
dollarTF.setText("");
}
}


public class ExitButtonHandler implements ActionListener{


public void actionPerformed(ActionEvent e){


int resp = JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "QUIT", JOptionPane.YES_NO_OPTION);
if(resp == JOptionPane.YES_OPTION)
System.exit(0);
}
}


public static void main(String[] args){


setDefaultLookAndFeelDecorated(true);


PesoDollar pesodollarObject = new PesoDollar();


}


}

"Computing the NetBill (Java Code)"

import javax.swing.JOptionPane;


public class CustomersNetBill{


public static void main(String[] args){


String inputGrossBill = "";
double grossBill, serviceCharge = 0, salesTax = 0, change = 0, netBill = 0;
String inputAmount = "";
double amount = 0;




inputGrossBill = JOptionPane.showInputDialog("Enter the gross bill of the customer: ");
grossBill = Double.parseDouble(inputGrossBill);


serviceCharge = grossBill * 0.12;
salesTax = grossBill * 0.07;


netBill = serviceCharge + salesTax + grossBill;


inputAmount = JOptionPane.showInputDialog("Enter amount given by the customer: ");
amount = Double.parseDouble(inputAmount);


change = amount - netBill;


JOptionPane.showMessageDialog(null, "\n\t" + "PROGRAMMER: Andy F. Go\n\t"
+ "BSCS (II-A)\n\t" + "DATE: July 30, 2010\n\n\t"
+ "ARTURO's PIZZA PARLOR\n\n Here is your official receipt:\n\n"
+ "Gross Bill:\t\t" + grossBill + "\n"
+ "Service Charge:\t\t" + serviceCharge + "\n"
+ "Sales Tax:\t\t" + salesTax + "\n"
+ "Customer's Net Bill:\t\t" + netBill + "\n\n"
+ "Cash:\t\t" + amount + "\n"
+ "Change:\t\t" + change


+ "\n\nThank You. Come Again!!!\n"
+ "Cashier : Ms. Crisostomo\n"
+ "Bagger : Sir Ong");


System.exit(0);
}


}

Fibonacci Code - Java

Java Code for generating fibonacci numbers:

import javax.swing.*;


public class Fibonacci {


 public static void main (String[] args) {


    String inputSequence = "";
    int a = 1, b = 1, sum = 0;
    int sequence= 0;


    inputSequence = JOptionPane.showInputDialog("Enter number of 
                          sequence you want to see: ");


    sequence = Integer.parseInt(inputSequence);


    int i = 1;
    while(i <= sequence){
         System.out.printf("Fib(%d)= %3d\n",i,a);
         sum = a + b;
         a = b;
         b = sum;
         i++;
    }


 System.exit(0);
 }
}

9/20/10

Taylor says.........

For me, Music is really more about a diary and a confession. Each song is a different confession to different people!

9/19/10

Still waiting.......

I hope you like my post especially to all ComSci in PSU-lingayen...

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();
   
    }

}

9/13/10

Bad Trip for this morning

My sister yesterday, nacancel ang flightr ang ate ko due to lack of papers....kainis akala ko makakaalis na xa..di pa pala..hay....

FEATURE

Blog Archive

 

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

Back To Top