Tuesday, March 17, 2009

Exer no.1 (WORD REVERSER )

//Final Exercises

/*

Programmer    : Dandy A. Macaubos
ProgramName: Word Reverser 
Purpose            : To make a program that will  print  out  word  that  will be reverse  in it's  original order.
Date                  : March 17,2009
Instructor        : Dony Dongiapon
*/


 
public class reverse
{
  public static void main(String[] args)
  {
  // The normal sentence that is going to be reversed.
  String words = "Go to the main menu";
   
  String reverse2="";
  String reverse = new StringBuffer(words).reverse().toString();
  String Word1=words.substring(words.indexOf(" "),words.length());
  reverse= new StringBuffer(Word1).reverse().toString();
  String Word2=words.substring(0,words.indexOf(" "));

  reverse2=new StringBuffer(Word2).reverse().toString();


  // Print the normal string

  System.out.println("Normal : " + words);


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

Exercise no.2 (COLOR CYCLE)

/*
ProgrammerName: Dandy A. Macaubos
ProgramName : CoLor CycLe 
Purpose : to make a program that will cycle through four different colors.
Date : March 17,2009
Instructor : Dony Dongiapon
*/


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 < frame =" new" contentpane =" new">}

Exercise no.3 (Combination Lock)

/*
ProgrammerName : Dandy A. Macaubos
ProgramName       : Combination Lock 
Purpose                 : To make a program that will unlocked a combination
Date                        : March 17,2009
Instructor               : Dony Dongiapon
*/

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.white);
  pack();
   

  }
}

Exercise no.4 (ECHO)

/*
ProgrammerName: Dandy A. Macaubos
ProgramName       :  Echo
Purpose                  : to make a  program that echo's name problems
Date                        : March 17,2009
Instructor              : Dony Dongiapon
*/

import java.util.Scanner;
import java.io.*;
public class reverse {
   
 
  public static void main(String[] args) throws IOException
  {
  // The normal sentence that is going to be reversed.
  System.out.print("Enter Name: ");
  Scanner in=new Scanner(System.in);
  String words = in.nextLine();
   
  String reverse2="";
   
  String Word1=words.substring(words.indexOf(" "),words.length()).toUpperCase();
  String Word2=words.substring(0,words.indexOf(" "));
   
  // Print the normal string
  System.out.println("Normal : " + words);
 // Print the string in reversed order
  System.out.println("Reverse: " +Word2+ " "+Word1);
  }

Exercise no.5 (HELLO OBJECT)

/*
Programmer     : Dandy A. Macaubos                                                                              ProgramName : Hello Object                                                                                                        Purpose: To  create a program that prints out a greeting to an object that is  given by the user.   Date : March 17,2009                                                                                                                 Instructor : Dony Dongiapon

*/



import javax.swing.*;

public class Reverse
{

  public static void main(String args[]){

  String i=JOptionPane.showInputDialog("Enter Greeting:");
  System.out.println("Enter Greeting:"+i);
  System.out.println("\n"+i); 
  }

Friday, March 6, 2009

User-Friendly Division

 
/* Programmer : Dandy A. Macaubos
  Program name : User Friendly Division
  Date Started : March 6,2009
  Date Finished : March 7,2009
  Purpose : to make a program friendly to the user 
  Instructor : Dony Dongiapon
  Subject : IT134
*/

import java.util.Scanner;


public class DivisionPractice{

private static int quotient(int numerator, int denominator)

  {

//throws Arithmetic Exception

  if (denominator == 0)
  throw new ArithmeticException();
  return(numerator / denominator);
  }
public static void main(String args[])
  {
  Scanner input = new Scanner(System.in);
  int number1=0, number2=0, result=0;
  String snum;
  String sdiv;
  char y = ' ';

//determine if the user wants to continue or quit


  while( ( y != 'q') || ( y!= 'Q' ))

  {

  try 

  {

System.out.print(" WELCOME  TO MY USER FRIENDLY DIVISION " ) 

// asks the user to input a value of numerator

System.out.print("\nEnter the  numerator value : ");

  snum = input.next();
  y= snum.charAt(0);
  if( (y == 'q') || ( y == 'Q') )
  System.exit(-1);
  number1 = Integer.parseInt(snum);

// asks the user to input a value of divisor

System.out.print("Enter the  divisor value : ");

  sdiv = input.next();
  number2 = Integer.parseInt(sdiv);
  result = quotient(number1,number2);
  System.out.print(number1 + " / " + number2+" is "+result);
  }

//catches the Arithmetic Exception it detects


  catch (Exception e) 

  {
  System.out.println(e.toString());
  System.out.println("You can't divide "+number1+" by "+number2);
  }
  }
}
}

Monday, March 2, 2009

ITERATORS

/* Programmer : Dandy A. Macaubos
  Program name : Iterators
  Date Started : March 2,2009
  Date Finished : March 2,2009
  Purpose : Iterate through elements Java ArrayList using Iterator
  Instructor : Dony Dongiapon
  Subject : IT134
*/

import java.util.ArrayList;
import java.util.Iterator;
 
public class IterateThroughArrayListUsingIterator {
 
  public static void main(String[] args) {
 
  //create an ArrayList object
  ArrayList arrayList = new ArrayList();
 
  //Add elements to Arraylist
  arrayList.add("1");
  arrayList.add("2");
  arrayList.add("3");
  arrayList.add("4");
  arrayList.add("5");
 
  //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 would be
Iterating through ArrayList elements...
1
2
3
4
5
*/

/*source : http://www.java-examples.com/iterate-through-elements-java-arraylist-using-iterator-example


What I did I learned in this topic?

I learned that before you can access a collection through an iterator, you must obtain one. 
Each of the collection classes provides an iterator( ) method that returns an iterator to the start of the collection.
By using this iterator object, you can access each element in the collection, one element at a time.

*/

Sunday, February 8, 2009

SET OF CLASSES

/* Programmer : Dandy A. Macaubos

  Program name : Direct Clothing Case Study
  Date Started : February 7,2009
  Date Finished : February 8,2009
  Purpose : To give solution to direct clothing case study
  Instructor : Dony Dongiapon
  Subject : IT134
*/

import java.util.Scanner;

public class ClothingTester{ 
 
 public static void main(String args[]){ 
 
 Scanner input= new Scanner(System.in); 
 Shirt myShirt=new Shirt();
 System.out.println("Welcome:\n\n Direct Clothing!!\nPlease Choose on our Catalog?");
 myShirt.displayCatalog(); 
 Scanner input= new Scanner(System.in); 
 System.out.println("Do you have your choice ?"); 
 if (input=='y') 
 { 
 System.out.println("Enter ShirtID:"); 
 String ID=input.nextLine();
 myShirt.setShirtID(ID); 
 
 System.out.println(); 
 System.out.println("Enter Price:"); 
 double cprice=input.nextDouble(); 
 myShirt.setPrice(cprice); 
 
 System.out.println();
 System.out.println("Enter Color:"); 
 String ccolor=input.nextLine(); 
 myShirt.setColor(ccolor);  
 ]
 System.out.println(); 
 System.out.println("Enter Quantity:"); 
 int cquantity=input.nextInt(); 
 myShirt.setQuantity(cquantity); 
 
 System.out.println(); 
 System.out.println("Enter shirt Description:"); 
 String cdescription=input.nextLine(); 
 myShirt.setDescription(cdescription); 
 
 System.out.println(); 
 System.out.println("Shirt was chosen successfully.\n\n\t Thank You!!!");
  } 
 else 
 { 
 System.out.println("Ok"); 
 } 
  } 
}

________________________________________________________________

public class Customer{

 //variable

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


 //constructor 

 public Customer(){
 }

 //method 

 public void customergreetings(String newname)
 {
 name=newname; 

 }

 public void customerprofile(String newname, int newid, String newaddress,int newphonenumber, String newemailaddress)
 {
 
 name=newname;
 address=newaddress;
 customerid=newid;
 phonenumber=newphonenumber;
 emailaddress=newemailaddress;
 
 System.out.println("P_R_O_F_I_L_E");
 System.out.println("Name: "+name+ "\nCustomer ID: "+customerid+"\nAddress:"+address+"\nPhone Number: "+phonenumber+"\nE-mail address: "+emailaddress);
 }
}

____________________________________________________________________________________

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;
 }
 
 public String removestock()
 { 
 System.out.println("The Shirt with an ID\t\s getShirtID()); 
 System.out.println("was successfully remove.Thank you!!!");
 }
}
__________________________________________________________________________________________

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

 public void setTotaltorderprice(double newtotalorderprice)
 { 
 double totalorderprice=newtotalorderprice;
 }
 
 public double getTotaltorderprice()
 { 
 return totalorderprice;
 }

 public void setStatus(String newstatus)
 { 
 String status=newstatus;
 }
 public String getStatus()
 { 
 return status;
 }
}

_____________________________________________________________

public class FormofPayment{ 
 
 //variable

 private String checknumber; 
 private String cardnumber; 
 private String expirationDate;
 
 public FormofPayment(String check,String card,String date)

 //constructor{
 
 checknumber=check; 
 cardnumber=card; 
 expirationDate=date; 
 }
 //method
 public void setChecknumber(String check){
 
 checknumber=check;
 } 

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

 cardnumber=card;
 } 
 
 public String getCardnumber(){ 

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

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


 
 public class Catalog {
 public void displayCatalog(){ 
 System.out.println("ShirtID:252-22\nPrice:25,000\nColor:Black \nQuantity:5\nDescription:Beautiful"); 
 System.out.println("ShirtID:252-54\nPrice:90,000\nColor:Pink\nQuantity:1\nDescription:Nice");
 }
}

____________________________________________________________