Results 1 to 2 of 2
  1. #1
    BetaDave1877 is offline Member
    Join Date
    Apr 2012
    Posts
    3
    Rep Power
    0

    Default Implementing a Priority queue with two values.Can you store an array in a priority q?

    Hi this is for a homework assignment I don't want answers and I am not looking for it, I just want help to be a better programmer. I have questions and don't know where to look. Ok I will start explaining what my problem is. Basically my program is a "CPU SIM". It is not to fancy it just takes a name a priority and then a size variable and prints that off. For the value of the Size variable it prints out it is starting a new time slice. The problem is that my program needs to build an the priority queue then print off the values in the priority queue until there are no more priority left in the queue. It gets its commands from a text file that reads
    add job Internet with length 6 and priority 4
    add job Launchcode with length 3 and priority 3
    add job Facebook with length 2 and priority 5
    add job explorer with length 1 and priority 2
    add job shutdown with length 5 and priority 1
    the name varaible is shut down, and the length is how many time slices it should print out.What I have programmed so far makes three variables for name, length, and priority. My plan is to then run it through a builder to make a queue then after the builder is done have a another class that will have it print out what i need to print out. I need help figuring out my static classes and how to implement my static Variable ADT.
    My code is bellow. Please ask any question I will answer immediately please help me!

    Java Code:
    package cpusim;
    
    import java.io.*;
    import java.util.Scanner;
    
    public class Cpusim {
    
        public int x = 0;
        public boolean T;
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws FileNotFoundException, IOException {
    
            String[] myarray;
            String fileName;
            FileInputStream in = new FileInputStream("input.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
    
            String strLine;
    
            myarray = new String[5];
    
    
    
            for (int j = 0; j < myarray.length; j++) {
                myarray[j] = br.readLine();
            }
    
            in.close();
            for (int i = 0; i < myarray.length; i++) {
                String S=myarray[i];
                String[] X = S.split(" ");
                String name = X[3];
                String p= X[6];
                String n = X[9];
                System.out.print(name+" "+p+" "+n+" "+" ");
                int length = Integer.parseInt(p);
                int priority =Integer.parseInt( n );
                builder(name,length,priority);
                
               
              
            }
        }
    
        public static void builder(String name, int length, int priority) {
          
        }
    Last edited by Fubarable; 04-16-2012 at 02:32 AM. Reason: request for PM's deleted

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: Implementing a Priority queue with two values.Can you store an array in a priorit

    Have you browsed through the API documentation? There already exists a PriorityQueue, so why not use it?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Priority Queue Implementation
    By cylus99 in forum New To Java
    Replies: 1
    Last Post: 12-20-2011, 10:48 PM
  2. Priority Queue
    By fam2315 in forum New To Java
    Replies: 5
    Last Post: 06-29-2011, 03:10 AM
  3. Priority Queue with explicit priority
    By lsk in forum Advanced Java
    Replies: 4
    Last Post: 06-10-2011, 07:16 PM
  4. Priority Queue
    By Suende in forum New To Java
    Replies: 19
    Last Post: 04-25-2011, 08:46 AM
  5. Priority Queue Question
    By Taz_84 in forum New To Java
    Replies: 0
    Last Post: 01-29-2009, 03:23 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •