Wednesday, March 18, 2009

Project Exercises

--Exercise No.1--

/*
Programmer Name: Jay S. Gil
Program Name: Word Reverser
Purpose: To Learned how to program when the output is 
reverse from the original word.
Date: March 18,2009
Instructor: Dony Dongiapon
*/

/*Java String Reverse example.
This example shows how to reverse a given string*/ 
public class StringReverse {

public static void main(String args[])

{ //declare orinial string

  String strOriginal = "Hello World";

  System.out.println("Original String : " + strOriginal);
  
  /* The easiest way to reverse a given string is to use reverse()
 method of java StringBuffer class.
  reverse() method returns the StringBuffer object so we need to
cast it back to String using toString() method of StringBuffer*/

  strOriginal = new StringBuffer(strOriginal).reverse().toString();

  System.out.println("Reversed String : " + strOriginal);

  }
}

/*Output of the program would be :
Original String : Hello World Reversed String : dlroW olleH*/

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

--Exercise No.2--

/*
Programmer Name: Jay S. Gil
Program Name: Color Cycle
Purpose: To Learned how to program when the output is color background code.
Date: March 18,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);

  }
}

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

--Exercise No.3--

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

--Exercise No.4--

/*
Programmer Name: Jay S. Gil
Program Name: Name Echo
Purpose: To Learned how to 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 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); 
 }
}

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

--Exercise No.5--

/*
Programmer Name: Jay S. Gil
Program Name: Name Echo
Purpose: To Learned how to 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 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); 
 }
}

THanK YOU!!!!

Monday, March 9, 2009

User-Friendly Division

//Programmer Name: Jay S. Gil
//Date Finished: MARCH 11, 2009
//Purpose: To apply my knowledge in making a program of division.

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

public class Division {

public static void main(String[] args)
{
division(100, 0);
} public static void division(int numerator, int denominator )throws Exception

{
return numerator/denominator;}

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

int numerator;
int denominator;
char x=exitchar.charAt(0);

while(x!='q'){if(x != 'Q')
{
try {
if((scan.next().charAt(0)=='q')(scan.next().charAt(0)=='Q')){x=scan.next().charAt(0);
}
else
{
numerator=scan.nextInt();

System.out.println("Enter the divisor:");
denominator=scan.nextFloat();
int average = numerator / denominator;
System.out.println("Average : " + average);
}
}
int average = numerator / denominator;
System.out.println("Average : " + average);
} catch (Exception ex)
{
System.out.println("Divide" + ex.getMessage() + "Exception" + "\n" + "Please check the denominator");

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

catch(IndexOutOfBoundsException index)
{
System.err.println("");}
}else
{
x='q';
}
} }
}

Monday, March 2, 2009

Iterator

/*Programmer name: Jay Gil

Title: Iteration Arraylist

Date: March 2, 2009

Purpose: To apply knowledge that I've got from the reporter of Iterators.

*/

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 + " ");  }

  }

}

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

/*
 Output: 
Original contents of al: C A E B D F 
Modified list backwards: F+ D+ B+ E+ A+ C+ 

 */



Monday, February 9, 2009

Direct Clothing Case Study Solution


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


/*pragrammer name: Jay S. Gil
Title: Direct Clothing Case Study
Date Started: February 8, 2009
Date Finished : February 9, 2009
Purpose: To enhance my ability in programming and 
apply my knowledge that I learned in OOP.
Subject: Computer Programming 3
Instructor: Doni Dongiapon

*/


public class shirt 

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

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


//constructor

shirtID=newshirtID; 
price=newprice; 
color=newcolor; 
description=newdescription; 
quantity=newquantity; 



public int addStock( int stock) 

quantity=quantity+stock; 

return quantity; 



public int removeStock( int stock) 

quantity=quantity-stock; 
return quantity; 



public String displayInformation() 

return String.format("The ShirtID:%d\n ThePrice:%f\n ThE Color:%s\n
 The Description:%s\n The Quantity:%d" , 
shirtID,color,price,description,quantity); 


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("ShirtID: %d\n Price: %f\n Color: %s\n Description: 
%s\n Quantity in Stock: %d",shirtID,color,price,description,quantity); 


System.out.println("The information above has been succesfully added");
}

public void removestock(int newshirtid)
{
shirtid=newshirtid;
System.out.println("The shirt#: \n"+shirtId);
System.out.println("succesfully... removed");
}
}


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

/*pragrammer name: Jay S. Gil
Title: Direct Clothing Case Study
Date Started: February 8, 2009
Date Finished : February 9, 2009
Purpose: To enhance my ability in programming and 
apply my knowledge that I learned in OOP.
Subject: Computer Programming 3
Instructor: Doni Dongiapon

*/


public class order
{

 private String orderID;
 private double totalprice; 
private String status;

public Order()
{

}
public void orderShirt(String neworderID,double newtotalorderprice,String newstatus)



String orderID=neworderID; 
double totalorderprice=newtotalorderprice;
 String status=newstatus;
}

public void setOrderID(String neworderID)

{ String orderID=neworderID;

}
public String getOrderID()

{
 return orderID;

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

}
}

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


/*pragrammer name: Jay S. Gil
Title: Direct Clothing Case Study
Date Started: February 8, 2009
Date Finished : February 9, 2009
Purpose: To enhance my ability in programming and 
apply my knowledge that I learned in OOP.
Subject: Computer Programming 3
Instructor: Doni Dongiapon

*/



public class customer
{



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




public Customer()
{
}

public Customer(int ID, String cname, String caddress,
 int cphonenumber, String cemailaddress)

{
customerid=ID;
name=cname;
address=caddres;
phonenumber=cphonenumber;
emailaddress=cemailaddress;

}


public void customerprofile(String newname, int newid, 
String newaddress, int newphonenumber, String newemailaddress)
{
customerid=newid;
name=newname;
address=newaddress;
phonenumber=newphonenumber;
emailaddress=newemailaddress;
System.out.println("Cutomer's Background");
System.out.println("Customer Name: %s\n Customer ID: %d\n Customer Address: %s\n
 Customer PhoneNumber: %d\n Customer E-mail address: %s", customerid,
name, address, phonenumber, emailaddress);
}
}

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


/*pragrammer name: Jay S. Gil
Title: Direct Clothing Case Study
Date Started: February 8, 2009
Date Finished : February 9, 2009
Purpose: To enhance my ability in programming and 
apply my knowledge that I learned in OOP.
Subject: Computer Programming 3
Instructor: Doni Dongiapon

*/



public class Catalog {



public Catalog()
{
}

public Catalog(int cshirtid, double cprice, String ccolor, 
String cdescription, int cquantityinstock)
{
shirtid=cshirtid;
price=cprice;
color=ccolor;
description=cdescription;
quantityinstock=cquantityinstock;
}



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("ShirtID: %d\n Price: %f\n Color: %s\n Description: %s\n 
Quantity in Stock: %d",shirtid,price,color, description, quantityinstock);
System.out.println("The data was added...");
}


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");
}
public void removeashirt(int newshirtid)
{
shirtid=newshirtid;
System.out.println("The ShirtID: %d",+shirtid);
System.out.println("The data was successfully removed from the order");
}
}

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


/*pragrammer name: Jay S. Gil
Title: Direct Clothing Case Study
Date Started: February 8, 2009
Date Finished : February 9, 2009
Purpose: To enhance my ability in programming and 
apply my knowledge that I learned in OOP.
Subject: Computer Programming 3
Instructor: Doni Dongiapon

*/


public class formOfpayment


private String checknumber; 
private String cardnumber; 
private String expirationdate;

public FormofPayment(String newcheck,String newcard,String newexpirationdate)



checknumber=newcheck; 
cardnumber=newcard; 
expirationdate=newexpirationdate 
}



 public String getChecknumber()

{
 return checknumber;

}

public void setCardnumber(String newcard)

{ cardnumber=newcard;



public String getCardnumber()

{

 return cardnumber;
}

public void setExpirationdate(String newexpirationdate)



expirationDate=newepirationdate;



public String getExpirationdate()


returnexpirationDate;

}public void Dispalymessage()



System.out.println("\nWelcome!!!!\n");
System.out.println("This is your cardnumber:%s/n and your checknumber is: %s");

}
}

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


import java.util.Scanner;

public class clothingTester{
 public static void main(String args[])

 { 

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


System.out.println("Be one of us...Welcome to Direct Clothing Solution\n");

System.out.println("24 Hours available...\");
Scanner input= new Scanner(System.in); 

Shirt myShirt=new Shirt(); 

System.out.println("Welcome to Direct Clothing:\n\nHere's the Catalog?");

 myShirt.displayCatalog(); 

Scanner input= new Scanner(System.in); 
System.out.println("Want to add a stock?"); 

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("Your Shirt was Successfully added.....\n 
System.out.println("Thank You and God Bless"); 

}
 else
 { 

System.out.println("IT is OK"); 


}
 }




Wednesday, February 4, 2009

Cube Manipulation

/*Programmer Name: Jay S. Gil

Program Title: Cube ManipulationDate:

February 2009

Purpose: To classes using Modifiers

*/

import java.util.Scanner;

public class Cube{   

private double width;   

private double length;   

private double height;   

private double volume;   

private double area;           

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

    width=w;        height=h;        length=l;   

}    public Cube()   

{           

}    private double volume() 

  {        return (width*length*height);       

        }   

private double area() 

  {                return (width*length);       

        }        public void setDimension(double newwidth, double newheight, double newlength) 

  {        width=newwidth;     

  height=newheight;       

length=newlength;    } 

  public String displayCube()   

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

  }

}    

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

/*Programmer Name: Jay S. Gil
Program Title: Cube Manipulation
Date: February 2009
Purpose: To create a tester that test the cube class

*/


import java.util.Scanner;

class CubeTester{

public static void main(String args[]){

double l;
double w;
double h;

System.out.println("Constructor with a parameter");

Cube newCube=new Cube(1,2,3);;

newCube.displayCube();

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

Scanner a=new Scanner(System.in);

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

l=a.nextDouble();

Scanner b=new Scanner(System.in);

System.out.println("Enter value of  height:");
w=b.nextDouble();Scanner 
c=new Scanner(System.in);

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

h=c.nextDouble();
System.out.println("The Cube object without a parameter"); 



Cube secondCube=new Cube(); 
secondCube.setDimension(l,w,h);
secondCube.displayCube();


}
}


Tuesday, February 3, 2009

"Here we go again.,,.let's get it on.,,"