Thursday, March 19, 2009

Exer # 2

/*
Programmer Name: Jhovan C. Besas
Program Name: Hello Object
Purpose: To enhance how to run a program that will change it's background
Date: March 19,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.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
public class MainClass 

{ public static void main(String args[]) 

{  
 JFrame f = new JFrame("JColorChooser Sample");
  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  final JButton button = new JButton("Pick to Change Background");

  ActionListener actionListener = new ActionListener()

 { public void actionPerformed(ActionEvent actionEvent) 

{  
 Color initialBackground = button.getBackground();
  Color background = JColorChooser.showDialog(null, "JColorChooser Sample", initialBackground);

  if (background != null)

 { button.setBackground(background);

  }
  }

  };

  button.addActionListener(actionListener);

  f.add(button, BorderLayout.CENTER);
  f.setSize(300, 200);
  f.setVisible(true);

  }
}

Wednesday, March 18, 2009

Exer # 1

/*Programmer Name: Jhovan C. BesasProgram Name: Hello ObjectPurpose: To enhance how to run a program that will reverse the outputDate: March 18,2009Instructor: Dony Dongiapon*/ 


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 a 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:  vhan d'best

Input in Normal Form: vhan d'best
Reverse input: nhav tseb'd

Exerc# 5

/*
Programmer Name: Jhovan C. Besas
Program Name:  Hello Object
Purpose: To enhance how to run a program the name echo problems
Date: March 18,2009
Instructor: Dony Dongiapon
*/

import java.util.Scanner;


public class HelloObject {

  public static void main(String[]args) {
  Scanner a = new Scanner(System.in);
  String greeting;

  System.out.print("Enter your Greeting: ");

//it is where the greeting that is printed by the object given by the user.

  greeting = a.nextLine();
  System.out.println("\n");
  System.out.print(greeting);
  System.out.println();
  }
   
   

}

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

//Output of this program:

Enter Greeting: 

Hello World!

Hello World!

Exer # 4

/*
Programmer Name: Jhovan C. Besas
Program Name: Name Echo
Purpose: To enhance how to run a program the name echo problems
Date: March 18,2009
Instructor: Dony Dongiapon
*/


import java.util.Scanner;
import java.io.*;
public class Echo {  

  public static void main(String[] args) throws IOException {

  System.out.print("Enter a 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(" "));  
 System.out.println("Normal : " + words);
 System.out.println("Reverse: " +Word2+ " "+Word1); 
 }

}



Sunday, March 8, 2009

User-Friendly Division by: Jhovan C. Besas

/**Programmer Name: Besas, Jhovan C.
Program Name: User-Friendly Division
Purpose: To apply knowledge that i have learned in OOP.
Date: March 8, 2009
Subect: Computer Programming 3
Instructor: Dony Dongiapon**/


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("\nEnter the value of numerator: ");
         snum = input.next();
         y= snum.charAt(0);
         if( (y == 'q') || ( y == 'Q') )
        System.exit(-1);
        number1 = Integer.parseInt(snum);
        System.out.print("Enter the value of the divisor: ");
        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);
         }
       }
}
}

Tuesday, March 3, 2009

Arraylist and Iterators

/* Programmer: Besas, Jhovan
  Program name: Arraylist with Iterators
  Subject: IT134A_Computer Programming 3
  Instructor: Mr. Dony Dongiapon
  Date Started: March 2,2009
  Purpose: To  implement a java code that deals with ArrayList and Iterators.***/


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

public class iterators {
public static void main(String args[]) {
ArrayList vhan = new ArrayList();

vhan.add("Yamaha");
vhan.add("Suzuki");
vhan.add("Isuzu");
vhan.add("Firari");
vhan.add("Mitsubishi");
vhan.add("Honda");

System.out.print("Original contents of vhan: ");
Iterator mine = vhan.iterator();
while (mine.hasNext())
{
String element = mine.next();
System.out.print(element + " ");
}

System.out.println();

ListIterator jhoy = vhan.listIterator();
while (jhoy.hasNext())
{
String element = jhoy.next();
jhoy.set(element + "+");
}

System.out.println("Size of vhan after additions: " + vhan.size());
vhan.remove(1);

{
System.out.println("Size of vhan after deletions: " + vhan.size());
System.out.println("Contents of vhan: " + vhan );
}
}
}

Things I learned in this exercise:

  • Every element can be accessed directly by specifying
    its position (index).
  • ArrayList used to demonstrate several Collection interface capabilities. 

  • The implementation of array list is more comprehensive compared to array.

Sunday, February 8, 2009

Objects in the Direct Clothing Case Study

/**Programmer Name: Besas, Jhovan C.
   Program Name: Direct Clothing Case Study
   Purpose: To apply knowledge that i have learned in OOP.
   Date: February 8, 2009
   Subect: Computer Programming 3
   Instructor: Dony Dongiapon**/

public class Customer{ Int CustomerID; String Name; String Address; int phoneNumber; String EmailAdd;

public Customer(int newcustomerID, string newname, String newAddress, int newPhoneNumber, string newEMail) { this.CustomerID=newcustomerID; this.Name=newname; this.Address=newAddress; this.phoneNumber=newPhoneNumber; this.EmailAddress=newEMail; }
public String displayInformation() { return String.format(CustomerID,Name,Address,phoneNumber,EmailAdd); } }


____________________________________________________________
public class Shirt { Int shirtID; double price; String color; String Sdescription; int Squantity;
public Shirt(int newID, double newprice, String newCcolor, String newdescription, int newquantity) { shirtID=newID; price=newprice; color=newCcolor; description=newdescription; quantity=newquantity; } Public shirt() { }public int addStock() { return quantity=quantity+stock; }
public int removeStock() { return quantity=quantity-stock; }
public String displayInformation() { return String.format("The following are the current information of the shirt"shirtID,price,color,description,quantity); } }


___________________________________________________
public class Order{ Int OrderID; double TotaPrice;; String status; public Order(int newID, double newTotalPrice, String newStatus) { OrderID=newID; TotalPrice=newTotalPrice; status=newStatus; }
public String displayInformation() { return String.format(OrderID,TotalPrice,status); } }