Really bad code :P

Discussion in 'Web Design & Coding' started by X-Istence, Jun 21, 2005.

  1. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    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;
    }