Wednesday, March 18, 2009

COLOR CYCLE

/*

Exercise 2
Program Name:Color Cycle
Programmer name: Danver G. Palmiano
Date Started: March 18,2009, 8:15pm
Date Ended: March 18, 2009,9:15pm
Aim: When you enter the button then the color of the background will change depends on the color that are required or stated on the button.
*/


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class ButtonDemo extends JPanel implements ActionListener {

private static boolean USE_CROSS_PLATFORM_UI = false;

int buttonLabelIndex = 0;
String buttonLabels[] = { "Green", "blue", "Gray", "Red" };
Color buttonColors[] = { Color.GREEN, Color.BLUE, Color.GRAY, Color.RED,};

JButton button;

public ButtonDemo() {
super(new BorderLayout());

button = new JButton(buttonLabels[buttonLabelIndex]);
// In the default UI look and feel you cannot easily alter the background color
// for buttons since it is designed to match the OS X UI.
if(USE_CROSS_PLATFORM_UI) {
button.setBackground(buttonColors[buttonLabelIndex]);
} else {
button.setForeground(buttonColors[buttonLabelIndex]);
}

button.addActionListener(this);


this.add(button, BorderLayout.CENTER);

this.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
}

public void actionPerformed(ActionEvent e) {
buttonLabelIndex = ++buttonLabelIndex < buttonLabels.length?buttonLabelIndex:0;

button.setText(buttonLabels[buttonLabelIndex]);
this.setBackground(buttonColors[buttonLabelIndex]);
button.setBackground(buttonColors[buttonLabelIndex]);

}


private static void run() {
if(USE_CROSS_PLATFORM_UI) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}

JFrame frame = new JFrame("Button Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JComponent contentPane = new ButtonDemo();
contentPane.setOpaque(true);

frame.setContentPane(contentPane);
frame.pack();

frame.setVisible(true);
}

public static void main(String[] args) {
run();
}

}

COMBINATION LOCK

/*

Exercise 3
Program Name:Combination Lock
Programmer name: Danver G. Palmiano
Date Started: March 18,2009, 8:15pm
Date Ended: March 18, 2009,9:15pm
Aim: The user must click the correct combination button. If user will click the correct button then it is a right code and then exit, else the background of the JFrame will turn into color Red if wrong combination..
*/

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Combination extends JPanel {

String[] password={"7","3","5"};
int Check=0;
int counter=0;
public Combination() {

JButton btn1 = new JButton("0");
btn1.addActionListener(new ButtonListener());
add(btn1);
JButton btn2 = new JButton("1");
btn2.addActionListener(new ButtonListener());
add(btn2);
JButton btn3 = new JButton("2");
btn3.addActionListener(new ButtonListener());
add(btn3);
JButton btn4 = new JButton("3");
btn4.addActionListener(new ButtonListener());
add(btn4);
JButton btn5 = new JButton("4");
btn5.addActionListener(new ButtonListener());
add(btn5);
JButton btn6 = new JButton("5");
btn1.addActionListener(new ButtonListener());
add(btn6);
JButton btn7 = new JButton("6");
btn7.addActionListener(new ButtonListener());
add(btn7);
JButton btn8 = new JButton("7");
btn8.addActionListener(new ButtonListener());
add(btn8);
JButton btn9 = new JButton("8");
btn9.addActionListener(new ButtonListener());
add(btn9);
JButton btn10 = new JButton("9");
btn10.addActionListener(new ButtonListener());
add(btn10);

}

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MainClass());

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);
}
}

class ButtonListener implements ActionListener {
ButtonListener() {
}

public void actionPerformed(ActionEvent e)
{
if(counter<3)
{
if (e.getActionCommand().equals(password[counter]))
{
Check=1;
}
else
{
Check=2;
}
counter++;
}
else
{
if (e.getActionCommand().equals(password[counter]))
{
Check=1;
}
else
{
Check=2;
}
counter=0;
if(Check==3)
{
this.setBackground(Color.RED);
}
else
{
System.exit(0);
}
}


}
}

NAME ECHO

/*

Exercise 4
Program Name:NAME ECHO
Programmer name: Danver G. Palmiano
Date Started: March 18,2009, 9:15am
Date Ended: March 18, 2009,1:24pm
Aim: When enter two word second word will turn to capital letter or in upper case form.

*/

import java.util.Scanner;
import javax.swing.*;
import java.io.*;


public class nameEcho{


public static void main(String[] args) throws IOException//start the main method that will catch Exceptions
{

String b;//first input string
String c;//second input string


String a=JOptionPane.showInputDialog("Enter your Name: ");//ask input to the user in correct form



b=a.substring(a.indexOf(" "),a.length()).toUpperCase();// uppercase method
c=a.substring(0,a.indexOf(" "));


System.out.println("Input in normal form : " + a);// Print the normal string
System.out.println("Output: " +c+ " "+b);// Print the string in normal and in Uppercase

}//end main method

}//end class nameEcho





Sample Output:

Enter name: dan ver

Input in Normal Form: dan ver
Output: dan VER


source:SAVITCH, WALTER"Java: AN INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING",THIRD EDITION

WORD REVERSE

/*

Exercise 1
Program Name: WORD REVERSE
Programmer name: Danver G. Palmiano
Date Started: March 18,2009, 8:30am
Date Ended: March 18, 2009,11:24am
Aim: To enter a word that will reverse from the first index to last. if two words entered, then the place of the word won't change but its index will reverse.

*/

import javax.swing.*;
import java.util.Scanner;
import java.io.*;


public class Reverse {

public static void main(String[] args) throws IOException//start the main method that will catch Exceptions
{

String a=JOptionPane.showInputDialog("Enter Name: ");//ask input to the user in correct form
System.out.print("Input:"+a);//print output of the user

String b=a.substring(a.indexOf(" "),a.length());
String reverse= new StringBuffer(b).reverse().toString();//reverse the first word entered
String c=a.substring(0,a.indexOf(" "));
String reverse2=new StringBuffer(c).reverse().toString();//reverse the second word entered


System.out.println("\nInput in Normal Form : " + a);// Print the normal string

System.out.println("Reverse input: " +reverse2+ " "+ reverse );// Print the string in reversed order
}//end main method


}//end class Reverse


Sample Output:


Enter name: dan ver

Input in Normal Form: dan ver
Reverse input: nad rev



source:SAVITCH, WALTER"Java: AN INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING",THIRD EDITION

Monday, March 16, 2009

EXERCISE 5: Greetings..

/*
Programmer: Danver G. Palmiano
Date Started: March 17,2009
Date Ended: March 17, 2009
*/


import javax.swing.*;
public class helloObject{//name of class

public static void main(String args[])//start main method

{
String a=JOptionPane.showInputDialog("Enter Greeting:");//ask input to user
System.out.println("Enter greeting:"+a);
System.out.println("\n"+a); //display input
}//end main method

}//end class Reverse

SAMPLE OUTPUT:

Enter greeting:
Hello!

OUTPUT:

Enter greeting:Hello!

Hello!

Friday, March 6, 2009

User-Friendly Division by: Danver G. Palmiano

/*
Programmer: Danver G. Palmiano
Date Started: March 6,2009
Date Ended: March 6, 2009

*/

import java.util.InputMismatchException;
import javax.swing.*;

public class UserFriendlyDivision{

public static void main(String args[]){

char ans='y';

while(ans=='y'){

double x=Integer.parseInt(JOptionPane.showInputDialog("Enter numerator:"));//ask user input
double y=Integer.parseInt(JOptionPane.showInputDialog("Enter divisor:"));//ask user second input

double answer=x/y; //formula to get the answer

System.out.println(+ x + " / " + ); //display the input ask
System.out.println("The quotient is:"+answer); //display the answer

if(y==0)//conditional method
{
System.out.println("You cannot divide the " + x + " to 0. ");// display th econditional staement
}

String a=(JOptionPane.showInputDialog("Do you want to continue?");//ask user to continue the program
ans=a.chartAt(0);//get the input
}
}//end main method

}//end class UserFriendlyDivision

Monday, March 2, 2009

Array List and Iterator Exercise

/*
Programmer: Danver G. Palmiano
Date Started: March 2,2009
Date Ended: MArch 3, 2009
Purpose: To learn about Iterators.
*/


import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class Iteratorsmain{
public static void main(String args[]) {//start main method

ArrayList dan = new ArrayList();

dan.add("D");
dan.add("O");
dan.add("G");//output ask in arraylist
dan.add("C");
dan.add("A");
dan.add("T");

System.out.print("Original contents of al: ");
Iterator Iter = al.iterator();
while (Iter.hasNext()) {
String element = Iter.next();
System.out.print(element + " ");//print the original output in sequence
}
System.out.println();

ListIterator Litre= al.listIterator();
while (Litre.hasNext()) {
String element = Litre.next();
Litre.set(element + "+");// setting the element
}

// Now, display the list backwards.
System.out.print("Modified list backwards: ");
while (Litre.hasPrevious()) {
String element = Litre.previous();
System.out.print(element + " ");//print the elements in backwards form
}

}// end main method

}//end class Iteratorsmain



*Output:
Original contents of al: D O G C A T
Modified list backwards: T+ A+ C+ G+ O+ D+


NOTE: This code were copied at the net. Since we are trying to learn how to create an Array List Iterators...

SOURCE:http://www.java2s.com/Code/JavaAPI/java.util/
ArrayListiterator.htm


What I learned in this exercise:

* To add iteration support to your own classes, we must implement the iter method.
* The for-in statement uses iterators to control the loop, and we can use iterators in many other contexts.
* Iterators are very usefull in making program even using it in our thesis...

Sunday, February 8, 2009

PROGRAM SOLUTION OF DIRECT CLOTHING CASE STUDY

/*Programmer: Danver G. Palmiano
Date Started: March 23,2009
Date Ended: March 23, 2009
Purpose: For Midterm Purposes
*/
import javax.swing.*;
import java.util.Scanner;

public class ShirtTester{
public static void main(String args[]){
char ans='y';

System.out.println("\tWELCOME TO DANVER's CLOTHING");
System.out.println("\n");
System.out.println("1 Applicatiopn Form");
System.out.println("2 View Catalog");
System.out.println("3 Order");
System.out.println("4 Form of Payment");
System.out.println("5 Erase Order");
System.out.println("6 Finish Order");
System.out.println("\n\n");
System.out.println("Reminders:\tFor you to get correct order pls. follow procedure.");
System.out.println("\t\t\tThank You!");
System.out.println("\n\n");

while(ans=='y')
{int choice=Integer.parseInt(JOptionPane.showInputDialog("Enter procedure:"));

if(choice==1)

{
String b=JOptionPane.showInputDialog("Enter complete name:");
String c=JOptionPane.showInputDialog("Enter City Address:");
int a=Integer.parseInt(JOptionPane.showInputDialog("Enter Phone Number:")); String e=JOptionPane.showInputDialog("Enter E-mail:");


System.out.println("\t\tCUSTOMER PROFILE\n");
System.out.println("Name:\t\t\t"+ b +"\nCity Address\t"+ c +"\nPhone Number:\t"+ a +"\nE-mail:\t\t\t"+ e);
System.out.println("\n");
}

else if(choice==2)

{
Catalog dan=new Catalog();
dan.display(23211300,150,"Blue","Cotton");
System.out.println("\n");
dan.display(23213244,150,"Red","Cotton");
System.out.println("\n");
dan.display(23211300,150,"Yellow","Cotton");
}

else if(choice==3)

{
System.out.println("\tTAKE AN ORDER\n");
System.out.println("1. yes");
System.out.println("2. no");
System.out.println("\n\n");

int choice1=Integer.parseInt(JOptionPane.showInputDialog("Enter choice:"));

if(choice1==1)
{
int order=Integer.parseInt(JOptionPane.showInputDialog("Enter your order:"));System.out.println("You oredered "+ order + " piece/pieces.");
}
else if(choice==2)
{
System.out.println("You must have your order inorder to process order correctly. Thank you!.");
}
}

else if (choice==4)

{
System.out.println("\tTYPE OF PAYMENT\n");
System.out.println("1. Credit Card");
System.out.println("2. Check");
System.out.println("\n\n");

int choice2=Integer.parseInt(JOptionPane.showInputDialog("Enter choice:"));

if(choice2==1)
{
int creditnum=Integer.parseInt(JOptionPane.showInputDialog("Enter credit card number:"));
System.out.println("Credit Card Number:"+creditnum);
System.out.println("\n Note: This order will expire for two weeks if order failure to deliver.");
System.out.println("\t\tThank You!");

}
else if(choice==2)
{
int checknum=Integer.parseInt(JOptionPane.showInputDialog("Enter check number:"));
System.out.println("Check Number:"+checknum);
System.out.println("\n Note: This order will expire for two weeks if order failure to deliver.");
System.out.println("\t\tThank You!");
}
}

else if (choice==5)
{
System.out.println("ERASE ORDER");
System.out.println("You erase previous order. You may continue now.\n");
}

else if (choice==6)
{
System.out.println("\n\n");
System.out.println("Thank you for visiting DANVER's CLOTHING");
System.out.println("Your order will deliver as soon as possible. Thank You!");

}

String a=JOptionPane.showInputDialog("Enter key 'y' to continue order, if not, no order happen:");
ans=a.charAt(0);
}




}
}




/*Programmer: Danver G. Palmiano
Date Started: February 9,2009
Date Ended: February 9, 2009
Purpose: For Midterm Purposes
*/

public class Catalog {
private int shirtID;
private int price;
private String color;
private String description;


public Catalog()
{

}

public Catalog(int sID, int p, String c, String d)
{
shirtID=sID;
price=p;
color=c;
description=d;
}

void display(int sID, int p, String c, String d)
{
System.out.println("\t\tSHIRT CATALOG\n");
System.out.println("\nID num:\t\t\t"+ sID +"\nPrice:\t\t\t"+ p +"\nColor:\t\t\t "+ c +"\nDescription:\t"+d);
}

//add method
//add stock shirt
public void add(int newshirtID)
{
shirtID=newshirtID;
}

//remove method
//remove stock shirt
public void remove(int newshirtID)
{
shirtID=newshirtID;
}

}
___________________________________________________________________________

public class Payment {
private int checkNum;
private int creditcardNum;
private int expirationcardDate;

public Payment()
{
}

public Payment(int cN, int ccN, int ecD)
{
checkNum=cN;
creditcardNum=ccN;
expirationcardDate=ecD;
}

public void verifycardNum()
{
System.out.println("Your card has been verified. Thank you");
}


public void verifycheckPayment()
{
System.out.println("Your check has been verified. Thank you");
}

}

______________________________________________________________________

public class Shirt {

private int shirtID;
private int price;
private String color;
private String description;
private int stock;


public Shirt()
{
}

public Shirt(int sID, int p, String c, String d, int s)
{
shirtID=sID;
price=p;
color=c;
description=d;
stock=s;
}

//add method
public void add(int newshirtID)
{
shirtID=newshirtID;
}


//remove method
public void remove(int newshirtID)
{
shirtID=newshirtID;
}

//display item method
public void display()
{
System.out.println("Shirt IDnum:"+shirtID);
System.out.println("Price:"+price);
System.out.println("Color:"+color);
System.out.println("Description:"+description);
}

//add method
public void addstock(int newshirtID, int newprice, String newcolor, String newdescription)
{
shirtID = newshirtID;
price = newprice;
color = newcolor;
description = newdescription;
System.out.println("Shirt IDnum:"+shirtID);
System.out.println("Price:"+price);
System.out.println("Color:"+color);
System.out.println("Description:"+description);

}
//remove method
public void removestock(int newshirtID)
{
shirtID=newshirtID;
}



}
_______________________________________________________________________________

public class Customer {

private int customerID;
private String Name;
private String Address;
private int phoneNum;
private String email;


public Customer()
{

}

public Customer(int c, String n, String a, int p, String e)
{
customerID=c;
Name=n;
Address=a;
phoneNum=p;
}

public void placeOrder()
{
}
public void cancelOrder()
{
}
}
_________________________________________________________________________________

public class Order{

private int orderID;
private int totalPrice;
private String status;

public Order()
{

}

public Order(int oID, int tP, String s)
{
this.orderID=oID;
this.totalPrice=tP;
this.status=s;
}

public void placeOrder(int newOrderID)
{
orderID=newOrderID;
System.out.println("You place an Order");
}

public void removeOrder(int newOrderID)
{
orderID=newOrderID;
System.out.println("You removed your order");
}

public void submitOrder()
{
System.out.println("Thank you! Your order will deliver as soon as possible.");
}
}



}

Wednesday, February 4, 2009

THE CUBE PROGRAM

Programmer: Danver G. Palmiano
Date started: February 4, 2009
Date ended: February 5, 2009
Programmed name: Cube
Purpose: To create classes using Visibility Modifiers


public class Cube{

private double width;
private double length;
private double height;
private double volume;
private double area;

// constructor declaration

public Cube(double h, double l, double w)
{
width=h;
height=l;
length=w;
}

public Cube()
{

}

private double volume()
{

return (width*length*height);

}


private double area()
{

return (width*length);

}



public void setDimension(double newHeight, double newWidth, double newLength)
{
height=newHeight;
width=newWidth;
lenght=newLenght;
}

public void displayCube()
{
System.out.println(" Cube Dimansions");
System.out.println("Cube volume: " +volume());
System.out.println("Cube area: " +area());

}
}


//main method

class CubeTester{
public static void main(String args[]){

double l;
double w;
double h;


System.out.println("\n\n");
System.out.println("Cube with a Parameter");

Cube cube=new Cube(2,3,4);;
cube.displayCube();

System.out.println("The Cube object without a parameter");
System.out.println("\n\n");

Cube cube2=new Cube();
cube2.setDimension(l,w,h);
cube2.displayCube();
}
}



The IT 134 World

Good Day!

This blogger entitled IT 134_DDS will serve as information to everyone especially in Java Programming. This blog will help you to learn about Java. All of this will be given to you by me and MY CLASSMATES.

If you are in need or in trouble in Java just visit my blog as well as my classmates blog. If you want to be my classmate send me your blog address...

palm's_09