Site hosted by Angelfire.com: Build your free website today!
Blog Tools
Edit your Blog
Build a Blog
View Profile
« November 2008 »
S M T W T F S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Entries by Topic
All topics  «
You are not logged in. Log in
java
Thursday, 22 January 2004

class Search
{
EasyReader reader;
private Item[] itemList;
private int total;

public Search()
{
reader = new EasyReader(fName);
total = reader.readInt();
itemList = new Item[total];
for(int i = 0; i < total; i++)
itemList[i] = new Item(reader.readInt(), reader.readInt());
original = itemList;
}
public void displayStore()
{
for(int i = 0; i < itemList.length; i++)
{
System.out.println(i + 1);
FormatWriter.printWhole(itemList[i].getId(), 10);
FormatWriter.printWhole(itemList[i].getInv(), 10);
System.out.println();
}
}
public void Sort()
{
for(int i = 0; i < itemList.length - 1; i++)
{
Item temp;
int minPos = i;
for(int j = minPos + 1; j < itemList.length; j++)
if(itemList[minPos].getId() > itemList[j].getId())
minPos = j;
temp = itemList[minPos];
itemList[Pos] = itemList[i];
itemList[i] = temp;
}
}
public String toString()
{
String report = "";
for(int i = 0; i < itemList.length; i++)
report += i + " " + itemList[i].myId + " " + itemList[i].myInv;
return report;
}
public void testLinSearch()
{
System.out.println("==========================================\n");
System.out.println("Testing Linear Search Algorithm\n");
System.out.println("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
while(target != -1)
{
boolean ifFound = false;
for(int i = 0; i < itemList.length; i ++)
{
if(itemList[i].getId() == target)
{
System.out.println("Id # " + itemListp[i].getId()
+" Inventory = " + itemList[i].getInv());
ifFound = true;
}
else if(i == itemList.length - 1 && !ifFound)
System.out.println("No Such Part In Stock");
}
System.out.println("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
}
}
public void testBinSearch()
{
System.out.println("==========================================\n");
System.out.println("Testing Binary Search Algorithm\n");
System.out.print("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
while(target != -1)
{
int low = 0;
int high = itemList.length;
boolean found = false;
while(low < high && !found)
{
int mid = (low + high) / 2;
int diff = itemList[mid].getId() - target;
if(diff == 0)
{
System.out.println("Id # " + itemListp[i].getId()
+" Inventory = " + itemList[i].getInv());
ifFound = true;
}
else if (diff > 0)
high = mid - 1;
else
low = mid + 1;
}
if(!found)
System.out.println("No Such Part In Stock");
System.out.println("Enter Id value to search for (-1 to quit) --->");
target = SavitchIn.readInt();
}
}
}





class Item
{
private int myId;
private int myInv;

public Item(int id1, int inv1)
{
myId = id1;
myInv = inv1;
}
public int getId()
{
return myId;
}
public int getInv()
{
return myInv;
}
public int compareTo(Object otherObject)
{
Item temp = (Item)otherObject;
if(myId > temp.getId())
return 1;
else if(myId < temp.getId())
return -1;
else
return 0;
}
public boolean equals(Object otherObject)
{
if(this.myId == otherObject.myId && this.inv == otherObject.inv)
return true;
else
return false;
}
public String toString()
{
return "" + getId() + " " + getInv();
}
}






public class searchTester
{
public static void main(String[] args)
{
System.out.println("Lafs Java Project 11\n\n");
Search widgMart = new Search("inv.data");
System.out.println("Store Data");
System.out.println();
widgMart.displayStore();
widgMart.testLinSearch();
widgMart.Sort();
System.out.println("\nStore Data after sort by Id");
System.out.println();
widgMart.displayStore();
widgMart.testBinSearch();
widgMart.testRecurBinSearch();
}
}





http://www.fredosaurus.com/notes-cpp/algorithms/searching/rbinarysearch.html

Posted by linux/isgreat1 at 8:39 PM EST
Post Comment | Permalink | Share This Post

class Search
{
EasyReader reader;
private Item[] itemList;
private int total;

public Search()
{
reader = new EasyReader(fName);
total = reader.readInt();
itemList = new Item[total];
for(int i = 0; i < total; i++)
itemList[i] = new Item(reader.readInt(), reader.readInt());
original = itemList;
}
public void displayStore()
{
for(int i = 0; i < itemList.length; i++)
{
System.out.println(i + 1);
FormatWriter.printWhole(itemList[i].getId(), 10);
FormatWriter.printWhole(itemList[i].getInv(), 10);
System.out.println();
}
}
public void Sort()
{
for(int i = 0; i < itemList.length - 1; i++)
{
Item temp;
int minPos = i;
for(int j = minPos + 1; j < itemList.length; j++)
if(itemList[minPos].getId() > itemList[j].getId())
minPos = j;
temp = itemList[minPos];
itemList[Pos] = itemList[i];
itemList[i] = temp;
}
}
public String toString()
{
String report = "";
for(int i = 0; i < itemList.length; i++)
report += i + " " + itemList[i].myId + " " + itemList[i].myInv;
return report;
}
public void testLinSearch()
{
System.out.println("==========================================\n");
System.out.println("Testing Linear Search Algorithm\n");
System.out.println("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
while(target != -1)
{
boolean ifFound = false;
for(int i = 0; i < itemList.length; i ++)
{
if(itemList[i].getId() == target)
{
System.out.println("Id # " + itemListp[i].getId()
+" Inventory = " + itemList[i].getInv());
ifFound = true;
}
else if(i == itemList.length - 1 && !ifFound)
System.out.println("No Such Part In Stock");
}
System.out.println("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
}
}
public void testBinSearch()
{
System.out.println("==========================================\n");
System.out.println("Testing Binary Search Algorithm\n");
System.out.print("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
while(target != -1)
{
int low = 0;
int high = itemList.length;
boolean found = false;
while(low < high && !found)
{
int mid = (low + high) / 2;
int diff = itemList[mid].getId() - target;
if(diff == 0)
{
System.out.println("Id # " + itemListp[i].getId()
+" Inventory = " + itemList[i].getInv());
ifFound = true;
}
else if (diff > 0)
high = mid - 1;
else
low = mid + 1;
}
if(!found)
System.out.println("No Such Part In Stock");
System.out.println("Enter Id value to search for (-1 to quit) --->");
target = SavitchIn.readInt();
}
}
}





class Item
{
private int myId;
private int myInv;

public Item(int id1, int inv1)
{
myId = id1;
myInv = inv1;
}
public int getId()
{
return myId;
}
public int getInv()
{
return myInv;
}
public int compareTo(Object otherObject)
{
Item temp = (Item)otherObject;
if(myId > temp.getId())
return 1;
else if(myId < temp.getId())
return -1;
else
return 0;
}
public boolean equals(Object otherObject)
{
if(this.myId == otherObject.myId && this.inv == otherObject.inv)
return true;
else
return false;
}
public String toString()
{
return "" + getId() + " " + getInv();
}
}






public class searchTester
{
public static void main(String[] args)
{
System.out.println("Lafs Java Project 11\n\n");
Search widgMart = new Search("inv.data");
System.out.println("Store Data");
System.out.println();
widgMart.displayStore();
widgMart.testLinSearch();
widgMart.Sort();
System.out.println("\nStore Data after sort by Id");
System.out.println();
widgMart.displayStore();
widgMart.testBinSearch();
widgMart.testRecurBinSearch();
}
}





http://www.fredosaurus.com/notes-cpp/algorithms/searching/rbinarysearch.html

Posted by linux/isgreat1 at 8:35 PM EST
Post Comment | Permalink | Share This Post
11
class Search
{
EasyReader reader;
private Item[] itemList;
private int total;

public Search()
{
reader = new EasyReader(fName);
total = reader.readInt();
itemList = new Item[total];
for(int i = 0; i < total; i++)
itemList[i] = new Item(reader.readInt(), reader.readInt());
original = itemList;
}
public void displayStore()
{
for(int i = 0; i < itemList.length; i++)
{
System.out.println(i + 1);
FormatWriter.printWhole(itemList[i].getId(), 10);
FormatWriter.printWhole(itemList[i].getInv(), 10);
System.out.println();
}
}
public void Sort()
{
for(int i = 0; i < itemList.length - 1; i++)
{
Item temp;
int minPos = i;
for(int j = minPos + 1; j < itemList.length; j++)
if(itemList[minPos].getId() > itemList[j].getId())
minPos = j;
temp = itemList[minPos];
itemList[Pos] = itemList[i];
itemList[i] = temp;
}
}
public String toString()
{
String report = "";
for(int i = 0; i < itemList.length; i++)
report += i + " " + itemList[i].myId + " " + itemList[i].myInv;
return report;
}
public void testLinSearch()
{
System.out.println("==========================================\n");
System.out.println("Testing Linear Search Algorithm\n");
System.out.println("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
while(target != -1)
{
boolean ifFound = false;
for(int i = 0; i < itemList.length; i ++)
{
if(itemList[i].getId() == target)
{
System.out.println("Id # " + itemListp[i].getId()
+" Inventory = " + itemList[i].getInv());
ifFound = true;
}
else if(i == itemList.length - 1 && !ifFound)
System.out.println("No Such Part In Stock");
}
System.out.println("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
}
}
public void testBinSearch()
{
System.out.println("==========================================\n");
System.out.println("Testing Binary Search Algorithm\n");
System.out.print("Enter Id value to search for (-1 to quit) --->");
int target = SavitchIn.readInt();
while(target != -1)
{
int low = 0;
int high = itemList.length;
boolean found = false;
while(low < high && !found)
{
int mid = (low + high) / 2;
int diff = itemList[mid].getId() - target;
if(diff == 0)
{
System.out.println("Id # " + itemListp[i].getId()
+" Inventory = " + itemList[i].getInv());
ifFound = true;
}
else if (diff > 0)
high = mid - 1;
else
low = mid + 1;
}
if(!found)
System.out.println("No Such Part In Stock");
System.out.println("Enter Id value to search for (-1 to quit) --->");
target = SavitchIn.readInt();
}
}
}





class Item
{
private int myId;
private int myInv;

public Item(int id1, int inv1)
{
myId = id1;
myInv = inv1;
}
public int getId()
{
return myId;
}
public int getInv()
{
return myInv;
}
public int compareTo(Object otherObject)
{
Item temp = (Item)otherObject;
if(myId > temp.getId())
return 1;
else if(myId < temp.getId())
return -1;
else
return 0;
}
public boolean equals(Object otherObject)
{
if(this.myId == otherObject.myId && this.inv == otherObject.inv)
return true;
else
return false;
}
public String toString()
{
return "" + getId() + " " + getInv();
}
}






public class searchTester
{
public static void main(String[] args)
{
System.out.println("Lafs Java Project 11\n\n");
Search widgMart = new Search("inv.data");
System.out.println("Store Data");
System.out.println();
widgMart.displayStore();
widgMart.testLinSearch();
widgMart.Sort();
System.out.println("\nStore Data after sort by Id");
System.out.println();
widgMart.displayStore();
widgMart.testBinSearch();
widgMart.testRecurBinSearch();
}
}





http://www.fredosaurus.com/notes-cpp/algorithms/searching/rbinarysearch.html

Posted by linux/isgreat1 at 8:34 PM EST
Post Comment | Permalink | Share This Post
Sunday, 11 January 2004

public class Payroll
{
public static void main (String[] args)
{
Staff personnel = new Staff();
personnel.payday();
}
}








import java.text.DecimalFormat;

public class Staff
{
StaffMember[] staffList;

public Staff()
{
staffList = new StaffMember[6];
Executive laf = new Executive ("Lala Laferty", "123 Main Line", "555-0469",
"123-45-6789", 2000.00);
staffList[0] = laf;
staffList[1] = new Employee ("Robin Droppings", "456 Off Line", "555-0101",
"987-65-4321", 1200.00);
staffList[2] = new Employee ("Allen Wrench", "789 Off Rocker", "555-0000",
"010-20-3040", 1000.00);
Hourly bob = new Hourly ("Bobbi Soks", "678 Fifth Ave.", "555-0690",
"958-47-3625", 15.00);
staffList[3] = bob;
staffList[4] = new Volunteer ("Stu Meet", "987 Suds Blvd.", "555-8374");
staffList[5] = new Volunteer ("Justin Thyme", "321 Duds Lane", "555-7282");

laf.awardBonus();
bob.addHours(46);
}
public void payday()
{
System.out.println("Project 10\n\n");
System.out.println("Lafs Computer Geeks Weekly Payroll Report \n");

for(int count = 0; count < staffList.length; count++)
{
if(count < 4)
{
System.out.print(staffList[count]);
double amount = staffList[count].pay();

System.out.println(amount);
System.out.println("-----------------------------------");
}
else
{
System.out.print(staffList[count]);
}
}
}
}








public abstract class StaffMember
{
protected String name;
protected String address;
protected String phone;
protected int hoursworked;

public StaffMember (String one, String two, String three)
{
name = one;
address = two;
phone = three;
}
public String toString()
{
String whole = "Name: " + name + "\n" +"Address: " + address + "\n" + "Phone: " +
phone + "\n" + "Thanks for your time!" + "\n" + "-----------------------------------" + "\n";
return whole;
}
public abstract double pay();
}







public class Employee extends StaffMember implements pay
{
protected String socialSecurityNumber;
protected double payRate;

String fname;
String place;
String pnum;

public Employee(String name, String address, String phone, String security, double pay)
{
super(name, address, phone);
socialSecurityNumber = security;
payRate = pay;
}
public String toString()
{
fname = name;
place = address;
pnum = phone;
String whole = "Name: " + fname + "\n" +"Address: " + place + "\n" +
"Phone: " + pnum + "\n" + "Social Security Number: " + socialSecurityNumber + "\n" +
"Paid: $";
return whole;
}
public double pay()
{
return payRate;
}
}






public class Executive extends Employee implements pay
{
double bonus;
double salary;

public Executive(String name, String address, String phone, String security, double pay)
{
super(name, address, phone, security, pay);
bonus = 0.00;
salary = pay;
}
public void awardBonus()
{
bonus = 5000.00;
}
public double pay()
{
return salary + bonus;
}
}





public class Hourly extends Employee implements pay
{
double payment;
double wage;

public Hourly(String name, String address, String phone, String security, double pay)
{
super(name, address, phone, security, pay);
hoursworked = 0;
wage = pay;
}
public void addHours(int moreHours)
{
hoursworked += moreHours;
}
public double pay()
{
if(hoursworked > 40)
{
return ((40 * wage) + ((hoursworked - 40) * wage * 1.5));
}
else
{
payment = hoursworked * wage;
return payment;
}
}
public String toString()
{
fname = name;
place = address;
pnum = phone;

String whole = "Name: " + fname + "\n" +"Address: " + place + "\n" +
"Phone: " + pnum + "\n" + "Social Security Number: " + socialSecurityNumber + "\n" +
"Current Hours: " + hoursworked + "\n" + "Paid: $";
return whole;
}
}






public class Volunteer extends StaffMember implements pay
{
public Volunteer(String name, String address, String phone)
{
super(name, address, phone);
}
public double pay()
{
return 0.00;
}
}






public interface pay
{
double pay();
}

Posted by linux/isgreat1 at 6:09 PM EST
Post Comment | Permalink | Share This Post

Newer | Latest | Older