Friday, March 20, 2009

EXER 3
/*Programmer: Tomarocon, Rolando
Program Name: Combination Lock
Date Finished: March 20, 2009
Program Purpose: To be able to make a program in which in a frame with ten buttons, labeled 0 through 9. If the user exit the program, he/she must click on the correct three buttons in order. 
*/
import java.awt.*;
import javax.swing.*;

public class CombinationLock extends JFrame
{
  public static void main (String [] args)
  {
  new CombinationLock().setVisible(true);
  }

  public CombinationLock ()
  {
  Container cp = getContentPane();
  cp.setLayout(new FlowLayout());

  cp.add(new JButton("a"));
  cp.add(new JButton("b"));
  cp.add(new JButton("c"));
  cp.add(new JButton("d"));
  cp.add(new JButton("e"));
  cp.add(new JButton("f"));
  cp.add(new JButton("g"));
  cp.add(new JButton("h"));
  cp.add(new JButton("i"));
  cp.add(new JButton("j"));
  cp.setBackground(Color.black);
  pack();
}

}

*******************************************************************************

Thursday, March 19, 2009

helloOBJECT
/*Exercise 5
 **Name of Program:helloObject
 *Programmer name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:To enter words then it will reverse.


import java.util.Scanner; 
public class helloObject 

  public static void main(String[] args)  
  { 
  String greetings; // Used for the input string. 
  Scanner input=new Scanner(System.in); 
  System.out.println("pls.........Enter ur Greeting:"); 
  greetings=input.nextLine(); 
  System.out.println(greetings); 
  } 
}
*/OUTPUT:

heloo

heloo

*/
===================================================================
NAME ECHO
/*Exercise 4
 **Name of Program:nameEcho
 *Programmer name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:Enter 2 words then the second word will be capital letter.

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


public class nameEcho{
public static void main(String[] args) throws IOException// main method using catch Exceptions
{
String b;//first input string 
String c;//second input string

String a=JOptionPane.showInputDialog("Enter your Name: ");//ask input from the user

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 string in normal and Uppercase

}
}


*/OUTPUT:

rolando tomarocon

rolando TOMAROCON

*/

==================================================================

WORD REVERSE
/*Exercise 1
 **Name of Program:Word Reverse
 *Programmer name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:To enter a word that will reverse from the first index to last.
 */

 
public class wordReverse
{
  public static void main(String[] args)
  {
  // The normal sentence that is going to be reversed.
  String words = "Tomarocon, Rolando";
   
  // To reverse the string we can use the reverse() method in the 
  // StringBuffer class. The reverse() method returns a StringBuffer so
  // we need to call the toString() method to get a string object.
  String reverse = new StringBuffer(words).reverse().toString();
   
  // Print the normal string
  System.out.println("Normal : " + words);
  // Print the string in reversed order
  System.out.println("Reverse: " + reverse);
  }
}
 
/* OUTPUT:

Normal : Tomarocon, Rolando
Reverse: odnaloR ,nocoramoT
*/

------------------------------------------------------------------------------
COLOR CYCLE
/*Exercise 2
 *Name of Program:Color Cycle
 *Programmers name:Tomarocon, Rolando
 *Date:March 19,2009
 *Purpose:When you enter the button then the color of the background will change.depend to the color
 */

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 colorcycle extends JPanel implements ActionListener {
private static boolean USE_CROSS_PLATFORM_UI = false;
int buttonLabelIndex = 0;
String buttonLabels[] = { "green", "yellow", "pink", "Red", "gray","black","white","orange","blue"};
Color buttonColors[] = { Color.GREEN, Color.YELLOW, Color.PINK, Color.RED,Color.GRAY,Color.BLACK,Color.WHITE,Color.ORANGE,Color.BLUE,};

JButton button;
public colorcycle() {
super(new BorderLayout());

button = new JButton(buttonLabels[buttonLabelIndex]);
// 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 < frame =" new" contentpane =" new">

Friday, March 13, 2009

UserFriendlyDivision by:Tomarocon Rolando

import java .util.*;
import java.io.*;
public class DivisionPractice
{
 //this will compute the numerator and divisor 
public static int quotient(int x ,int y,int div)throws ArithmeticException{

public static void main (String[] args )
{
Scanner scan = new Scanner(System.in);
char a='m';
  do{
System.out.print("Enter numerator>:");
x = scan.nextInt();
  char x=n.charAt(0);
  try{
  //program will exit if x= 'q'or'Q'
  if(x=='q'||x=='Q'){
  System.exit(0);
  else{

System.out.print("Enter divisor>:");
  }
y = scan.nextInt();
  char y=d.charAt(0);
}
  //program will exit if y= 'q' or 'Q', 
  if(y=='q'||y=='Q'){
  System.exit(0);
  }else{
divide();
}

div = x / y;
System.out.println("The divide is >:" + div);
return div;

}
}


 catch(NumberFormatException numberFormat){
  //print the error message 
  System.err.printf("\nIncompatible type.\nPlease try again.");
  }
  catch(ArithmeticException arithmetic){
  //convert the String value and store in num
  num=Integer.parseInt(n);
  //print the error message
  System.err.printf("\nYou can't divide "+num+" by 0");
  }

 }

Tuesday, March 3, 2009

Iterators and ArrayList

/*
Programmer:Tomarocon, Rolando D.
Date:March 4,2008
Purpose:To learn about iterators.
*/

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

public class IterateThroughArrayListUsingIteratorExample {

public static void main(String[] args) {

//create an ArrayList object
ArrayList arrayList = new ArrayList();

//Add elements to Arraylist
arrayList.add("L");
arrayList.add("M");
arrayList.add("N");
arrayList.add("O");
arrayList.add("P");

//get an Iterator object for ArrayList using iterator() method.
Iterator itr = arrayList.iterator();

//use hasNext() and next() methods of Iterator to iterate through the elements
System.out.println("Iterating through ArrayList elements...");
while(itr.hasNext())
System.out.println(itr.next());

}
}

/*
Output
Iterating through ArrayList elements...
L
M
N
O
P
*/

What I learned in this exercise:

* This Java Example shows how to iterate through the elements of java
ArrayList object using Iterator.
* Use iterator() method to get an iterator object for arraylist
*ArrayList provides additional methods to manipulate the array that actually stores the elements.
*Iterator are usefull in making a programming.

Monday, February 9, 2009

Direct Clothing

/**Programmer:Tomarocon Rolando
 * Purpose:To apply Knowledge we learn from OOP
 *Date :Feb 9,2009
 *Instructor:Dony Dongiapon
 */

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


public Catalog()
{

}

public Catalog(int s, int pri, String col, String des)
{
shirtID=s;
price=pri;
color=col;
description=des;
}

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

}

------------------------------------------------------------------------------------------

public class Customer{

 private int customerid;
 private String name;
 private String address;
 private int phonenumber;
 private String emailaddress;


 //constructor for customer

 public Customer(){
 }


 public void customerprofile(String newname, int newid, String newaddress,int newphonenumber, String newemailaddress)
 {
 name=newname;
 address=newaddress;
 customerid=newid;
 phonenumber=newphonenumber;
 emailaddress=newemailaddress;
 }
 
public void placeOrder()
{
}
public void cancelOrder()
{
}



}
------------------------------------------------------------------------------

public class Order{ 
 
 private String orderID; 
 private double totalprice; 
 private String status;
 
 public Order(){
 }
 public void orderShirt(String neworderID,double newtotalorderprice,String newstatus)
 { 
 
 //constructor for order
 
 orderID=neworderID;
 totalorderprice=newtotalorderprice; 
 status=newstatus;
 }
 public void setOrderID(String neworderID)
 {
 String orderID=neworderID;
 }
 public String getOrderID()
 { 
 return orderID;
 }
 //method for order

 public void setTotaltorderprice(double newtotalorderprice)
 { 
  totalorderprice=newtotalorderprice;}
 public double getTotaltorderprice(){ 
 return totalorderprice;
 }
 public void setStatus(String newstatus)
 { 
 status=newstatus;}
 public String getStatus()
 { 
 return status;
 }
}
--------------------------------------------------------------------------

public class Shirt {
 
 //variable

 private String shirtID;
  private double price;
  private String color; 
 private int quantity;
  private String description;

 public Shirt(){ 
 }
 public Shirt(String newshirtID,double newprice,String newcolor, int newquantity,String newdescription){ 

 //constructor

 shirtID= newshirtID; 
 price=newprice; 
 color= newcolor; 
 quantity=newquantity; 
 description=newdescription;
 }
 //method 
 
 public void setShirtID(String newshirtID){ 
 shirtID= newshirtID; }
 public String getShirtID()
 { 
 return shirtID;} 
 public void setPrice(double newprice)
 { 
 price=newprice;}
 public double getPrice()
 { 
 return price;}
 public void setColor(String newcolor)
 {
  color= newcolor;}
 public String getColor()
 {
  return color;}
 public void setQuantity(int newquantity)
 {
  quantity=newquantity;}
 
 public int getQuantity()
 { 
 return quantity;}

 public void setDescription(String newdescription)
 { 
 description=newdescription;}
 public String getDescription()
 { 
 return description;}
 
 //add method
public void add(int newshirtID)
{
shirtID=newshirtID;
}


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

public class FormofPayment{ 


 private String checknumber; 
 private String cardnumber; 
 private String expirationDate;
 
 public FormofPayment(String c,String ca,String d)

 //constructor{
 
 checknumber=c; 
 cardnumber=ca; 
 expirationDate=d; 
 }
 //method
 public void setChecknumber(String check){
 
 checknumber=c;
 } 

 public String getChecknumber(){
 
 return checknumber;
 }
 
 public void setCardnumber(String card){ 

 cardnumber=ca;
 } 
 
 public String getCardnumber(){ 

 return cardnumber;
 }
 
 public void setExpirationdate(String date){ 
 expirationDate=d;
 } 

 public String getExpirationdate(){ 
 returnexpirationDate;
 }
 public void Dispalymessage()
 { 
 System.out.println("Your checknumber is:%s");
 }
}

Wednesday, February 4, 2009

Programming 3

/*Programmer:Tomarocon,Rolando
Program Title:Cube
Date:Feb 4, 2009
Purpose: To create a source code of a cube*/

public class Cube{

private double cubewidth;
private double cubelength;
private double cubeheight;
private double cubevolume;
private double cubearea;

  public Cube(double width, double height, double length)
{
this.cubewidth=width;
this.cubeheight=height;
this.cubelength=length;
}

 public Cube(){
}
private double volume(){
return (cubewidth*cubelength*cubeheight); 
}
private double area(){
return (cubewidth*cubelength); 
}
public void setDimension(double newwidth, double newheight, double newlength)
{
this.cubewidth=newwidth;
this.cubeheight=newheight;
this.cubelength=newlength;
}
public String displayCube(){
return String.format(volume()+" and "+area());

  }
}


/*Programmer:Tomarocon.Rolando
Program Title:CubeTester
Date:Feb 4, 2009

Purpose: To test the cube*/


public class CubeTester{
public static void main(String[] args){
   
    Cube myCube1=new Cube(2,2,2);
       myCube.displayCube();
  cube myNewCube = new cube();
  myNewCube.displayCube();


}
}