Thursday, March 19, 2009

EXER2-COLOR CYCLE

/*Program Name: Gezelle Re-ann Mandabon
Program Name: Color Cycle
Date-Started: 03-18-09
Date-Ended: 03-20-09
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class ColorCycle extends JFrame
implements ActionListener {

private WindowTerminator wt = new WindowTerminator(); // Code below
private JButton red,blue, green, gray; // the JButtons which will cause the background colors to change
private Container cp; // our contentpane

public ColorCycle( ) {
setSize(250,205);
setLocation(100,100);
setTitle(getClass().getName());


addWindowListener(wt);

green = new JButton("Red");
blue = new JButton("Green");
gray = new JButton("Blue");
red = new JButton("Gray");
green.addActionListener(this);
blue.addActionListener(this);
gray.addActionListener(this);
red.addActionListener(this);
cp = getContentPane();
cp.setBackground(Color.black);
cp.setLayout(new FlowLayout());
cp.add(green);
cp.add(blue);
cp.add(gray);
cp.add(red);

show();
}


public void actionPerformed(ActionEvent e) {

JButton s = (JButton) e.getSource(); //get the source of the event

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 == red) cp.setBackground ( Color.red);


cp.repaint();
}


public static void main (String[] args) {

JFrame f = new ColorCycle();
}

}

class WindowTerminator extends WindowAdapter {

public void windowClosing (WindowEvent e) {
System.exit(0);
}
}

EXER3-Combination Lock

/*Program Name: Gezelle Re-ann Mandabon
Program Name:
Date-Started: 03-18-09
Date-Ended: 03-20-09
*/

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();
}
}

EXER5-HELLO

/*Program Name: Gezelle Re-ann Mandabon
Program Name: Hello
Date-Started: 03-18-09
Date-Ended: 03-20-09
*/

import java.util.Scanner;
public class Hello
{
public static void main(String[] args)
{
String greetings; // Used for the input string.
Scanner input=new Scanner(System.in);
System.out.println("Enter Greeting:");
greetings=input.nextLine();
System.out.println();
System.out.println(greetings);
}
}

sample output:

Enter Greeting: Hello YHANG!

                             hello YHANG!

Exer4-Name Echo

/*Program Name: Gezelle Re-ann Mandabon
  Program Name: Name Echo
  Date-Started: 03-18-09
  Date-Ended: 03-20-09
*/    

import java.util.*;  

import java.io.*;  

public class nameEcho 
{  
      public static void main(String[] args) throws IOException  
     {  
     String yourName; 
     String firstName; 
     String lastname; 
     System.out.println("Enter your name:");  
     Scanner input = new Scanner(System.in);  
     yourName = input.nextLine();  
     firstName = yourName.substring(0,yourName.indexOf(" "));  
     lastname= yourName.substring(yourName.indexOf(""),
     yourName.length()).toUpperCase();  
     System.out.println();  
     System.out.print(firstName); 
     System.out.print(lastname); 
     System.out.println();  
     }  

sample output: 

Enter your name:     Yhang-yhang
                                    YHANG-YHANG
Process completed.

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


   

EXER1-Word Reverse

/*Program Name: Gezelle Re-ann Mandabon
  Program Name: Word Reverser
  Date-Started: 03-18-09
  Date-Ended: 03-19-09
  Purpose: To be able to Reverse the wor and manipulate Swing.....
*/

import javax.swing.*;

public class WordReverse 
{
    public static void main(String[] args) 
    {
      String input;         
      String reversed;     

      input = JOptionPane.showInputDialog(null, "Enter a string"); 
      reversed = "";
      for (int i=0; i reversed = input.substring(i, i+1) + reversed;
      }
      JOptionPane.showMessageDialog(null, "Reversed:\n" + reversed);
  }
}

sample output

Enter a String:    Go to the main menu
                              unem niam eht ot oG


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



Tuesday, March 10, 2009

User-Friendly Division

/*Programmer Name:Gezelle Re-ann B. Mandabon
Program Name: User-Friendly Division
Date-Started: 03-08-09
Date-Ended: 03-10-09
Description: This program will calculate the quotient, then
if you enter any character it will return an error
message.If the user will press q it will exit.
Purpose: To know more about Exception
*/


import java.util.Scanner;
import java.util.InputMismatchException;

public class UserFriendlyDivision
{
public static int quo(int num,int den)throws ArithmeticException
{
return num/den;

}
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
int den;
int result;
char exit='y';
while (exit=='y')
{

try
{
System.out.print("Enter the numerator:");
num=input.nextInt();
System.out.print("Enter the denominator:");
den=input.nextInt();
result=quo(num,den);
System.out.println(num+"/"+den+" is " +result);
System.out.println("");
}

catch(InputMismatchException num)
{
System.err.printf("\n Exception %s\n");
System.out.println("Please try again");
}

catch(ArithmeticException den)
{
System.err.printf("\n Exception %s\n");
System.out.println("You cannot divide "+num+"by "+den);
}

System.out.println("Enter the numerator:");
}

}
}

Saturday, March 7, 2009

ArrayListIterator

public class ArrayListIterators
{

public ArrayListIterators()
{

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("LYHN");
al.add("JHONG");
al.add("MHING");
al.add("JHEN");
al.add("PHAU");
al.add("YHANG");

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("List Backwards: ");
while (litr.hasPrevious())
{
String element = litr.previous();
System.out.print(element + " ");
}
}
}
}

Sunday, February 8, 2009

IT134_Direct Clothing Case Study

/*Programmer Name: Gezelle Re-ann B. Mandabon
Program Name: Direct Clothing Case Study (Catalog)
Date Started: 02-07-2009
Date Finished: 02-08-2009
Program PUrpose: to be able to make the case study solution for direct clothing
*/

public class Catalog
{

//variable declaration

private int shirtid;
private double price;
private String color;
private String description;
private int quantityinstock;

//costructor declaration

public Catalog()

{
}

public Catalog(int s, double p, String c, String d, int q)

{
shirtid=s;
price=p;
color=c;
description=d;
quantityinstock=q;
}

//method declaration

public void addashirt(int newshirtid, double newprice, String newcolor, String
newdescription, int newquantityinstock)

{
shirtid=newshirtid;
price=newprice;
color=newcolor;
description=newdescription;
quantityinstock=newquantityinstock;
System.out.println("Shirt number: "+shirtid+ "\nPrice: "+price+"\nColor: "+color+"\nDescription: "+description+"\nQuantity in Stock: "+quantityinstock);
}

public void removeashirt(int newshirtid)

{
shirtid=newshirtid;
System.out.println("The Shirt number "+shirtid+" is succesfully remove from the order");
}
}

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


/*Programmer Name: Gezelle Re-ann B. Mandabon
Program Name: Direct Clothing Case Study (Customer)
Date Started: 02-07-2009
Date Finished: 02-08-2009
Program PUrpose: to be able to make the case study solution for direct clothing
*/


public class Customer
{

//variable declaration

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


//constructor declaration

public Customer()

{
}

public Customer(int c, String n, String a, int p, String e)

{
customerid=c;
name=n;
address=a;
phonenumber=p;
emailaddress=e;
}

//method declarations

public void customergreetings(String newname)

{
name=newname;
System.out.println("Hi! "+name+" Welcome to DIRECT CLOTHING");
}

public void customerprofile(int newid, String newname, String newaddress, int newphonenumber, String newemailaddress);

{
customerid=newid;
name=newname;
address=newaddress;
phonenumber=newphonenumber;
emailaddress=newemailaddress;

System.out.println("customer's Profile");
System.out.println("Customer ID: "+customerid+"\nName: "+Name+"\nAddress: "+address+"\nPhone Number: "+phonenumber+"\nE-mail address: "+emailaddress);
}
}

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


/*Programmer Name: Gezelle Re-ann B. Mandabon
Program Name: Direct Clothing Case Study (Order)
Date Started: 02-07-2009
Date Finished: 02-08-2009
Program PUrpose: to be able to make the case study solution for direct clothing
*/

public class Order
{

//variable declaration

private int orderid;
private double totalprice;
private String status;

//constuctor declaration


public Order()

{
}

public Order(int o, double t, String s)

{
orderid=o;
totalprice=t;
status=s;

}


//method declaration


public void placeorder(int newo, double newt, String news)

{
orderid=newo;
totalprice=newt;
status=news;
}

public void removeorder(int o)

{
orderid=o;
System.out.println("Order number "+orderid+" is succesfully canceled");
}

public void submitorder()

{
System.out.println("You have submitted successfully the order number "+orderid);
}

public void putorderonhold()

{
System.out.println("The order is proccess by the company.\nJust wait for he reply.");
}
}


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


/*Programmer Name: Gezelle Re-ann B. Mandabon
Program Name: Direct Clothing Case Study (Shirt)
Date Started: 02-07-2009
Date Finished: 02-08-2009
Program PUrpose: to be able to make the case study solution for direct clothing
*/

public class Shirt
{

//variable declaration

private int shirtid;
private double price;
private String color;
private String description;
private int quantityinstock;

//constructor declaration

public Shirt()

{
}

public Shirt(int s, double p, String c, String d, int q)

{
shirtid=s;
price=p;
color=c;
description=d;
quantityinstock=q;
}

//method declaration


public void addshirttoorder(int newshirtid)

{
shirtid=newshirtid;
System.out.println("You've added the Shirt number "+shirtid+" to your orders");
}

public void removeshirttoorder(int newshirtid)

{
shirtid=newshirtid;
System.out.println("Shirt number " +shirtid+ "is remove successfully from the orders");
}

public void displayshirtinformation()

{
System.out.println("Shirt number: "+shirtid+ "\nPrice: "+price+"\nColor: "+color+"\nDescription: "+description+"\nQuantity in Stock: "+quantityinstock);
}

public void addstock(int newshirtid, double newprice, String newcolor, String newdescription, int newquantityinstock)

{
shirtid=newshirtid;
price=newprice;
color=newcolor;
description=newdescription;
quantityinstock=newquantityinstock;
System.out.println("Shirt number: "+shirtid+ "\nPrice: "+price+"\nColor: "+color+"\nDescription: "+description+"\nQuantity in Stock: "+quantityinstock);
}

public void removestock(int newshirtid)

{
shirtid=newshirtid;
System.out.println("The Shirt number "+shirtid+" is succesfully remove from the stock");
}
}


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


/*Programmer Name: Gezelle Re-ann B. Mandabon
Program Name: Direct Clothing Case Study (Form of Payment)
Date Started: 02-07-2009
Date Finished: 02-08-2009
Program PUrpose: to be able to make the case study solution for direct clothing
*/

public class Formofpayment

{

//variable declaration

private int checknumber;
private int creditcardnumber;
private String expirationdate;

//constructor declaration

public Formofpayment()

{
}

public Formofpayment(int c, int cc, String e)

{
checknumber=c;
creditcardnumber=cc;
expirationdate=e;
}

public void verifycreditcard()

{
System.out.println("Your credit card is OK, we will deduct your transaction from your credit dard.");
}

public void verifycheckpayment()

{
System.out.println("OK!!!You must send first your Check in the company before we Send to you your orders!");
}
}


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


/*Programmer Name: Gezelle Re-ann B. Mandabon
Program Name: Direct Clothing Case Study (Direct Clothing Tester)
Date Started: 02-07-2009
Date Finished: 02-08-2009
Program PUrpose: to be able to make the case study solution for direct clothing
*/


import java.util.*;
public class DirectClothingTester
{
public static void main(String args[])

{
String name;
int customerid;
String address;
int phonenumber;
String emailaddress;
int cq1;
int cq2;
int shirtid;
double price;
String color;
String description;
int quantity;
int payment;
int ordernumber;

System.out.println("WELCOME TO DIRECT CLOTHING CASE STUDY");
System.out.println("\n");
System.out.println("The Shirt in the direct clothing that is currently available is/are:");
System.out.println("\n");
Scanner z=new Scanner(System.in);
System.out.println("If you want to add another stock just press:");
System.out.println("Y if yes!, Z if no!");
cq1=z.nextInt();
if(cq1==1)

{

Scanner y=new Scanner(System.in);
System.out.println("Enter the following information:");
System.out.println("Shirt ID:");
Shirtid=y.nextInt();

Scanner x=new Scanner(System.in);
System.out.println("Price:");
price=x.nextDouble();


Scanner w=new Scanner(System.in);
System.out.println("Color:");
color=w.nextLine();


Scanner v=new Scanner(System.in);
System.out.println("Description:");
description=v.nextLine();


Scanner u=new Scanner(System.in);
System.out.println("Quantity:");
quantity=u.nextInt();


Shirt shirt2=new Shirt();
Shirt2.addstock(shirtid, price, color, description, quantity);
Shirt1.displayshirtinformation();
System.out.println("\n");
Shirt2.displayshirtinformation();

}

else

{
System.out.println("OKIE");
}

System.out.println("\n");
Scanner t=new Scanner(System.in);
System.out.println("If you want to remove a stock just press:");
System.out.println("Y if yes, Z if no!");
cq2=t.nextInt();
if(cq2==1)

{
Scanner s=new Scanner(System.in);
System.out.println("Please enter the Shirt ID number:");
System.out.println("REMINDER:just enter the shirt id number 1 if it is only the available");
shirtid=s.nextInt();
shirt1.removestock(shirtid);
}

}
}

******************************NOTHING FOLLOWS*******************************

Wednesday, February 4, 2009

IT134A_DDS

/*Programmer: Gezelle Re-ann B. Mandabon
/*Date started: 02-04-2009
/*Date ended: 02-04-2009
/*Program name: Cube
/*Program purpose: To create classes using Visibility Modifiers.

public class Cube
{
private double length;

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

public Cube(double l, double w, double h)

{

l=length;

w=width;

h=height;

}

public Cube()

{

}

private double volume()

{
return (length*width*height);

}


private double area()

{

return (length*width);

}

public void setDimension(double newLength, double newwidth, double newheight)

{

length=newLength;

width=newWidth;

height=newHeight;

}


public void displayCube()

{

System.out.println("Cube Dimensions");

System.out.println("The VOLUME of the Cube is" +volume());

System.out.println("The AREA of the Cube is" +area());

}

}

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

/*Programmer: Gezelle Re-ann B. Mandabon

/*Date started: 02-04-2009

/*Date ended: 02-04-2009

/*Program name: CubeTester

/*Program purpose: To create classes using Visibility Modifiers.

import java.util.Scanner;

class CubeTester

{

public static void main(String args[])

{

double l;

double w;

double h;


System.out.println("\n\n");

System.out.println("The Cube object with a parameter");

Cube firstCube=new Cube(2,2,2);

firstCube.displayCube();

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

System.out.println("\n\n");

Scanner a=new Scanner(System.in);

System.out.println("enter the value of the length:");

l=a.nextDouble();

Scanner b=new Scanner(System.in);

System.out.println("enter the value of the height:");

w=b.nextDouble();

Scanner c=new Scanner(System.in);

System.out.println("enter the value of the width:");

h=c.nextDouble();

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

System.out.println("\n\n");

Cube secondCube=new Cube();

secondCube.setDimension(l,w,h);

secondCube.displayCube();

}

}

************************nothing follows***************************