Wednesday, March 18, 2009

Exercise 1- Reverse Word

//ProgrammerName: Joan N. Dominguez
//ProgramName: ReverseSent
//Purpose: Programming exercise which display the original line/words and reversed the words/line that have been entered by the user 
//Date: March 17, 2009
//Subject: Computer Programming 3
//Instructor: Dony Dongiapon

import javax.swing.*;


public class ReverseSent {

public static void main(String[] args) 
{
String ReverserWord = JOptionPane.showInputDialog("Enter a line to be reverse : ");//input an original words or phrase
String ReverserWord2 = ReverserWord.substring(ReverserWord.indexOf(" "),ReverserWord.length());
String reverseWord = new StringBuffer(ReverserWord2).reverseWord().toString();
String ReverserWord3 = ReverserWord.substring(0,ReverserWord.indexOf(" "));
String reverseWord2 = new StringBuffer(ReverserWord3).reverseWord3().toString();
    System.out.println("\nOriginal input: " + ReverserWord);// Print the original string
    System.out.println("Reversed input: " + reverseWord2 + " "+ reverseWord);//Print the string in reversed order
}
    }

        }

-----

//A sample output of this program must be....






Original input: Have a good summer vacation!

Reversed input: evaH !noitacav remmus doog a 


note: this program is modified from the web.



Tuesday, March 17, 2009

Exercise 4 - Name Echo

//ProgrammerName: Joan N. Dominguez

//ProgramName: NameEcho
//Purpose: Programming exercise
//Date: March 17,2009
//Subject: Computer Programming 3
//Instructor: Dony Dongiapon

import java.util.Scanner;
import java.io.*;

public class NameEcho {
 public static void main(String[] args) throws IOException
 {
 System.out.print("\nEnter your name:");//Input a name  
 System.out.println("");
 Scanner in = new Scanner(System.in);
 String name = in.nextLine();
     
 //first input/Fname    
 String FN = name.substring(name.indexOf(" "),name.length()).toUpperCase();
 
 //second input/Secondname    
 String SN = name.substring(0,name.indexOf(" "));


 // Print the Input names
 System.out.print(SN);
 System.out.println(FN);

 }

}
------

//output of this program

Enter your name:

Joan Dominguez

Joan DOMINGUEZ


Exercise 5 - Greeting

//ProgrammerName: Joan N. Dominguez
//ProgramName: HelloObject
//Purpose: Programming exercise with the application of the previous lesson in java programming
//Date: March 17,2009
//Subject: Computer Programming 3
//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 Sir!

Hello Sir!


Friday, March 6, 2009

User-Friendly Division by: Joan N. Dominguez

//ProgrammerName: Joan N. Dominguez
//ProgramName: DivisionPractice
//Purpose: Programming exercise with the application of the previous lesson in java programming
//Date: March 06,2009
//Subject: 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 x = ' ';
  //determine if the user wants to continue or quit
  while( ( x != 'q') || ( x != 'Q' )) {
  try {
         System.out.print("\nEnter the numerator: ");
  snum = input.next();
  x = snum.charAt(0);
  if( (x == 'q') || ( x == 'Q') )
      System.exit(-1);
  number1 = Integer.parseInt(snum);
  System.out.print("Enter the divisor: ");
  sdiv = input.next();
  number2 = Integer.parseInt(sdiv);
  result = quotient(number1,number2);
  System.out.print(number1 + " / " + number2+" is "+result);
  }
  //cathes the Arithmetic Exception it detects
  catch (Exception e) {
  System.out.println(e.toString());
  System.out.println("You can't divide "+number1+" by "+number2);
  }
  }
}
   
}

Monday, March 2, 2009

Iteration_ArrayList Exer

//ProgrammerName: Joan N. Dominguez
//ProgramName: Iterator_arraylist
//Purpose: To show how to iterate through the elements of java ArrayList object using Iterator.
//Date: March 02,2009
//Subject: Computer Programming 3
//Instructor: Dony Dongiapon


 
import java.util.ArrayList;
import java.util.Iterator;
 
public class Iterator_arraylist {
 
  public static void main(String[] args) {
 
  //create an ArrayList object
  ArrayList arrayList = new ArrayList();
 
  //Add elements to Arraylist
  arrayList.add("1");
  arrayList.add("2");
  arrayList.add("3");
  arrayList.add("4");
  arrayList.add("5");
 
  //get an Iterator object for ArrayList using iterator() method.
  Iterator itr = arrayList.iterator();
 
  //use hasNext() and next() methods of Iterator to iterate through the elements
  System.out.println("Iterating through ArrayList elements...");
  while(itr.hasNext())
  System.out.println(itr.next());
 
  }
}
 

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


//The  output would be


Iterating through ArrayList elements...
1
2
3
4




Sunday, February 8, 2009

Case Study Solution

//ProgrammerName: Joan N. Dominguez
//ProgramName: 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


import java.awt.*;
import javax.swing.*;
import java.text;
import java.awt.Graphics;


public class DirectClothing {
public static void main (String[]args){
public void Catalog(){
int array[];
String display = " ";
Shirt s = new Shirt(System.in);
int x;

void Printcatalog(){
System.out.println("Add a shirt: "); //method
x = s.nextString();
String blank = " ";
String x = name.length;
if(character.isYes (aChar)){
System.out.println("Do you want to remove it? + aChar + Yes. ");
x = s.previousString();
String x = name.length;
}else{
System.out.println("Do you want to remove it? + aChar + No. ");
x = s.previousString();
String x = name.length;
}
System.out.println("Do you want to remove it? + aChar + "is" +
cCharacter.isYes(aChar)? "Yes" : "No");

}
}

}

}

public void Shirt(){
protected int Shirt_ID;
protected int Price;
protected String color;
protected String Description;
protected int Quanity;

public Shirt(int a, double b, String c, String d, int e){
this.Shirt_ID = a;
this.Price = b;
this.color = c;
this.Description = d;
this.Quantity = e;
}
public void SetPrice(double b){
Price = b;
}
System.out.println("Shirt ID is " + a.length);
int blank = " ";
System.out.println("Price is " + b.length);
int blank = " ";
System.out.println("Color is " + c.length);
String blank = " ";
System.out.println("Description is " + d.length);
String blank = " ";
System.out.println("Quantity in Stock is "+ e.length);
int blank = " ";

}
}

__________________________________________________________________

//ProgrammerName: Joan N. Dominguez
//ProgramName: Order extends Shirt
//Purpose: To apply knowledge that i have learned in OOP.
//Date: February 8, 2009
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



public class Order extends Shirt {

protected int Order_ID;
protected double totalPrice;
protected int Status;

public Orders (int f, double g, int h){
this.Order_Id = f;
this.totalPrice = g;
this.Status = h;
}
public void setTotalPrice(double g){
totalPrice = g;
}
System.out.Println("Order ID is " + f.length);
int blank = " ";
System.out.Println("TotalPrice is " + g.length);
double blank = " ";
System.out.Println("Status is " + h.length);
int blank = " ";

}

}

_____________________________________________________________________

//ProgrammerName: Joan N. Dominguez
//ProgramName: Form of Payment extends Order
//Purpose: To apply knowledge that i have learned in OOP.
//Date: February 8, 2009
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



public class FormOfPayment extends Order {
protected int CheckNum;
protected int CreditCardNum;
protected String Expiration;

public Payment(int i, int j, String k){
this.CheckNum = i;
this.CreditCardNum= j;
this.Expiration = k;
}
System.out.println("Check Number is " + i.length);
int blank = " ";
System.out.println("Credit Card Number is " + j.length);
int blank = " ";
System.out.println("Expiration Date is " + k.length);
String blank = " ";
if(Credit CardNum == 0)
int credit cardNum = j;
j = int.parseInt(JOptionPane.ShowInputDialog("Verify Credit Card Number"));
}

}



_____________________________________________________________________

//ProgrammerName: Joan N. Dominguez
//ProgramName: Customer extends Order
//Purpose: To apply knowledge that i have learned in OOP.
//Date: February 8, 2009
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



public class Customer extends Order {
protected int Customer_ID;
protected String Name;
protected String Address;
protected int PhoneNum;
protected String Email;

public Customers(int l, String m, String n, int o, string p){
this.Customer_ID = l;
this.Name = m;
this.Address = n;
this.PhoneNum = o;
this.Email = p;
}

System.out.println("Customer ID is " + l.length);
int blank = " ";
System.out.Println("Name is " + m.length);
String blank = " ";
System.out.Println("Address is " + n.length);
String blank = " ";
System.out.Println("Phone Number is " + o.length);
int blank = " ";
System.out.Println("Email Address is " + p.length);
String blank = " ";
}
if (response == CANCEL){
}else{

}
}
}

________________________________________________________________________


//ProgrammerName: Joan N. Dominguez
//ProgramName: Direct Clothing Demo
//Purpose: To apply knowledge that i have learned in OOP.
//Date: February 8, 2009
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



public DirectClothingDemo() {
public static void main(String[]args){
DirectClothing Shirt = new DirectClothing();
DirectClothing Order = new DirectClothing();
DirectClothing FormOfPayment = new DirectClothing();
DirectClothing Customer = new DirectClothing();

Shirt.Shirt_ID("2009-01");
Shirt.Price();
Shirt.Color("Blue");
Shirt.Description(" ");
Shirt.Quanity("3");
Order.Order_ID("234-567");
Order.totalPrice("234-567");
Order.Status("234-567");
FormOfPayment.CheckNum("001-02");
FormOfPayment.CreditCardNum("1234-5678");
FormOfPayment.Expiration(" ");
Customer.Customer_ID("234");
Customer.Name("Joan Dominguez");
Customer.Address("Daticor Matiao, Mati City");
Customer.PhoneNum(" ");
Customer.Email(" ");
}
}

Wednesday, February 4, 2009

Cube Solution

//ProgrammerName: Joan N. Dominguez
//ProgramName: Cube
//Purpose: To create a program that calculate the volume of an object cube
//Date: February 04, 2009 
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



import javax.swing.JOptionPane;

public class Cube{
    private double Volume;
    private double Length;
    private double Width;
    private double Height;
    private double Area;

public CubeSolution(double Width, double Height, double Lenght)
  {
  this.Width;
  this.Height;
  this.Lenght;
  }
  public Cube()
  {
   
  }  
public void SetDimension(double newWidth, double newHeight, double newLength)
  {
  this.Width = newWidth;
  this.Height = newHeight;
  this.Lenght = newLength;
  }  
private double Volume(){
  return Width * Lenght * Height;
}

private double Area(){
  return Width * Lenght;
}  
public void displayCube(){
  System.out.print(Volume() + " and " + Area());
}

}

}



//ProgrammerName: Joan N. Dominguez
//ProgramName: CubeTester
//Purpose: To create a cube tester that test the cube class
//Date: February 04, 2009 
//Subect: Computer Programming 3
//Instructor: Dony Dongiapon



import javax.swing.JOptionPane;

public class CubeTester{
    
    public static void main(String []args){
        Cube newCube1 = new Cube(10,10,10);
        Cube newCube2 = new Cube();
                    
JOptionPane.showMessageDialog("\t The volume and area of constructor having a parameter: " 
  + newCube1.displayCube(),"Volume and Area of a Cube",JOptionPane.INFORMATION_MESSAGE);

 String Width = JOptionPane.showInputDialog(" Enter a value of Width "));
 String Height = JOptionPane.showInputDialog(" Enter a value of Height "));
 String Length = JOptionPane.showInputDialog(" Enter a value of Length "));  
     
 double x = Integer.parseInt(Width);
 double y = Integer.parseInt(Height);
 double z = Integer.parseInt(Length);
    
     
Cube2.setDimension(x, y, z);
JOptionPane.showMessageDialog("\t The volume and area of constructor having no a parameter is: " 
 + newCube2.displayCube(),"Volume and Area of a Cube",JOptionPane.INFORMATION_MESSAGE);
 
          }
    }
}