Click here to Skip to main content
15,908,254 members
Home / Discussions / Java
   

Java

 
GeneralRe: Applet Button thru HTML Pin
002comp12-Apr-10 0:15
002comp12-Apr-10 0:15 
GeneralRe: Applet Button thru HTML(Solved) Pin
002comp12-Apr-10 1:05
002comp12-Apr-10 1:05 
QuestionLocking the size of window Pin
sangeeta200910-Apr-10 21:31
sangeeta200910-Apr-10 21:31 
AnswerRe: Locking the size of window Pin
Richard MacCutchan11-Apr-10 14:34
mveRichard MacCutchan11-Apr-10 14:34 
AnswerRe: Locking the size of window Pin
TorstenH.11-Apr-10 20:54
TorstenH.11-Apr-10 20:54 
Questionshortest remaining time first Pin
Blackberry8910-Apr-10 2:31
Blackberry8910-Apr-10 2:31 
AnswerRe: shortest remaining time first Pin
Richard MacCutchan11-Apr-10 14:34
mveRichard MacCutchan11-Apr-10 14:34 
GeneralRe: shortest remaining time first Pin
Blackberry8912-Apr-10 11:10
Blackberry8912-Apr-10 11:10 
i have got 5 randomly generated numbers in a queue. I want the smallest number in the queue to be displayed. After this another random number will be generated and i want it to be compared against the queue and from that the smallest number be displayed. The code so far is below:
import java.util.ArrayList;
import java.util.Iterator;

public class Assign1 {
    private final int MAX_QUEUE_SIZE = 5;
    private final int NO_SIMULATIONS_TO_RUN = 7; 
    
    private int maxSize;

  private double[] queArray;

  private int nItems;

      /**
     * main method
     * @param args
     */
    public static void main( String args[] ) {
       new Assign1().runSimulation();
    }
    
    /**
     * run a simulation priority queue
     */
    public void runSimulation() {
        
        PriorityQueue queue = new PriorityQueue();
        initQueue(queue);
        
        for (int i = 0; i < NO_SIMULATIONS_TO_RUN; i++) {
            
            System.out.println( "The numbers in the queue are: " + queue.toString());
    
            System.out.println( "The current dispatched number is " + queue.poll());
            queue.remove();
            int item = getRandomNumber();
            
            System.out.println( "The new coming number is " + item );
            queue.add(item);   
            System.out.print( "\n\n" );
        }
    }
    /**
     * creates and inits a queue
     * @param queue
     */
    private void initQueue(PriorityQueue queue){
        for (int i = 0; i < MAX_QUEUE_SIZE; i++) 
            queue.add(getRandomNumber());
    }
    /**
     * returns a RandomNumber()
     * @return
     */
    public static int getRandomNumber(){
        return 1 + ( int ) ( Math.random() * 100 );
    }
    
    /**
     * custom queue class
     */
    private class PriorityQueue extends ArrayList {

        /**
         * allows us to add int values into an ArrayList
         * @param val
         */
        public void add(int val){
            super.add(new Integer(val));
        }
        /**
         * poll for the current top item in the list 
         * @return
         */
        public int poll(){
           return ((Integer) iterator().next()).intValue(); 
        }
        /**
         * returns the items in queue out
         * @param queue
         */
        public String toString(){
            StringBuffer buff = new StringBuffer();
            Iterator it = iterator();
            buff.append("[");
            while (it.hasNext()) {
                buff.append(it.next());
                if (it.hasNext())
                    buff.append(", ");
            }
            buff.append("]");
            return buff.toString();
        }
        /**
         * remove the top level item if the list is not empty
         */
        public void remove(){
            if (!isEmpty())
                remove(0);
        }
    }
}

GeneralRe: shortest remaining time first Pin
TorstenH.12-Apr-10 20:10
TorstenH.12-Apr-10 20:10 
AnswerRe: shortest remaining time first Pin
TorstenH.11-Apr-10 20:59
TorstenH.11-Apr-10 20:59 
Questionencrypting and decrypting an image Pin
glinseynew@gmail.com9-Apr-10 13:55
glinseynew@gmail.com9-Apr-10 13:55 
AnswerRe: encrypting and decrypting an image Pin
Richard MacCutchan11-Apr-10 14:32
mveRichard MacCutchan11-Apr-10 14:32 
QuestionSearch Array Pin
Blackberry899-Apr-10 8:58
Blackberry899-Apr-10 8:58 
AnswerRe: Search Array Pin
Nagy Vilmos9-Apr-10 10:13
professionalNagy Vilmos9-Apr-10 10:13 
GeneralRe: Search Array Pin
Blackberry8910-Apr-10 0:10
Blackberry8910-Apr-10 0:10 
QuestionResizing Button?? Pin
AmbiguousName7-Apr-10 7:51
AmbiguousName7-Apr-10 7:51 
AnswerRe: Resizing Button?? Pin
TorstenH.8-Apr-10 1:59
TorstenH.8-Apr-10 1:59 
Questionhow to find jre is installed or not? Pin
002comp6-Apr-10 23:09
002comp6-Apr-10 23:09 
AnswerRe: how to find jre is installed or not? Pin
002comp6-Apr-10 23:27
002comp6-Apr-10 23:27 
QuestionResizing an image of Diamond shape and placing a label inside the image using Swing Pin
PJanaki6-Apr-10 4:14
PJanaki6-Apr-10 4:14 
AnswerRe: Resizing an image of Diamond shape and placing a label inside the image using Swing Pin
TorstenH.7-Apr-10 1:02
TorstenH.7-Apr-10 1:02 
GeneralRe: Resizing an image of Diamond shape and placing a label inside the image using Swing Pin
PJanaki14-Apr-10 2:40
PJanaki14-Apr-10 2:40 
Questionxampp in linux ubuntu Pin
hansoctantan5-Apr-10 16:51
professionalhansoctantan5-Apr-10 16:51 
AnswerRe: xampp in linux ubuntu Pin
David Skelly5-Apr-10 22:15
David Skelly5-Apr-10 22:15 
QuestionXMPP (Building an Instant Messaging Application Using Jabber/XMPP) Pin
Ireland.ir2-Apr-10 8:45
Ireland.ir2-Apr-10 8:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.