• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Really bad code :P

X-Istence

*
Political User
#1
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies