Really bad code :P

X-Istence

*
Political Access
Joined
5 Dec 2001
Messages
6,498
Here is some really bad code i want to keep for later

Code:
Free Response -- Jan-Willem Regeer

import java.util.*

public static ArrayList createList (int n) {
	ArrayList myList = new ArrayList();
	Random myRand = new Random();
	
	for (int i = 0; i < n; ++i) {
		int blah = 0;
		while (blah < 10) 
			blah = myRand.nextInt(100)

		myList.add(new Integer(blah));
	}

	return myList;
}

public static double getMean (ArrayList myList) {

	double sum = 0;
	for (int i = 0; i < myList.size(); ++i)
		sum += ((Integer)myList.get(i)).intValue();

	double mean = sum / myList.size();
	return mean;
}

public static double getMedian (ArrayList myList) {
	sortList(myList);

	if ((myList.size() % 2) == 1)
		return (double) ((Integer)myList.get((((myList.size()-1)/2)+1)));
	
	return (double)((((Integer)myList.get((myList.size()/2))).intValue()+((Integer)myList.get(((myList.size()/2)+1))).intValue())/2.0)
}

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

public void addNewProduct (String name, double cost, int amount) {

	for (int i = 0; i < products.size(); ++i) {
		if (name < ((Product)products.get(i)).getItem() ) {
			int b = i;
			break;
		}
	}

	products.add(i, new Product(name, cost, amount));
}

public ArrayList mustOrder() {
	ArrayList myArray = new ArrayList();

	for (int i = 0; i < products.size(); ++i) {					/*
		if ( ((Product)products.get(i)).getQuantity() > 20 ) {			 * We might as well check if we have more
			System.out.prinln ("We don't have to order anything !!!!");      * than 20 items eh? 
		}									 */
		if ( ((Product)products.get(i)).getQuantity() < 20 ) {
			myArray.add( (String) ((Product)products.get(i)).getItem() );
		}
	}
	return myArray;
}
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back