Saturday, March 21, 2009

Exercise5-Hello

/* Programmer: Norfe R. Gregorio
* Program name:Hello
* Subject: IT134_Computer Programming 3
* Instructor: Mr. Dony Dongiapon* Date Started: 03/14/09
* Date Finished: 03/19/09* Purpose: Will print the greeting that is given by the user*/
import java.*;
public class HelloTester{public static void main(String args[]){
String greet;Scanner scan=new Scanner(System.in);
System.out.println("Enter Your Greeting:");
greet=scan.nextLine();Hello h=new Hello(greet);System.out.println(h.echo());}}

Exercise4-NameEcho

/* Programmer: Norfe R. Gregorio * Program name: NameEcho * Subject: IT134_Computer Programming 3 * Instructor: Mr. Dony Dongiapon * Date Started: 03/16/09 * Date Finished: 03/19/09 * Purpose: To write a program that will asks for user's * name and then writes it back with the first name * as entered, and the second name all in capital letters. */
import java.*;
public class NameEcho{ public static void main(String[] args)throws StringIndexOutOfBoundsException{ try{ Scanner scan = new Scanner(System.in); System.out.println("Enter your name:"); String name = scan.nextLine(); int Big=name.indexOf(" "); int gib=Big++; String output = name.substring(0,Big); String name2=name.substring(gib,name.length()); System.out.print(output+" "+name2.toUpperCase()); } catch(StringIndexOutOfBoundsException index){ System.err.printf("No more data."); } }}

Exercise3-CombinationLock

/*Programmer: Norfe R Gregorio *Date started: March 13, 2009 *Date ended: March 19, 2009 *Title:CombinationLock *Description:a program tht will result other frame color if the user will click three buttons that the program have*;
public class CombinationLock extends JFrame {
public static void main (String [] args) { new CombinationLock().setVisible(true); }
public CombinationLock () {
Container ComLock = getContentPane(); cp.setLayout(new FlowLayout());
ComLock.add(new JButton("0")); ComLock.add(new JButton("1")); ComLock.add(new JButton("2")); ComLock.add(new JButton("3")); ComLock.add(new JButton("4")); ComLock.add(new JButton("5")); ComLock.add(new JButton("6")); ComLock.add(new JButton("7")); ComLock.add(new JButton("8")); ComLock.add(new JButton("9")); ComLock.setBackground(Color.white); pack();
}}

Exercise2-ColorCycle

/* Programmer: Norfe R. Gregorio* Program name: Color Cycle* Subject: IT134_Computer Programming 3* Instructor: Mr. Dony Dongiapon* Date Started: 03/14/09 * Date Finished: 03/19/09* Purpose:A program that will change the color of the background in Frame when you click the botton*/
import java.*;
public class ColorCycle extends JFrame implements ActionListener {
private WindowTerminator wincolor = new WindowTerminator(); private JButton red, Green, Blue, Gray, Violet; private Container color;
public ColorCycle( ) { setSize(200,200); setLocation(100,100); setTitle(getClass().getName());
addWindowListener(wincolor);
red = new JButton("Red"); green = new JButton("Green"); blue = new JButton("Blue"); gray = new JButton("Gray"); Violet = new JButton("Violet"); red.addActionListener(this); green.addActionListener(this); blue.addActionListener(this); gray.addActionListener(this); Violet.addActionListener(this); color = getContentPane(); color.setBackground(Color.white); color.setLayout(new FlowLayout()); color.add(red); color.add(Green); color.add(Blue); color.add(Gray); color.add(Violet); show(); }
public void actionPerformed(ActionEvent e) {
JButton s = (JButton) e.getSource();
if ( s == Red) cp.setBackground(Color.Red); else if ( s == Green) cp.setBackground ( Color.Green); else if ( s == Blue) cp.setBackground ( Color.Blue); else if ( s == Gray) cp.setBackground ( Color.Gray); else if ( s == Violet) cp.setBackground ( Color.Violet);

color.repaint(); }
public static void main (String[] args) {
JFrame f = new ColorCycle(); }
}
class WindowTerminator extends WindowAdapter {
public void windowClosing (WindowEvent e) { System.exit(0); }}

Thursday, March 19, 2009

Exercise1-Reverse

/* Programmer: Norfe R. Gregorio* Program name: Reverse* Subject: IT134_Computer Programming 3* Instructor: Mr. Dony Dongiapon* Date Started: 03/14/09 * Date Finished: 03/19/09* Purpose: The purpose of this proggram is to read the entered string of the user in reverse form*/
import java.util.*;public class reverse{ public static void main(String[] args){sring val;string value; Scanner scan = new Scanner(System.in); System.out.print("Please enter the word to be rverse: "); String value = scan.nextLine(); StringTokenizer val = new StringTokenizer(value); while(val.hasMoreTokens())
{ String element = tokens.nextToken(); StringBuffer buffer = new StringBuffer(word); element = buffer.reverse().toString(); System.out.print(word+" "); } }}

Monday, March 16, 2009

User-Friendly Division

import java.util.*;

public class UserFriendlyDivision{
public static double quotient(double num, double den)
{
return num/den;}
public static void main(String args[]){
Scanner scan=new Scanner(System.in);

String exit="quit";
char x=exit.charAt(0);
double num=0;
double den=0;
String ask="quit";

while(x!='q'){
if(x != 'Q'){

try{
System.out.println("Enter the numerator:");
if((scan.next().charAt(0)=='q')||(scan.next().charAt(0)=='Q')){
x=scan.next().charAt(0);
}else{
num=scan.nextFloat();
System.out.println("Enter the denomenator:");
den=scan.nextFloat();
double result=quotient(num,den);
System.out.println(num+"/"+den+" is "+result);
}
}
catch(ArithmeticException arerr)
{
System.err.println("You can't divide "+num+" by "+den);
}

catch(InputMismatchException inputerr)
{
System.err.println("You enter bad data.\nPlease try again.");
}
catch(IndexOutOfBoundsException index)
{
System.err.println("");
}

}else{
x='q';
}
}

}
}

Saturday, March 7, 2009

arraylist iterator

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

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

al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");

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

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

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

}

/*things I've learned in this exercise:

Iterator takes the place of Enumeration in the Java collections framework.

  • Iterators allow the user to remove elements from the underlying collection during the iteration.
  • Method names have been improved in this Interface.

*/

Sunday, February 8, 2009

Objects in the Direct Clothing Case Study

/*Programmer: Norfe Gregorio
*Programme Name: Customer
*Subject: IT134 *Instructor: Mr. Dony Dongiapon
*Date stated: 02/08/09
*Date end: 02/08/09 */
public class Customer{
Int CustomerID;
String Name;
String Address;
int phoneNumber;
String EmailAddress;
public Customer(int CID, string N, String A, int PN D, string EMA)
{
this.CustomerID=CID;
this.Name=N;
this.Address=D;
this.phoneNumber=PN;
this.EmailAddress=EMA;
} Public shirt()
{ }
public int placeOrder()
{ }
public int cancelOrder()
{ }
public String displayInformation()
{
return String.format(CustomerID,Name,Address,phoneNumber,EmailAddress);
}
}
***************************************************************************************
/*Programmer: Norfe Gregorio
*Programme Name: Order
*Subject: IT134
*Instructor: Mr. Dony Dongiapon
*Date stated: 02/08/09
*Date end: 02/08/09 */
public class Order
{
Int OrderID;
double TotalPrice;
String status;

public Order(int OID, double TP, String S)
{
this.OrderID=OID;
this.TotalPrice=TP;
this.status=S;
}
public int addOrder()
{ }
public int removeStock()
{ }
public String displayInformation()
{
eturn String.format(OrderID,TotalPrice,status);
}

***************************************************************************************
/*Programmer: Norfe Gregorio
*Programme Name: shirt
*Subject: IT134
*Instructor: Mr. Dony Dongiapon
*Date stated: 02/08/09
*Date end: 02/08/09 */
public class Shirt
{
Int shirtID;
ouble price;
String color;
String description;
int quantityInStock;
public Shirt(int SID, double P, String C, String D, int QIS)
{
this.shirtID=SID;
this.price=P;
this.color=C;
this.description=D;
this.quantityInStock=QIS;
}
Public shirt()
{ }
public int addStock()
{
return quantityInStock=quantityInStock+stock;
}
public int removeStock()
{
return quantityInStock=quantityInStock-stock;
}
public String displayInformation()
{
return String.format(shirtID,price,color,description,quantityInStock);
}
}
***************************************************************************************
/*Programmer: Norfe Gregorio
*Programme Name: FormofPayment
*Subject: IT134
*Instructor: Mr. Dony Dongiapon
*Date stated: 02/08/09
*Date end: 02/08/09 */
public class FormofPayment{
private int checkno;
private int creditcardno;
private String expiredate;

public FormofPayment(int CN,int NCN,String ED)
{
this.checkno=CN;
his.cardno=NCN;
this.expiredate=ED; }
public String verifyCardno() {
}
public String verifyChekPayment() {
}
}

Wednesday, February 4, 2009

Cube

/*Programmer: Norfe Gregorio
 *Programme Name: Cube
 *Subject: IT134
 *Instructor: Mr. Dony Dongiapon
 *Date stated: 02/04/09
 *Date end: 02/04/09
 */


public class Cube{

    private double width;
    private double length;
    private double height;
    

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

    public Cube()
    {
        
    }

    private double volume()
    {

        return width*length*height;    
        
    }


    private double area()
    {
        
        return width*length;    
        
    }
    

    public void setDimension(double nw, double nh, double nl)
    {
        this.width=nw;
        this.height=nh;
        this.length=nl;
    }

    public String displayCube()
    {
        return String.format(volume()+" and "+area());
        
    }
}
    

CubeTester

/*Programmer: Norfe Gregorio
 *Programme Name: CubeTester
 *Subject: IT134
 *Instructor: Mr. Dony Dongiapon
 *Date stated: 02/04/09
 *Date end: 02/04/09
 */
import java.util.Scanner;

public class CubeTester{

    public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    Cube myCube1=new Cube(3,3,3);
    Cube myCube2=new Cube();

System.out.println("The volume and area of a cube with width, height, and length is equal to 3: "+myCube1.displayCube());
System.out.println("Please fill in the following question.");
System.out.print("Enter width value: ");
double w=scan.nextDouble();
System.out.print("Enter height value: ");
double h=scan.nextDouble();
System.out.print("Enter length value: ");
double l=scan.nextDouble();

myCube2.setDimension(w,h,l);
System.out.println("The volume and area of a cube with width, height, and length is being entered by the user are : "+myCube2.displayCube());


}
}