Monday, March 23, 2009
nameEcho
Program name: nameEcho
Date started: march 23, 2009
Date ended: march 24, 2009
Purpose: manipulate String.*/
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();
}
}
reverseword
Program Name: Word Reverser
Date Started: March 23, 2009
Date Ended: March 24, 2009
Program Purpose: A program that will ask a String to the user,then the program will read it and
print it in a reverse form.*/
import java.util.*;
public class reverseword{
public static void main(String args[])
{
String inputword;
String word;
Scanner scan=new Scanner(System.in);
System.out.println("Enter a sentence:");
input=scan.nextLine();
StringTokenizer st=new StringTokenizer(wordinput) ;
while (st.hasMoreTokens())
{
word=st.nextToken();
word=new StringBuffer(r).reverse().toString();
System.out.println(word+" ");
}
}
}
Monday, March 16, 2009
arraylist/iterators
Name of Program: ArrayList with Iterators
Date Started : March 16,2009
Date Ended: March 17,2009
Purpose: To try implementations that deals with ArrayList and Iterators.
***/
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;
public class iterators {
public static void main(String args[]) {
ArrayList
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
list.add("f");
System.out.print("Original contents of list: ");
Iterator
while (zai.hasNext())
{
String element = zai.next();
System.out.print(element + " ");
}
System.out.println();
ListIterator
while (partz.hasNext())
{
String element = partz.next();
partz.set(element + "+");
}
System.out.println("Size of list after additions: " + list.size());
list.remove(1);
{
System.out.println("Size of list after deletions: " + list.size());
System.out.println("Contents of list: " + list);
}
}
}
____________________________________________
output:
Original contents of list: a b c d e f
Size of list after additions: 6
Size of list after deletions: 5
Contents of list: [a+, c+, d+, e+, f+]
Monday, March 9, 2009
OBJECTS IN THE DIRECT CLOTHING CASE STUDY
Customer:
public class Customer{
String Name=" ";
String Address=" ";
int PhoneNumber=00000000000;
String EmailAddress=" ";
int Order=0;
public void displayCustomerInformation()
{
System.out.println("CustomerID: "+getCustomerID());
System.out.println("Name: "+getName());
System.out.println("Address: "+getAddress());
System.out.println("PhoneNumber: "+getPhoneNumber());
System.out.println("EmailAddress: "+getEmailAddress());
System.out.println("Order: "+getOrder());
}
public int getCustomerID()
{
return CustomerID;
}
public void setCustomerID(int CustomerID)
{
this.CustomerID=CustomerID;
}
public String getName()
{
return Name;
}
public void setName(String Name)
{
this.Name=Name;
}
public String getAddress()
{
return Address;
}
public void setAddress(String Address)
{
this.Address=Address;
}
public int getPhoneNumber()
{
return PhoneNumber;
}
public void setPhoneNumber(int PhoneNumber)
{
this.PhoneNumber=PhoneNumber;
}
public String getEmailAddress()
{
return EmailAddress;
}
public void setEmailAddress(String EmailAddress)
{
this.EmailAddress=EmailAddress;
}
public int getOrder()
{
return Order;
}
public void setOrder(int Order)
{
this.Order=Order;
}
}
CustomerTest:
import java.io.*;
import java.util.*;
public class CustomerTest{
public static void main(String[]args) throws IOException
{
Scanner input= new Scanner(System.in);
Customer myCustomer= new Customer();
PrintWriter output=new PrintWriter(new FileWriter("Grace.txt",true));
System.out.println("Enter CustomerID: ");
int CustomerID=input.nextInt();
System.out.println("Enter Name: ");
String Name=input.next();
System.out.println("Enter Address: ");
String Address=input.next();
System.out.println("Enter PhoneNumber: ");
int PhoneNumber=input.nextInt();
System.out.println("Enter EmailAddress: ");
String EmailAddress=input.next();
System.out.println("Enter Order: ");
int Order=input.nextInt();
myCustomer.setCustomerID(CustomerID);
myCustomer.setName(Name);
myCustomer.setAddress(Address);
myCustomer.setPhoneNumber(PhoneNumber);
myCustomer.setEmailAddress(EmailAddress);
myCustomer.setOrder(Order);
myCustomer.displayCustomerInformation();
output.println(myCustomer.getCustomerID()+ " " +myCustomer.getName()+ " " +myCustomer.getAddress()+ " " +myCustomer.getPhoneNumber()+ " "
+ " " +myCustomer.getEmailAddress()+ " " +myCustomer.getOrder());
System.out.println("Data was succesfully added!!!");
output.close();
}
}
Order:
public class Order{
int OrderID=0;
String OrderName=" ";
String OrderStatus=" ";
public void displayOrderInformation()
{
System.out.println("OrderID: "+getOrderID());
System.out.println("OrderName: "+getOrderName());
System.out.println("OrderStatus: "+getOrder());
}
public int OrderID()
{
return OrderID;
}
public void setOrderID(int OrderID)
{
this.OrderID=OrderID;
}
public String getOrderName()
{
return OrderName;
}
public void setOrderName(String OrderName)
{
this.OrderName=OrderName;
}
public int getOrderStatus()
{
return OrderStatus;
}
public void setOrderStatus(int OrderStatus)
{
this.OrderStatus=OrderStatus;
}
}
OrderTest:
import java.io.*;
import java.util.*;
public class Order{
public static void main(String[]args) throws IOException
{
Scanner input= new Scanner(System.in);
Console cust=System.console();
Customer aCustomer= new Customer();
PrintWriter output=new PrintWriter(new FileWriter("idhang.txt",true));
System.out.println("Enter OrdererID: ");
int CustomerID=input.nextInt();
System.out.println("Enter OrderName: ");
String Name=cust.readLine();
System.out.println("Enter OrderStatus: ");
int Order=input.nextInt();
aCustomer.setCustomerID(CustomerID);
aCustomer.setName(Name);
aCustomer.setAddress(Address);
aCustomer.setPhoneNumber(PhoneNumber);
aCustomer.setEmailAddress(EmailAddress);
aCustomer.setOrder(Order);
aCustomer.displayCustomerInformation();
output.println(aCustomer.getCustomerID()+ " " +aCustomer.getName()+ " " +aCustomer.getAddress()+ " " +aCustomer.getPhoneNumber()+ " "
+ " " +aCustomer.getEmailAddress()+ " " +aCustomer.getOrder());
System.out.println("The data has been successfully added");
output.close();
}
}
Shirt:
public class Shirt{
int ShirtID=0;
float Price=0;
String Color=" ";
String Description=" ";
int QuantityInStock=0;
public void displayShirtInformation()
{
System.out.println("ShirtID: "+getShirtID());
System.out.println("Price: "+getPrice());
System.out.println("Color: "+getColor());
System.out.println("Description: "+getDescription());
System.out.println("QuantityInStock: "+getQuantityInStock());
}
public int getShirtID()
{
return ShirtID;
}
public void setShirtID(int ShirtID)
{
this.ShirtID=ShirtID;
}
public float getPrice()
{
return Price;
}
public void setPrice(float Price)
{
this.Price=Price;
}
public String getColor()
{
return Color;
}
public void setColor(String Color)
{
this.Color=Color;
}
public String getDescription()
{
return Description;
}
public void setDescription(String Description)
{
this.Description=Description;
}
public int getQuantityInStock()
{
return QuantityInStock;
}
public void setQuantityInStock(int QuantityInStock)
{
this.QuantityInStock=QuantityInStock;
}
}
UniTest:
import java.io.*;
import java.util.*;
public class UniTest{
public static void main(String[]args) throws IOException
{
Scanner input= new Scanner(System.in);
Shirt myShirt= new Shirt();
PrintWriter output=new PrintWriter(new FileWriter("LA.txt",true));
System.out.println("Enter ShirtID: ");
int ShirtID=input.nextInt();
System.out.println("Enter Shirt Price: ");
float Price=input.nextFloat();
System.out.println("Enter shirt Color: ");
String Color=input.next();
System.out.println("Enter shirt description: ");
String Description=input.next();
System.out.println("Enter quantity in Stock: ");
int QuantityInStock=input.nextInt();
myShirt.setShirtID(ShirtID);
myShirt.setPrice(Price);
myShirt.setColor(Color);
myShirt.setDescription(Description);
myShirt.setQuantityInStock(QuantityInStock);
myShirt.displayShirtInformation();
output.println(myShirt.getShirtID()+ " " +myShirt.getPrice()+ " " +myShirt.getColor()+ " " +myShirt.getDescription()+ " "
+ " " +myShirt.getQuantityInStock());
System.out.println("Data was succesfully added!!!");
output.close();
}
}
Tuesday, February 3, 2009
IT134 Cube Solutions
//Programmer: Jeanne B. Ramos
//Date started: February 4, 2009
//Date ended: February 6, 2009
//Programmed name: Cube Exe
//Purpose: To create classes using Visibility Modifiers
public class Cubez{ private double volume;
private double area;
private double width;
private double height;
private double length;
private double setDimension;
public Cubez(){
width=0;
height=0;
length=0;
volume=0;
area=0;
}
public Cubez(double width,double height,double length){
this.width=width;
this.height=height;
this.length=length;
}
public void setDimension(double newwidth, double newheight, double newlength){
this.width=width;
this.height=height;
this.length=length;
}
public void displayArea(){
System.out.println(length*width);}
public void dispalyVolume(){
System.out.println(length*width*height);
}
}
//Programmer: Jeanne B. Ramos
//Date started: February 4, 2009
//Date ended: February 6, 2009
//Programmed name: Cube Exe
//Purpose: To create classes using Visibility Modifiers
public class CubeTest{
public static void main(String[]args){
Cube1 A=new Cube1();
Cube1 B=new Cube1(5, 6, 10);
A.setDimension(1,4,5);
A.getvolume();
A.getarea();
System.out.println("Cube A" +"\t="+A.getvolume());
System.out.println("Cube A"+"\t="+A.getarea());
B.setDimension(4,6,8);
B.getvolume();
B.getarea();
System.out.println("Cube B"+"\t="+B.getvolume());
System.out.println("Cube B"+"\t="+B.getarea());
}
}