Friday, March 20, 2009

NAME ECHO

EXERCISE 4

/* Programmer: Nerissa Agapay
* Program name: NameEcho
* Instructor: Mr. Dony Dongiapon
* Date Started: 03/16/09
* Date Finished: 03/18/09
* Description:To capitalize the second name enter by the user.
*/
import javax.swing.*;
import java.io.*;

public class NameEcho{
public static void main(String[] args)throws StringIndexOutOfBoundsException{
try{


String name=(JOptionPane.showInputDialog("Enter your name:"));//ASK THE USER
/

int c=name.indexOf(" ");
int a=c+1;
String name2=name.substring(a,name.length());
String output = name.substring(0,c);
System.out.print(output+" "+name2.toUpperCase());//print the input and the second name all in capital letters

}
catch(StringIndexOutOfBoundsException index){//error handling
System.err.printf("No more index follow.");//print messsage
}
}
}

HELLO

EXERCISE 5


**
/* Programmer: Nerissa Agapay
* Program name: Greeting
* Instructor: Mr. Dony Dongiapon
* Date Started: 03/16/09
* Date Finished: 03/18/09
* Description:To print message what is being enter by the user
*/
import javax.swing.*;//java package

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

String name=(JOptionPane.showInputDialog("Enter Greeting:"));//ask for greeting


JOptionPane.showMessageDialog(null,name,"Print Output",JOptionPane.INFORMATION_MESSAGE);//print the greeting in the dialog box


}
}

WORD REVERSER

EXERCISE 1

/* Programmer: Nerissa Agapay
* Program name: Reverser
* Instructor: Mr. Dony Dongiapon
* Date Started: 03/16/09
* Date Finished: 03/18/09
* Description:To reverse the phrase being enter by the user without changing orginal position of the words.
*/
import java.util.*;
import javax.swing.*;

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

String name=(JOptionPane.showInputDialog("Enter phrase:"));//

StringTokenizer tokens = new StringTokenizer(name);//use StringTokenizer to separate each word.
while(tokens.hasMoreTokens()){

String element = tokens.nextToken();
StringBuffer buffer = new StringBuffer(element); // a method that reverses the contents .

element = buffer.reverse().toString();

System.out.print(element+" "); //print the reverse word .
}
}
}

ArrayList

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Ex01 {

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

BufferedReader userInput = new BufferedReader
(new InputStreamReader(System.in));

ArrayList myArr = new ArrayList();
myArr.add("Italian Riviera");
myArr.add("Jersey Shore");
myArr.add("Puerto Rico");
myArr.add("Los Cabos Corridor");
myArr.add("Lubmin");
myArr.add("Coney Island");
myArr.add("Karlovy Vary");
myArr.add("Bourbon-l'Archambault");
myArr.add("Walt Disney World Resort");
myArr.add("Barbados");

System.out.println("Stupid Vacation Resort Adviser");
System.out.println("Enter your name:");
String name = userInput.readLine();
Integer nameLength = name.length();
if (nameLength == 0)
{
System.out.println("empty name entered");
return;
}

Integer vacationIndex = nameLength % myArr.size();

System.out.println("\nYour name is "+name+", its length is " +
nameLength + " characters,\n" +
"that's why we suggest you to go to "
+ myArr.get(vacationIndex));
}
}


http://www.anyexample.com/programming/java/java_arraylist_example.xml


Things I learned about:

ArrayList can dynamically increase or decrease in size.
Use only in primitive data type.

Direct Clothing Case Study by Agapay, Nerissa

catalog
/** Programmer: Nerissa Agapay
* Program: Catalog.java
* Date Strated : February 6,2009
* Date Ended: February 9,2009
*
*/


public class Catalog {


private int ShirtID;
private double Price;
private String Color;
private String Description;
private int QuantityInStock;




public Catalog(int SID, double P, String D,String C, int QIS)
{
ShirtID=SID;
Price=P;
Color=C;
Description=D;
QuantityInStock=QIS;

}


public void addshirt(int newsid, double newpri, String newcol, String newdes, int newqua)
{
ShirtID=newsid;
Price=newpri;
Color=newcol;
Description=newdes;
QuantityInStock=newqua;

System.out.println("Shirt number: "+ShirtID);
System.out.println("Price: "+Price);
System.out.println("Color: "+Color);
System.out.println("Description: "+Description);
System.out.println("Quantity in Stock: "+QuantityInStock);

System.out.println("The product was succesfully added!");
}
}

order
public class Order {

private int OrderID;
private double TotalPrice;
private String Status;


public Order()
{
}

public Order(int newOI, double newTP, String newS)
{
OrderID=newOI;
TotalPrice=newTP;
Status=newS;
}


public void OrderCancel(int newoid)
{
OrderID=newoid;
System.out.print("Order cancelled"+OrderID);
}

public void AddOrder()
{
System.out.println("The shirt has been added to your order "+OrderID);
}
}
FormofPayment
public class FormofPayment {

private int CheckNum;
private int CCN;
private String ExpDate;


private void VerifyCreditCardNumber(){
System.out.print("\nCredit Card number ok!");
}

private void VerifyCheckPayment(){
System.out.print("Check number ok!");
}

public FormofPayment(int newCCN, String newExpDate){
CCN = newCCN;
ExpDate = newExpDate;

this.VerifyCreditCardNumber();
}
public FormofPayment(){
this.VerifyCheckPayment();
}
}
shirt
public class Shirt {

private int ShirtID;
private int Price;
private String Color;
private String Description;
private int QuatityInStock;



public Shirt(int SID, int P, String C, String D,int QIS ){

ShirtID=SID;
Price=P;
Color=C;
Description=D;
QuatityInStock=QIS;

}

private void AddStock{
customer stock=new customer("012+ Lindsay+Davao City");
System.out.println("The stock was added!");

}
private void RemoveStock{
System.out.println(" ");
System.out.println("Succesfully Remove!!");

}

public void DisplayShirtInformation{
System.out.println("Information:+ 1112+ 250php+ green+ Small+ 4);
}
customer
public class Customer {

private int CustomerID;
private String Name;
private String Address;
private int PhoneNum;
private EMD;


private void placeOrder(){
System.out.print("\nName+"\n, from "+Address+" has a phone number "+PhoneNum);
System.out.print("\nand email add "+EMD+" have an order.");
Order avon = new Order(6,450.00,"available");
}

private void cancelOrder(){
System.out.print("\nCancelled order!");
Order avon = new Order();
}

public Customer(int cusID, String cusName, String cusAddress, int cusPhoneNumber, String cusEmail){
CustomerID = cusID;
Name = cusName;
Address = cusAddress;
PhoneNum = cusPhoneNumber;
EMD = cusEmail;
this.placeOrder();
}
public Customer(){
this.cancelOrder();
}

}
DSCTester
import javax.swing.*;
public class DSCTester {
public static void main(String[]args){


int choice;

System.out.println("\t\tWhat do you want to do?");
System.out.println("1.Place an order");
System.out.println("2. Cancel an order");



choice=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice"));


if(choice==1) {
Customer risa = new Customer(456,"Nerissa","Davao",237,"lindsay_2001@yahoo.com");
}else if(choice==2){
Customer risa = new Customer();
}
}
}

User Friendly Division

/*
Programmer: Nerissa Agapay
Date Started: March 6,2009
Date Ended: March 7, 2009
Description:This program will calculate the numerator and denominator,
then press 'y' if you want to continue,
otherwise just press any key in the keyboard to terminate.

*/

import java.util.InputMismatchException;
import javax.swing.*;

public class UserFriendlyDivision{

public static float quotient(float x, float y)throws ArithmeticException{


public static void main(String args[]){

char ans='y';

while(ans=='y'){

try{

float x=Integer.parseInt(JOptionPane.showInputDialog("Enter numerator:"));//ask user to input a integer
float y=Integer.parseInt(JOptionPane.showInputDialog("Enter divisor:"));//second integer input

float quotient=x/y; //calculate the answer
System.out.println("The quotient is:"+quotient ); //display the quotient

}
}


catch(ArithmeticException Numerr)// organizing the error in arithmetic
{
System.err.println("You can't divide "+x+" by "+y);//message print
}

catch(InputMismatchException Inputerr)//organizing the error in inputMismatch like string
{
System.err.println("You enter bad data.\nPlease try again.");//message print



}
String a=(JOptionPane.showInputDialog("Do you want to continue?");
ans=a.chartAt(0);


}

}
}

Wednesday, February 4, 2009

Cube Solution

Cube

/* Programmer:      Nerissa Agapay

  Program name:     Cube
  Subject:                   IT134_Computer Programming 3
  Instructor:             Mr. Dony Dongiapon
  Date Started:         02/04/09
  Date Finished:       02/04/09

  Purpose:               To make a cube class that both constructor and method are                                                                  private. Also to calculate volume and area of a cube.

*/


import java.util.Scanner;
public class Cube {
    Scanner scan = new Scanner(System.in);
    
    //fields
    private double width;
    private double height;
    private double length;
    private double volume;
    private double area;
    
    //constructor with parameter
    public Cube(double w,double h,double l){
        width=w;
        height=h;
        length=l;
        
        this.volume();
      this.area();
    }
    //constructor without parameter
    public Cube(){
         System.out.print("\nEnter a width of a cube: ");
            double a=scan.nextDouble();
          System.out.print("\nEnter a height of a cube: ");
          double b=scan.nextDouble();
      System.out.print("\nEnter a length of a cube: ");
          double c=scan.nextDouble();
          
          this.setDimension(a,b,c);
          this.volume();
          this.area();
    }
    
    //method 1
    private double volume(){
        volume=width*height*length;
        
            return volume;
    }
    //method 2
    private double area(){
        area=length*width;
        
            return area;
    }
    public void setDimension(double wid, double hyt, double lent){
        width = wid;
        height = hyt;
        length = lent;    
    
    }
    // display the area and volume
    public void displayCube(){
        System.out.println("\nThe volume of a cube is "+volume);
        System.out.println("\nThe area of a cube is "+area);
        
        
        }

    }

CubeTester

/* Programmer:     Nerissa Agapay
  Program name: CubeTester
  Subject:     IT134_Computer Programming 3
  Instructor:     Mr. Dony Dongiapon
  Date Started: 02/04/09
  Date Finished: 02/04/09
  Purpose:     To make a CubeTester main class that would access the constructor and method of Cube
*/


public class CubeTester {

  public static void main(String[] args){
      
      Cube myCube = new Cube(3.0,4.0,6.0);
        myCube.displayCube();
        
      Cube myNewCube = new Cube();
      myNewCube.displayCube();
  }
}
/* Programmer:     Nerissa Agapay
  Program name: CubeTester
  Subject:     IT134_Computer Programming 3
  Instructor:     Mr. Dony Dongiapon
  Date Started: 02/04/09
  Date Finished: 02/04/09
  Purpose:     To make a CubeTester main class that would access the                                                                         constructor and method of Cube
*/


public class CubeTester {

  public static void main(String[] args){
      
      Cube myCube = new Cube(3.0,4.0,6.0);
        myCube.displayCube();
        
      Cube myNewCube = new Cube();
      myNewCube.displayCube();
  }
}