Friday, March 20, 2009

Exer3:Combination Lock

import java.util.Scanner;
public class combinationLock
{
//Sets the combination lock to C O I

public char FIRST_LETTER='C';
public char SECOND_LETTER='O';
public char THIRD_LETTER='I';

//Declare the 3 inputs of the user

public char first_input;
public char second_input;
public char third_input;
public static void main(String args[])


//Start getting their first letter
System.out.println("Please enter in the first letter in the combination: ");
char first_input=numbers.next().charAt(0);
Character.toUpperCase(first_input);

//Start getting their second letter
System.out.println("Please enter in the second letter in the combination: ");
char second_input=numbers.next().charAt(0);
Character.toUpperCase(second_input);

//Start getting their second letter
System.out.println("Please enter in the third letter in the combination: ");
char third_input=numbers.next().charAt(0);
Character.toUpperCase(third_input);

//Begin running the methods to begin lock comparison
lock.lockComparison1(first_input);
lock.lockComparison2(second_input);
lock.lockComparison3(third_input);

//Start the methods for the lock combination testing
public char lockComparison1(char first_input)
{
boolean first;
if(first_input=='C')
{
first=true;
System.out.println("Your first guess, \"C\" is correct.");
}
else if(first_input==SECOND_LETTER || first_input==THIRD_LETTER)
{
System.out.println("Your first guess, \""+first_input+"\" was not the first letter in the combination, yet it is used in the actual combination");
first=false;
}
else if(first_input!=SECOND_LETTER || first_input!=THIRD_LETTER)
{
System.out.println("You entered \""+first_input+"\" but it isn't a letter in any part of this combination.");
}
return first_input;
}
public char lockComparison2(char second_input)
{
boolean second;
if(second_input=='O')
{
second=true;
System.out.println("Your second guess, \"O\" is correct.");
}
else if(second_input==FIRST_LETTER || second_input==THIRD_LETTER)
{
System.out.println("Your second guess, \""+second_input+"\" was not the second letter in the combination, yet it is used in the actual combination");
second=false;
}
else if(second_input!=FIRST_LETTER || second_input!=THIRD_LETTER)
{
System.out.println("You entered \""+second_input+"\" but it isn't a letter in any part of this combination.");
}
return second_input;
}
public char lockComparison3(char third_input)
{
boolean third;
if(third_input=='I')
{
third=true;
System.out.println("Your third guess, \"I\" is correct.");
}
else if(third_input==FIRST_LETTER || third_input==SECOND_LETTER)
{
System.out.println("Your third guess, \""+third_input+"\" was not the third letter in the combination, yet it is used in the actual combination");
third=false;
}
else if(third_input!=SECOND_LETTER || third_input!=FIRST_LETTER)
{
System.out.println("You entered \""+third_input+"\" but it isn't a letter in any part of this combination.");
}
return third_input;
}

}

Exer5: Hello Object

//Programmer:Pacalioga, Mark Jay
//Program Name:Hello Object
//Purpose:
//Date:March 19,2009
//Instructor: Dony Dongiapon


import java.util.Scanner;

public class helloObject { public static void main(String[] args)
{
String text;

Scanner input=new Scanner(System.in);

System.out.println("Please Enter your Text:");
greetings=input.nextLine();
System.out.println();
System.out.println(text);
}
}

Exer4. Name Echo

//programmer: Pacalioga, Mark Jay
//Program Name: Name Echo
//Date:March 19,2009
//Purpose:To enter name in capslock form
//instructor: Dony Dongiapon

import java.util.Scanner;

public class NameEcho{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
String username;
String Firtsname;
String Lastname;
System.out.println("Enter name:");

//ask for the user’s name

name=scan.nextLine();

int x=username.indexOf(" ");
fname=username.substring(0,x);
lname=username.substring(x);
System.out.println("\n%s %s\n",Firtsname,Lastname.toUpperCase());
}
}

Exer1. Word Reverser

//Programmer:Pacalioga, Mark Jay
//Program Name:Word Reverser
//Purpose:to reverse the entered word
//Date:March 17,2009
//Instructor: Dony Dongiapon


import java.io.*;


public class TestReverse
{
public static void main(String[] args) throws IOException
{
System.out.println("Enter a line to be reversed");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inData;
inData = br.readLine();
ReverseString rs = new ReverseString();
System.out.println("Reversed: " + rs.reverse(inData));
}
}

Saturday, March 14, 2009

Iterator Arraylist exer.

/*
//ProgrammerName: Pacalioga, Mark Jay
//ProgramName: Iterator_arraylist
//Purpose: 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;

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

System.out.println("Initial size of al: " + al.size());

//Elements of array
al.add("C");
al.add("A");
al.add("E");
al.add("B");
al.add("D");
al.add("F");
al.add(1, "A2");

System.out.println("Size of al after additions: " + al.size());

System.out.println("Contents of al: " + al);

al.remove("F");
al.remove(2);

System.out.println("Size of al after deletions: " + al.size());
System.out.println("Contents of al: " + al);
}
}

Output:

Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D]

Monday, February 9, 2009

Direct Clothing Case Study

/*Programmer: Pacalioga, Mark Jay
Program Name:Shirt class
Date Started: 02/09/09
Date Finished: 02/09/09
Program Purpose:To create a code for the purpose of our midterm exam.
*/

public class Shirt
{

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


public Shirt()
{
}

//constructor

public Shirt(String newshirtID,double newprice,String newcolor,int newquantity,String newdescription)
{
shirtid=newShirtID;
price=newprice;
color=newcolor;
quantity=newquantity;
description=newdescription;
}

//method

add stock void shirtid(String newShirtID)
{
shirtID=newShritID;
}

public void giveprice(double newprice)
{
price=newprice;
}

public double getprice(double newprice)
{
return price;
}

public void givecolor(String color)
{
color=newcolor;
}

public void getcolor(String color)
{
return color;
}

public void givequantity(int quantity)
{
quantity=newquantity;
}

public int getquantity(int quantity)
{
return quantity;
}

public void givedescription(String description)
{
description=newdescription;
}

public String(String description)
{
return description;
}

public String removestock()
{

}
}

Customer Class


public class Customer
{

private int CustomerID;
private String Name;
private String Address;
private int Phonenumber;
private String Emailaddress;

//constructor

public Customer()
{
}

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

{
CustomerID=c;
Name=n;
Address=a;
Phonenumber=p;
Emailaddress=e;
}

//methods
public void customergreetings(String newname)
{
Name=newname;
System.out.println(" Welcome to Direct Clothing" "+name+");
}

public void customerprofile(String newname, int newid, String newaddress, int newphonenumber, String newemailaddress)
{
Name=newname;
Address=newaddress;
Customerid=newid;
Phonenumber=newphonenumber;
Emailaddress=newemailaddress;
System.out.println("customer's Profile");
System.out.println("Name: "+name+ "\nCustomer ID: "+customerid+"\nAddress:"+address+"\nPhone Number: "+phonenumber+"\nE-mail address: "+emailaddress);
}
}

Catalog Class


public class Customer
{

private int CustomerID;
private String Name;
private String Address;
private int Phonenumber;
private String Emailaddress;

//constructor

public Customer()
{
}

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

{
CustomerID=c;
Name=n;
Address=a;
Phonenumber=p;
Emailaddress=e;
}

//methods
public void customergreetings(String newname)
{
Name=newname;
System.out.println(" Welcome to Direct Clothing" "+name+");
}

public void customerprofile(String newname, int newid, String newaddress, int newphonenumber, String newemailaddress)
{
Name=newname;
Address=newaddress;
Customerid=newid;
Phonenumber=newphonenumber;
Emailaddress=newemailaddress;
System.out.println("customer's Profile");
System.out.println("Name: "+name+ "\nCustomer ID: "+customerid+"\nAddress:"+address+"\nPhone Number: "+phonenumber+"\nE-mail address: "+emailaddress);
}
}

Order class


public class Order
{

//variable

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

//constuctor

public Order()
{
}

public Order(int orderID, double totalprice, String status)
{
}

//method

public void placeorder(int neworder, double newtotalprice, String newstatus)
{
orderid=neworder;
totalprice=newtotalprice;
status=newstatus;
}

public void removeorder(int order)
{
orderid=order;
System.out.println("Order number "+orderID+" has been remove");
}

public void submitorder()
{
System.out.println("Order number has been added "+orderid);
}

public void putorderonhold()
{
}
}

Order form class


public class FormofPayment
{
//variable declaration...

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

// constructor

public Formofpayment()
{
}

public FormofPayment(int c, int ccn, String e)
{
checknumber=c;
creditcardnumber=ccn;
expirationdate=e;
}

public void verifycreditcard()
{
System.out.println("Credit accepted!.");
}

public void verifycheckpayment()
{
System.out.println("pleasse verify your payment please");
}
}

Wednesday, February 4, 2009

CUBE

/*programmer: Pacalioga, Mark Jay    
date started:February 4,2009
date ended:February 4,2009
Programm name:Cube
Programm purpose:to learned more about visibility modifier
*/



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 Dimension(double nLength, double nHeight, double nWidth)
{
length=nLength;
width=nWidth;
height=nHeight;
}

public void displayCube()
{
System.out.println("The volume of the Cube:"+volume());
System.out.println("the area of the Cube:"+area());
}

}



CUBETESTER


/*programmer: Pacalioga, Mark Jay    
date started:February 4,2009
date ended:February 4,2009
Programm name:Cube
Programm purpose:to learned more about visibility modifier
*/

import java.util.Scanner;

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

double l;
double w;
double h;

System.out.println("the cube with a parameter");

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


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

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

}